package com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cico.nest.lcdp.boot.core.qxsd.adapter.web.vo.tunnelFacility.TunnelFacilityPageReqVO;
import com.cico.nest.lcdp.boot.core.qxsd.domain.tunnel.TunnelFacilityEnableStatus;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.dataobject.TunnelFacilityDO;
import com.cico.nest.lcdp.framework.common.pojo.PageResult;
import com.cico.nest.lcdp.framework.mybatis.core.mapper.BaseMapperX;
import com.cico.nest.lcdp.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 隧道设施 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface TunnelFacilityMapper extends BaseMapperX<TunnelFacilityDO> {

    default PageResult<TunnelFacilityDO> selectPage(TunnelFacilityPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TunnelFacilityDO>()
                .likeIfPresent(TunnelFacilityDO::getFacilityName, reqVO.getFacilityName())
                .likeIfPresent(TunnelFacilityDO::getFacilityEncode, reqVO.getFacilityEncode())
                .eqIfPresent(TunnelFacilityDO::getBelongSections, reqVO.getBelongSections())
                .eqIfPresent(TunnelFacilityDO::getManagementCenter, reqVO.getManagementCenter())
                .eqIfPresent(TunnelFacilityDO::getTunnelDept, reqVO.getTunnelDept())
                .eqIfPresent(TunnelFacilityDO::getTunnelType, reqVO.getTunnelType())
                .orderByAsc(TunnelFacilityDO::getSort));
    }


    default List<TunnelFacilityDO> selectByFacilityName(String facilityName) {
        LambdaQueryWrapper<TunnelFacilityDO> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TunnelFacilityDO::getFacilityName, facilityName);
        return selectList(queryWrapper);
    }

    /**
     * 启用
     * @param id
     */
    default void enable(String id){
        update(Wrappers.<TunnelFacilityDO>lambdaUpdate()
                .set(TunnelFacilityDO::getEnable, TunnelFacilityEnableStatus.enable.type)
                .eq(TunnelFacilityDO::getId,id));
    }

    default boolean existEnable(){
        return selectCount(Wrappers.<TunnelFacilityDO>lambdaQuery()
                .eq(TunnelFacilityDO::getEnable, TunnelFacilityEnableStatus.enable.type))>0;
    }


    /**
     * 禁用
     * @param id
     */
    default void disEnable(String id){
        update(Wrappers.<TunnelFacilityDO>lambdaUpdate()
                .set(TunnelFacilityDO::getEnable, TunnelFacilityEnableStatus.disEnable.type)
                .eq(TunnelFacilityDO::getId,id));
    }

    /**
     * 设施启用列表
     * @return 设施列表
     */
    default List<TunnelFacilityDO> getEnableList(){
        return selectList(Wrappers.<TunnelFacilityDO>lambdaQuery()
                .eq(TunnelFacilityDO::getEnable, TunnelFacilityEnableStatus.enable.type));
    }

}
