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

import com.baomidou.mybatisplus.core.metadata.IPage;
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.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.resource.controller.admin.resource.vo.ResourcePageReqVO;
import com.yc.ship.module.resource.dal.dataobject.resource.ResourceDO;
import com.yc.ship.module.resource.dal.dataobject.supplier.ProductSupplierDO;
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 ResourceMapper extends BaseMapperX<ResourceDO> {

    default PageResult<ResourceDO> selectPage(ResourcePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ResourceDO>()
                .likeIfPresent(ResourceDO::getName, reqVO.getName())
                .eqIfPresent(ResourceDO::getIsUse, reqVO.getIsUse())
                .eqIfPresent(ResourceDO::getSupplierId, reqVO.getSupplierId())
                .eqIfPresent(ResourceDO::getSourceType, reqVO.getSourceType())
                .eqIfPresent(ResourceDO::getCategoryId, reqVO.getCategoryId())
                .betweenIfPresent(ResourceDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(ResourceDO::getEndTime, reqVO.getEndTime())
                .eqIfPresent(ResourceDO::getPrice, reqVO.getPrice())
                .eqIfPresent(ResourceDO::getAccessType, reqVO.getAccessType())
                .eqIfPresent(ResourceDO::getStock, reqVO.getStock())
                .betweenIfPresent(ResourceDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ResourceDO::getId));
    }

    IPage<ResourceDO> queryPage(IPage<ProductSupplierDO> iPage, @Param("param")ResourcePageReqVO pageReqVO);

    default List<ResourceDO> getSimpleResourceList(){
        return selectList(new LambdaQueryWrapperX<ResourceDO>()
                .eq(ResourceDO::getIsUse, UseStatusEnum.ENABLE.getStatus())
                .orderByDesc(ResourceDO::getId)
        );
    }

    /**
     * 根据基础产品id获取资源
     * @param id 基础产品id
     * @return 资源
     */
    ResourceDO getByProductBaseId(@Param("id") Long id);

    /**
     * 根据基础产品id获取资源
     * @param productBaseId 基础产品id
     * @param excludeId 排除资源id
     * @return 资源列表
     */
    List<ResourceDO> getListWithoutExcludeId(@Param("productBaseId") Long productBaseId, @Param("excludeId") Long excludeId);

    /**
     * 根据资源ID获取
     * @param id
     * @return
     */
    @TenantIgnore
    ResourceDO getByResourceId(@Param("id") Long id);


    List<ResourceDO> getResourceByCategoryId(@Param("categoryId") Long categoryId);
}