package com.lightinit.hsdataportal.impl;

import com.lightinit.hsdataportal.dictionary.DicPlatformType;
import com.lightinit.hsdataportal.entity.Admin;
import com.lightinit.hsdataportal.entity.ResourceAuth;
import com.lightinit.hsdataportal.entity.User;
import com.lightinit.hsdataportal.mapper.*;
import com.lightinit.hsdataportal.model.*;
import com.lightinit.hsdataportal.service.IMyMicroappService;
import com.lightinit.hsdataportal.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyMicroappServiceImpl implements IMyMicroappService {
    @Autowired
    private ResourceAuthMapper resourceAuthMapper;
    @Autowired
    private ResourceFollowMapper resourceFollowMapper;
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<MyMicroappApplyListModel> selectOpenList(MyMicroappApplySearchModel inputModel) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        MyAPIFollowSearchModel followSearchModel = new MyAPIFollowSearchModel();
        return resourceAuthMapper.selectMicroappApplyList(inputModel);
    }

    @Override
    public long selectOpenCount(MyMicroappApplySearchModel inputModel) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        MyAPIFollowSearchModel followSearchModel = new MyAPIFollowSearchModel();
        return resourceAuthMapper.selectMicroappApplyCount(inputModel);
    }

    @Override
    public List<MyMicroappFollowListModel> selectFollowOpenList(MyMicroappFollowSearchModel inputModel) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        MyAPIFollowSearchModel followSearchModel = new MyAPIFollowSearchModel();
        return resourceFollowMapper.selectFollowOpenList(inputModel);
    }

    @Override
    public long selectFollowOpenCount(MyMicroappFollowSearchModel inputModel) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        MyAPIFollowSearchModel followSearchModel = new MyAPIFollowSearchModel();
        return resourceFollowMapper.selectFollowOpenCount(inputModel);
    }

    @Override
    public MyMicroappFeedbackModel feedback(Long id,String platformType) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        MyMicroappFeedbackModel myMicroappFeedbackModel = new MyMicroappFeedbackModel() ;
        ResourceAuth resourceAuth = resourceAuthMapper.selectByPrimaryKey(id) ;

        myMicroappFeedbackModel.setAuditResult(resourceAuth.getAuthState());
        myMicroappFeedbackModel.setAuditOpinion(resourceAuth.getAuditOpinion()) ;
        Admin admin = adminMapper.selectByPrimaryKey(resourceAuth.getAuditedBy()) ;
        if(null != admin) {
            myMicroappFeedbackModel.setAuditedByName(admin.getUsername());
        }

        return myMicroappFeedbackModel;
    }
}
