package com.changhu.module.management.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.db.enums.MiniProgramUserIdentity;
import com.changhu.common.db.enums.UserType;
import com.changhu.common.exception.MessageException;
import com.changhu.common.utils.UserUtil;
import com.changhu.module.management.pojo.params.IndexCheckPassParams;
import com.changhu.module.management.pojo.params.IndexCheckStatusParams;
import com.changhu.module.management.pojo.params.IndexDisableOrEnableParams;
import com.changhu.module.management.pojo.queryParams.UnitMiniProgramUserPagerQueryParams;
import com.changhu.module.management.pojo.vo.UnitCheckStatusVo;
import com.changhu.module.management.pojo.vo.UnitMiniProgramUserPagerVo;
import com.changhu.module.management.service.ManagementService;
import com.changhu.module.miniProgram.mapper.MiniProgramUserMapper;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 20252
 * @createTime 2024/9/2 上午9:49
 * @desc IndexServiceImpl...
 */
@Service
public class ManagementServiceImpl implements ManagementService {

    @Autowired
    private MiniProgramUserMapper miniProgramUserMapper;

    @Override
    public void checkPass(IndexCheckPassParams params) {
        params.getUnitOptType()
                .getHandler()
                .pass(params.getCheckDataId());
    }

    @Override
    public UnitCheckStatusVo getCheckStatus(IndexCheckStatusParams params) {
        return params.getUnitOptType()
                .getHandler()
                .getCheckStatus(params.getOnlyCode());
    }

    @Override
    public void disableOrEnable(IndexDisableOrEnableParams params) {
        params.getUnitOptType()
                .getHandler()
                .disableOrEnable(params.getDataId());
    }

    @Override
    public Page<UnitMiniProgramUserPagerVo> miniProgramUserPager(PageParams<UnitMiniProgramUserPagerQueryParams, UnitMiniProgramUserPagerVo> queryParams) {
        UserType userType = UserUtil.getUserType();
        MiniProgramUserIdentity identity = switch (userType) {
            case MANAGEMENT_POLICE -> MiniProgramUserIdentity.POLICE;
            case MANAGEMENT_SECURITY -> MiniProgramUserIdentity.PROJECT_MANAGER;
            default -> throw new MessageException("用户类型不匹配");
        };
        return miniProgramUserMapper.pager(queryParams.getPage(), queryParams.getParams(), identity);
    }

    @Override
    public void passMiniProgramUser(IndexDisableOrEnableParams params) {
        params.getUnitOptType()
                .getHandler()
                .passMiniProgramUser(params.getDataId());
    }

    @Override
    public void disableOrEnableMiniProgramUser(IndexDisableOrEnableParams params) {
        params.getUnitOptType()
                .getHandler()
                .disableOrEnableMiniProgramUser(params.getDataId());
    }
}
