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

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.code.vo.EngagementCodeRuleEntityVO;
import cn.ey.biz.module.system.controller.engagement.code.vo.EngagementCodeRuleRespVO;
import cn.ey.biz.module.system.dal.dataobject.engagement.code.SystemEngagementCodeRuleDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface SystemEngagementCodeRuleMapper extends BaseMapperX<SystemEngagementCodeRuleDO> {

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

    List<EngagementCodeRuleRespVO> selectByParam(SystemEngagementCodeRuleDO codeRuleDO);

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

    default PageResult<SystemEngagementCodeRuleDO> selectPage(EngagementCodeRuleEntityVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SystemEngagementCodeRuleDO>()
                .eq(SystemEngagementCodeRuleDO::getDeleted, false)
                .inIfPresent(SystemEngagementCodeRuleDO::getEntityCode, reqVO.getLegalEntityCode())
                .inIfPresent(SystemEngagementCodeRuleDO::getBuCode, reqVO.getBuCode())
                .inIfPresent(SystemEngagementCodeRuleDO::getOuCode, reqVO.getOuCode())
                .inIfPresent(SystemEngagementCodeRuleDO::getMuCode, reqVO.getMuCode())
                .inIfPresent(SystemEngagementCodeRuleDO::getSmuCode, reqVO.getSmuCode())
                .inIfPresent(SystemEngagementCodeRuleDO::getSlCode, reqVO.getSlCode())
                .inIfPresent(SystemEngagementCodeRuleDO::getSslCode, reqVO.getSslCode())
                .orderByDesc(SystemEngagementCodeRuleDO::getId));
    }

    SystemEngagementCodeRuleDO selectOneForMaxTime();
}
