package cn.ey.biz.module.system.dal.mapper.codeblock;

import cn.ey.biz.common.pojo.PageResult;
import cn.ey.biz.framework.mybatis.core.mapper.BaseMapperX;
import cn.ey.biz.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ey.biz.module.system.api.codeblock.dto.CodeBlockWideTableReqDTO;
import cn.ey.biz.module.system.controller.admin.codeblock.vo.*;
import cn.ey.biz.module.system.controller.engagement.code.vo.EngagementCodeRuleReqVOList;
import cn.ey.biz.module.system.dal.dataobject.codeblock.CodeBlockDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface CodeBlockMapper extends BaseMapperX<CodeBlockDO> {

    default PageResult<CodeBlockDO> selectPage(CodeBlockPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CodeBlockDO>()
                .likeIfPresent(CodeBlockDO::getCodeBlockCode, reqVO.getCodeBlockCode())
                .likeIfPresent(CodeBlockDO::getCountryRegionCode, reqVO.getCountryRegionCode())
                .likeIfPresent(CodeBlockDO::getGeoRegionName, reqVO.getGeoRegionName())
                .likeIfPresent(CodeBlockDO::getLegalEntityName, reqVO.getLegalEntityName())
                .likeIfPresent(CodeBlockDO::getBuName, reqVO.getBuName())
                .likeIfPresent(CodeBlockDO::getOuName, reqVO.getOuName())
                .likeIfPresent(CodeBlockDO::getSmuName, reqVO.getSmuName())
                .likeIfPresent(CodeBlockDO::getMuName, reqVO.getMuName())
                .likeIfPresent(CodeBlockDO::getSlName, reqVO.getSlName())
                .likeIfPresent(CodeBlockDO::getSslName, reqVO.getSslName())
                .likeIfPresent(CodeBlockDO::getCompetencyName, reqVO.getCompetencyName())
                .likeIfPresent(CodeBlockDO::getUsageDesr, reqVO.getUsageDesr())
                .orderByDesc(CodeBlockDO::getCodeBlockId));
    }

    List<CodeBlockCodeValueVO> selectDistinctCountryRegionCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctGeoRegionCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctBuCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctSlCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctSslCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctCompetencyCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctSmuCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctMuCodeBackList(EngagementCodeRuleReqVOList reqVOList);

    List<CodeBlockCodeValueVO> selectDistinctOuCodeBackList(EngagementCodeRuleReqVOList reqVOList);

    List<CodeBlockCodeValueVO> selectDistinctLegalEntityCodeBackList(EngagementCodeRuleReqVOList reqVOList);

    List<CodeBlockCodeValueVO> selectDistinctBuCodeBackList(EngagementCodeRuleReqVOList reqVOList);

    List<CodeBlockCodeValueVO> selectDistinctSlCodeBackList(EngagementCodeRuleReqVOList reqVOList);

    List<CodeBlockCodeValueVO> selectDistinctSslCodeBackList(EngagementCodeRuleReqVOList reqVOList);

    List<CodeBlockCodeValueVO> selectDistinctSmuCodeBackList(EngagementCodeRuleReqVOList reqVOList);

    List<CodeBlockCodeValueVO> selectDistinctMuCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctOuCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctLegalEntityList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctMrCodeList(CodeBlockWideTableReqDTO param);

    List<CodeBlockCodeValueVO> selectDistinctAreaCodeList(CodeBlockWideTableReqDTO param);

    List<String> pullDownLegalEntityCode();

    List<CodeBlockCodeValueVO> pullDownSl(@Param("legalEntityCode") String legalEntityCode);

    List<CodeBlockCodeValueVO> pullDownSlList(@Param("legalEntityCode") List<String> legalEntityCode);

    List<CodeBlockCodeValueVO> pullDownSmu(@Param("legalEntityCode") String legalEntityCode, @Param("slCode") String slCode, @Param("sslCode") String sslCode);

    List<CodeBlockCodeValueVO> pullDownSmuList(@Param("legalEntityCode") List<String> legalEntityCode, @Param("slCode") List<String> slCode, @Param("sslCode") List<String> sslCode);

    List<CodeBlockCodeValueVO> pullDownSslCodeList(@Param("legalEntityCode") List<String> legalEntityCode, @Param("slCode") List<String> slCode);
    List<CodeBlockDO> filterList(@Param("distinctList") List<CodeBlockVO> distinctList);

    List<CodeBlockDO> financeFilterList();

    List<CodeBlockDO> getCodeBlockList();

    List<CodeBlockDO> financeFilterFirmList();

    default List<CodeBlockDO> selectPageCodeBlockCode() {
        return selectList(new LambdaQueryWrapperX<CodeBlockDO>()
                .orderByDesc(CodeBlockDO::getCodeBlockId));
    }

    IPage<CodeBlockDO> filterListPage(IPage page, @Param("pageReqVO") CodeBlockPageReqVO pageReqVO,
                                      @Param("codeBlockServiceLineVO") List<CodeBlockServiceLineVO> codeBlockServiceLineVO,
                                      @Param("codeBlockAreaVO") List<CodeBlockAreaVO> codeBlockAreaVO);

    default CodeBlockDO selectOne(String codeBlock) {
        return selectOne(new LambdaQueryWrapperX<CodeBlockDO>()
                .eqIfPresent(CodeBlockDO::getCodeBlockCode, codeBlock)
        );
    }

    List<CodeBlockDO> getCodeBlockListByGpn(@Param("app")String app,
                                            @Param("userId") String userId,
                                            @Param("configType") String configType);

    List<String> getGpnListByCodeBlock(@Param("app")String app,
                                       @Param("codeBlock") String codeBlock,
                                       @Param("configType") String configType);

    List<CodeBlockDO> getCodeBlockListByGpnUpgrade(@Param("app")String app,
                                            @Param("roleIds") List<Long> roleIds,
                                            @Param("configType") String configType);

}

