package com.yc.ship.module.marketing.dal.mysql.policy;

import com.yc.ship.framework.common.enums.CommonStatusEnum;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.module.marketing.dal.dataobject.policy.PolicyDO;
import org.apache.ibatis.annotations.Mapper;
import com.yc.ship.module.marketing.controller.admin.policy.vo.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 营销政策 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface PolicyMapper extends BaseMapperX<PolicyDO> {

    default PageResult<PolicyDO> selectPage(PolicyPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PolicyDO>()
                .likeIfPresent(PolicyDO::getName, reqVO.getName())
                .eqIfPresent(PolicyDO::getShipId, reqVO.getShipId())
                .eqIfPresent(PolicyDO::getStatus, reqVO.getStatus())
                .orderByDesc(PolicyDO::getId));
    }

    default List<PolicyDO> selectList(List<Long> policyIds) {
        return selectList(new LambdaQueryWrapperX<PolicyDO>()
                .inIfPresent(PolicyDO::getId, policyIds)
                .ge(PolicyDO::getEffectiveTime, LocalDateTime.now())
                .eq(PolicyDO::getStatus, CommonStatusEnum.ENABLE.getStatus()));
    }
}