package cn.iocoder.yudao.module.relations.dal.mysql.contract;

import java.time.LocalDate;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.relations.controller.admin.contract.vo.RelationsContractPageReqVO;
import cn.iocoder.yudao.module.relations.dal.dataobject.contract.RelationsContractDO;
import cn.iocoder.yudao.module.relations.dal.dataobject.conversion.RelationsConversionDO;
import cn.iocoder.yudao.module.system.enums.common.DeletedEnum;
import org.apache.ibatis.annotations.Mapper;

/**
 * 员工合同信息 Mapper
 *
 * @author zhaopq
 */
@Mapper
public interface RelationsContractMapper extends BaseMapperX<RelationsContractDO> {

    default PageResult<RelationsContractDO> selectPage(RelationsContractPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RelationsContractDO>()
                .eqIfPresent(RelationsContractDO::getContractId, reqVO.getContractId())
                .likeIfPresent(RelationsContractDO::getEmployeeName, reqVO.getEmployeeName())
                .eqIfPresent(RelationsContractDO::getDeptId, reqVO.getDeptId())
                .likeIfPresent(RelationsContractDO::getDeptName, reqVO.getDeptName())
                .eqIfPresent(RelationsContractDO::getPostId, reqVO.getPostId())
                .eqIfPresent(RelationsContractDO::getPosition, reqVO.getPosition())
                .likeIfPresent(RelationsContractDO::getEmployeeNumber, reqVO.getEmployeeNumber())
                .likeIfPresent(RelationsContractDO::getEmployeePhone, reqVO.getEmployeePhone())
                .betweenIfPresent(RelationsContractDO::getContractStartDate, reqVO.getContractStartDate())
                .betweenIfPresent(RelationsContractDO::getContractEndDate, reqVO.getContractEndDate())
                .eqIfPresent(RelationsContractDO::getContractDeadline, reqVO.getContractDeadline())
                .eqIfPresent(RelationsContractDO::getRemarks, reqVO.getRemarks())
                .eqIfPresent(RelationsContractDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(RelationsContractDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(RelationsContractDO::getEmployeeId, reqVO.getEmployeeId())
                .eqIfPresent(RelationsContractDO::getTenantId, reqVO.getTenantId())
                .likeIfPresent(RelationsContractDO::getCreatorEmployeeName, reqVO.getCreatorEmployeeName())
                .eq(RelationsContractDO::getDeleted, DeletedEnum.FALSE)
                .orderByDesc(RelationsContractDO::getId));
    }

    default List<RelationsContractDO> selectListByStatusAndEmployeeId(Integer status, Long employeeId) {
        return selectList(new LambdaQueryWrapperX<RelationsContractDO>()
                .eqIfPresent(RelationsContractDO::getStatus, status)
                .eq(RelationsContractDO::getDeleted, DeletedEnum.FALSE)
                .eqIfPresent(RelationsContractDO::getEmployeeId, employeeId));
    }

    default List<RelationsContractDO> selectListByStatusAndEffectiveDateGe(Integer status, LocalDate now) {
        return selectList(new LambdaQueryWrapperX<RelationsContractDO>()
                .eqIfPresent(RelationsContractDO::getStatus, status)
                .eq(RelationsContractDO::getDeleted, DeletedEnum.FALSE)
                .geIfPresent(RelationsContractDO::getContractStartDate, now));
    }

    default List<RelationsContractDO> selectListByStatusAndEmployeeIds(Integer status, Set<Long> employeeIds) {
            return selectList(new LambdaQueryWrapperX<RelationsContractDO>()
                    .eqIfPresent(RelationsContractDO::getStatus, status)
                    .eq(RelationsContractDO::getDeleted, DeletedEnum.FALSE)
                    .inIfPresent(RelationsContractDO::getEmployeeId, employeeIds));
    }

}