package cn.ey.biz.module.system.dal.mapper.engagement.task;

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.controller.engagement.task.vo.EngagementTaskRuleInfoReqVO;
import cn.ey.biz.module.system.controller.engagement.task.vo.EngagementTaskRuleRespVO;
import cn.ey.biz.module.system.dal.dataobject.engagement.task.SystemEngagementTaskRuleDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;


@Mapper
public interface SystemEngagementTaskRuleMapper extends BaseMapperX<SystemEngagementTaskRuleDO> {

    EngagementTaskRuleRespVO selectById(@Param("id") Long id);

    EngagementTaskRuleRespVO selectByTaskRuleDescAndApplicationDesc(@Param("taskType") String taskType,
                                                                    @Param("applicationDesc") String applicationDesc);

    void updateBatchByIds(@Param("list") List<SystemEngagementTaskRuleDO> list);

    void deleteBatchByIds(@Param("list") List<Long> list);

    List<EngagementTaskRuleRespVO> selectListByPage(EngagementTaskRuleInfoReqVO param);

    Integer selectCountByPage(EngagementTaskRuleInfoReqVO param);

    default PageResult<SystemEngagementTaskRuleDO> selectPage(EngagementTaskRuleInfoReqVO reqVO) {
        LambdaQueryWrapperX<SystemEngagementTaskRuleDO> queryWrapperX = new LambdaQueryWrapperX<SystemEngagementTaskRuleDO>();
        queryWrapperX.eq(SystemEngagementTaskRuleDO::getDeleted, false)
                .eq(StringUtils.isNotBlank(reqVO.getCountryCode()),
                        SystemEngagementTaskRuleDO::getCountryCode, reqVO.getCountryCode())
                .eq(StringUtils.isNotBlank(reqVO.getMrCode()),
                        SystemEngagementTaskRuleDO::getMrCode, reqVO.getMrCode())
                .eq(StringUtils.isNotBlank(reqVO.getSlCode()),
                        SystemEngagementTaskRuleDO::getSlCode, reqVO.getSlCode())
                .eq(StringUtils.isNotBlank(reqVO.getSslCode()),
                        SystemEngagementTaskRuleDO::getSslCode, reqVO.getSslCode())
                .eq(StringUtils.isNotBlank(reqVO.getCompetencyCode()),
                        SystemEngagementTaskRuleDO::getCompetencyCode, reqVO.getCompetencyCode())
                .eq(StringUtils.isNotBlank(reqVO.getSmuCode()),
                        SystemEngagementTaskRuleDO::getSmuCode, reqVO.getSmuCode())
                .inIfPresent(SystemEngagementTaskRuleDO::getTaskType, reqVO.getTaskType())
                .orderByDesc(SystemEngagementTaskRuleDO::getId);
        return selectPage(reqVO, queryWrapperX);
    }
}