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

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

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.controller.admin.policy.vo.PolicyUsableReqVO;
import com.yc.ship.module.marketing.dal.dataobject.policydetail.PolicyDetailDO;
import com.yc.ship.module.product.dal.dataobject.voyage.VoyageDO;
import org.apache.ibatis.annotations.Mapper;
import com.yc.ship.module.marketing.controller.admin.policydetail.vo.*;

/**
 * 政策详情 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface PolicyDetailMapper extends BaseMapperX<PolicyDetailDO> {

    default PageResult<PolicyDetailDO> selectPage(PolicyDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PolicyDetailDO>()
                .eqIfPresent(PolicyDetailDO::getPolicyId, reqVO.getPolicyId())
                .orderByDesc(PolicyDetailDO::getId));
    }

    default void deleteByPolicyId(Long policyId) {
        delete(new LambdaQueryWrapperX<PolicyDetailDO>().eq(PolicyDetailDO::getPolicyId, policyId));
    }

    default List<PolicyDetailDO> selectByPolicyId(Long policyId) {
        return selectList(new LambdaQueryWrapperX<PolicyDetailDO>().eq(PolicyDetailDO::getPolicyId, policyId));
    }

    default List<PolicyDetailDO> selectByPolicyIds(List<Long> policyIds) {
        return selectList(new LambdaQueryWrapperX<PolicyDetailDO>().in(PolicyDetailDO::getPolicyId, policyIds)
                .gt(PolicyDetailDO::getSurplusNum, BigDecimal.ZERO));
    }

    default List<PolicyDetailDO> selectListByVoyageId(Long voyageId) {
        return selectList(new LambdaQueryWrapperX<PolicyDetailDO>().eq(PolicyDetailDO::getVoyageId, voyageId)
                .gt(PolicyDetailDO::getSurplusNum, BigDecimal.ZERO));
    }

    default PolicyDetailDO selectByPolicyIdAndVoyageId(Long policyId, Long voyageId) {
        return selectOne(new LambdaQueryWrapperX<PolicyDetailDO>()
                .eq(PolicyDetailDO::getPolicyId, policyId)
                .eq(PolicyDetailDO::getVoyageId, voyageId));
    }
}