package com.czg.order.service;

import cn.hutool.core.exceptions.ValidateException;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.entity.ShopInfo;
import com.czg.exception.CzgException;
import com.czg.exception.OrderCancelException;
import com.czg.exception.OrderValidateException;
import com.czg.order.dto.*;
import com.czg.order.entity.OrderDetail;
import com.czg.order.entity.OrderInfo;
import com.czg.order.enums.PayEnums;
import com.czg.order.vo.HistoryOrderPrintVo;
import com.czg.order.vo.HistoryOrderVo;
import com.czg.order.vo.OrderInfoVo;
import com.czg.pay.PayNotifyRespDTO;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import jakarta.validation.constraints.NotBlank;
import org.jetbrains.annotations.NotNull;

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

/**
 * 订单表 服务层。
 *
 * @author ww
 * @since 2025-02-13
 */
public interface OrderInfoCustomService {

    Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param);

    CzgResult<HistoryOrderVo> getOrderDetails(Long orderId);

    CzgResult<HistoryOrderPrintVo> getOrderByIdPrint(Long orderId);

    HistoryOrderVo historyOrder(Long orderId, String tableCode) throws CzgException;

    OrderInfo createOrder(OrderInfoAddDTO param) throws ValidateException, CzgException;

    OrderInfo checkOrderPay(CheckOrderPay param) throws OrderValidateException, OrderCancelException, CzgException;

    CzgResult<Object> mergeOrder(MergeOrderDTO param);

    void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, String channel, int retryCount);

    void refundCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);

    void upOrderInfo(OrderInfo orderInfo, BigDecimal payAmount, LocalDateTime payTime, Long payOrderId, PayEnums payType);

    void expired(Long orderId);

    OrderInfo createPayOrder(Long shopId, BigDecimal amount, String remark);

    void getOrderAmount(List<OrderDetail> orderDetails, BigDecimalDTO totalAmount, BigDecimalDTO packAmount,
                        BigDecimalDTO tempAmount, LimitRateDTO limitRate, boolean isAllPack, Integer userAllPack, boolean isVipPrice);

    Boolean printOrder(Long shopId, OrderInfoPrintDTO orderInfoPrintDTO);


    Boolean removeOrderDetail(Long shopId, Long orderId, Long detailId);

    Boolean cancelledOrder(Long shopId, Long orderId) throws OrderCancelException;

    Boolean cancelledPlaceOrder(Long shopId, Long orderId, Integer placeNum);


    Boolean updatePayOrderId(Long orderId, Long paymentId, String payType, String remark);

    void updateOrderDetailStatus(Long orderDetailId);

    Boolean upOrderDetail(Long shopId, OrderDetailStatusDTO detailStatusDTO);


    /**
     * 退单库存问题
     */
    void refundStock(ShopInfo shopInfo, Long orderId, Map<Long,BigDecimal> products, boolean refundStock);
}
