package co.yixiang.yshop.module.order.dal.mysql.storeorderdetail;


import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.module.order.controller.admin.storeorderdetail.vo.StoreOrderDetailExportReqVO;
import co.yixiang.yshop.module.order.controller.admin.storeorderdetail.vo.StoreOrderDetailPageReqVO;
import co.yixiang.yshop.module.order.dal.dataobject.storeorderdetail.StoreOrderDetailDO;
import org.apache.ibatis.annotations.Mapper;
import co.yixiang.yshop.module.order.controller.app.order.vo.AppOrderDetailVO;

import co.yixiang.yshop.framework.common.pojo.PageResult;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 订单明细 Mapper
 *
 * @author moxiangrong
 */
@Mapper
public interface StoreOrderDetailMapper extends BaseMapperX<StoreOrderDetailDO> {

    default PageResult<StoreOrderDetailDO> selectPage(StoreOrderDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<StoreOrderDetailDO>()
                .eqIfPresent(StoreOrderDetailDO::getOid, reqVO.getOid())
                .eqIfPresent(StoreOrderDetailDO::getProductId, reqVO.getProductId())
                .eqIfPresent(StoreOrderDetailDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(StoreOrderDetailDO::getProductAttrUnique, reqVO.getProductAttrUnique())
                .eqIfPresent(StoreOrderDetailDO::getOriginalPrice, reqVO.getOriginalPrice())
                .eqIfPresent(StoreOrderDetailDO::getPrice, reqVO.getPrice())
                .eqIfPresent(StoreOrderDetailDO::getState, reqVO.getState())
                .betweenIfPresent(StoreOrderDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StoreOrderDetailDO::getId));
    }

    default List<StoreOrderDetailDO> selectList(StoreOrderDetailExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<StoreOrderDetailDO>()
                .eqIfPresent(StoreOrderDetailDO::getOid, reqVO.getOid())
                .eqIfPresent(StoreOrderDetailDO::getProductId, reqVO.getProductId())
                .eqIfPresent(StoreOrderDetailDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(StoreOrderDetailDO::getProductAttrUnique, reqVO.getProductAttrUnique())
                .eqIfPresent(StoreOrderDetailDO::getOriginalPrice, reqVO.getOriginalPrice())
                .eqIfPresent(StoreOrderDetailDO::getPrice, reqVO.getPrice())
                .eqIfPresent(StoreOrderDetailDO::getState, reqVO.getState())
                .betweenIfPresent(StoreOrderDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StoreOrderDetailDO::getId));
    }


    List<AppOrderDetailVO> getOrderDetails(@Param("productAttrUniques") List<String> productAttrUniques,
                                           @Param("oid") Long oid);


    void batchInsert(@Param("list") List<StoreOrderDetailDO> list);

}
