package com.yc.ship.module.resource.dal.mysql.driver;

import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.module.resource.controller.admin.driver.vo.DriverPageReqVO;
import com.yc.ship.module.resource.controller.admin.driver.vo.DriverReqVO;
import com.yc.ship.module.resource.controller.admin.driver.vo.DriverRespVO;
import com.yc.ship.module.resource.controller.admin.driver.vo.DriverSimpleRespVO;
import com.yc.ship.module.resource.dal.dataobject.driver.DriverDO;
import com.yc.ship.module.resource.enums.CommonStatusEnum;
import com.yc.ship.module.resource.enums.UseStatusEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 驾驶员管理 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface DriverMapper extends BaseMapperX<DriverDO> {

    default PageResult<DriverDO> selectPage(DriverPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DriverDO>()
                .likeIfPresent(DriverDO::getName, reqVO.getName())
                .eqIfPresent(DriverDO::getDriverCode, reqVO.getDriverCode())
                .eqIfPresent(DriverDO::getId, reqVO.getId())
                .eqIfPresent(DriverDO::getGroupId, reqVO.getGroupId())
                .eqIfPresent(DriverDO::getIdCard, reqVO.getIdCard())
                .eqIfPresent(DriverDO::getSex, reqVO.getSex())
                .eqIfPresent(DriverDO::getBirthday, reqVO.getBirthday())
                .eqIfPresent(DriverDO::getPhone, reqVO.getPhone())
                .eqIfPresent(DriverDO::getDriverLevel, reqVO.getDriverLevel())
                .eqIfPresent(DriverDO::getDriverType, reqVO.getDriverType())
                .eqIfPresent(DriverDO::getEduType, reqVO.getEduType())
                .eqIfPresent(DriverDO::getNation, reqVO.getNation())
                .eqIfPresent(DriverDO::getAddress, reqVO.getAddress())
                .eqIfPresent(DriverDO::getEmergentPhone, reqVO.getEmergentPhone())
                .eqIfPresent(DriverDO::getUseStatus, reqVO.getUseStatus())
                .eqIfPresent(DriverDO::getDriverTag, reqVO.getDriverTag())
                .eqIfPresent(DriverDO::getDriverCardImgUrl1, reqVO.getDriverCardImgUrl1())
                .eqIfPresent(DriverDO::getDriverCardImgUrl2, reqVO.getDriverCardImgUrl2())
                .eqIfPresent(DriverDO::getIdCardImgUrl1, reqVO.getIdCardImgUrl1())
                .eqIfPresent(DriverDO::getIdCardImgUrl2, reqVO.getIdCardImgUrl2())
                .betweenIfPresent(DriverDO::getFirstIssuedate, reqVO.getFirstIssuedate())
                .eqIfPresent(DriverDO::getAnnualPeriod, reqVO.getAnnualPeriod())
                .betweenIfPresent(DriverDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(DriverDO::getSort)
                .orderByDesc(DriverDO::getId));
    }

    default List<DriverDO> selectList(DriverSimpleRespVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DriverDO>()
                .likeIfPresent(DriverDO::getName, reqVO.getName())
                .eqIfPresent(DriverDO::getUseStatus, reqVO.getUseStatus())
                .eqIfPresent(DriverDO::getId, reqVO.getId())
                .inIfPresent(DriverDO::getId, reqVO.getDriverIds())
                .eqIfPresent(DriverDO::getDeleted, CommonStatusEnum.ENABLE.getStatus())
                .orderByAsc(DriverDO::getSort));
    }

    default List<DriverDO> selectSimpleList() {
        return selectList(new LambdaQueryWrapperX<DriverDO>()
                .select(DriverDO::getId, DriverDO::getDriverCode, DriverDO::getName, DriverDO::getPhone)
                .eq(DriverDO::getUseStatus, UseStatusEnum.ENABLE.getStatus())
                .orderByAsc(DriverDO::getSort));
    }

    List<DriverRespVO> getDriverDefaultCarList(@Param("param") DriverReqVO reqVO);

    List<DriverDO> getSimpleDriverListByCarType(@Param("carType") String carType);
}
