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

import co.yixiang.yshop.framework.common.pojo.PageResult;
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.storeaftersales.vo.StoreAfterSalesPageReqVO;
import co.yixiang.yshop.module.order.dal.dataobject.storeaftersales.StoreAfterSalesDO;
import co.yixiang.yshop.module.order.enums.AdminAfterOrderStatusEnum;
import co.yixiang.yshop.module.order.enums.AfterSalesStatusEnum;
import org.apache.ibatis.annotations.Mapper;

/**
 * 售后记录 Mapper
 *
 * @author yshop
 */
@Mapper
public interface StoreAfterSalesMapper extends BaseMapperX<StoreAfterSalesDO> {

    default PageResult<StoreAfterSalesDO> selectPage(StoreAfterSalesPageReqVO reqVO) {
        LambdaQueryWrapperX<StoreAfterSalesDO> wrapper = new LambdaQueryWrapperX();
        wrapper.eqIfPresent(StoreAfterSalesDO::getOrderCode, reqVO.getOrderCode())
                .orderByDesc(StoreAfterSalesDO::getId);
        if(reqVO.getType() != null){
            switch (AdminAfterOrderStatusEnum.toType(reqVO.getType())) {
                //售后中
                case STATUS_1:
                    wrapper.ne(StoreAfterSalesDO::getState, AfterSalesStatusEnum.STATUS_3.getValue());
                    break;
                //已完成
                case STATUS_2:
                    wrapper.eq(StoreAfterSalesDO::getState, AfterSalesStatusEnum.STATUS_3.getValue());
                    break;

                default:
            }
        }
        return selectPage(reqVO, wrapper);
    }



}
