package com.yc.ship.module.trade.service.order;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.ship.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.trade.api.sms.dto.SmsSendLogDTO;
import com.yc.ship.module.trade.controller.admin.order.vo.check.CheckOrderPageVO;
import com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO;
import com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderPdaRespVO;
import com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO;
import com.yc.ship.module.trade.controller.admin.smsSendconfig.vo.SmsSendconfigQueryRespVO;
import com.yc.ship.module.trade.controller.app.pda.vo.PdaQueryOrderReqVO;
import com.yc.ship.module.trade.controller.app.pda.vo.PdaQueryVoucherReqVO;
import com.yc.ship.module.trade.dal.dataobject.order.*;
import com.yc.ship.module.trade.enums.TradeOrderBindEnum;
import com.yc.ship.module.trade.service.order.bo.*;
import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * &#064;Description 订单数据service接口
 * &#064;Author qsl
 * &#064;Date 2025/6/4 15:03
 * @author qsl
 */
public interface TradeOrderRepositoryService {

    String CHANGE_ORDER_LOCK = "order:change:lock:%d";

    /**
     * 订单保存
     *
     */
    void saveOrder(TradeOrderBO tradeOrderBO);

    void modifyOrder(TradeOrderBO tradeOrderBO,TradeOrderDO oldOrder);
    void updateInvoiceStatusByOrderNo(List<String> orderNoList, Integer invoiceStatus);
    /**
     * 更新订单状态
     *
     */
    void updateOrderStatus(TradeOrderDO tradeOrderDO);


    TradeOrderDO getById(Long id);

    void savePayOrder(TradeOrderPayDO tradeOrderPayDO);

    void updatePayOrderStatus(TradeOrderPayDO tradeOrderPayDO);

    BigDecimal getHadPayAmount(Long orderId);


    /**
     * 全部支付完成后更新订单
     *
     */
    void updateOrderAfterAllPay(TradeOrderDO tradeOrderDO);

    TradeOrderPayDO getPayOrderById(Long id);

    /**
     * 全部供应商支付完成后更新订单
     *
     */
    void updateOrderAfterAllSupplierPay(TradeOrderDO tradeOrderDO);


    void updateStatusAfterAllCheck(Long id);

    List<TradeVisitorBO> getVisitorVoucherListByOrderId(Long orderId);


    TradeOrderDO getOrderByNo(String orderNo);

    /**
     * 更新支付单支付参数
     *
     */
    void updatePayOrderPayParams(TradeOrderPayDO tradeOrderPayDO);

    List<TradeDetailDO> queryDetailByOrderId(Long orderId);
    List<TradeDetailDO> queryYcDetailByOrderId(Long orderId);

    /**
     * 查找分销商订单
     *
     */
    TradeOrderDO getOrderByOtaAndExternalOrderNo(String otaOrderNo, String sourceId);

    List<TradeVisitorDO> queryVisitorByDetailId(Long detailId);

    List<TradeDetailBO> getTradeDetailWithBase(Long orderId, Long tradeDetailId, List<String> voucherList);

    List<TradeDetailBO> getTradeDetailWithBase(Long orderId, List<Long> detailIdList);

    TradeOrderUserDO getOrderUser(Long orderId);

    Map<String, Object> queryDetailCountByOrderId(Long orderId);

    List<TradeOrderPayDO> getOrderPayList(Long orderId);

    Map<String, Long> getRefundCount(Long orderId);

    TradeMchInfoDO getByMchId(String mchId);

    Long queryEffectyCount(Long orderId);

    void cancelOrder(Long orderId);

    void createOrderFail(Long orderId);

    TradeDetailDO queryByOrderIdAndPassengerId(Long id, String passengerId);

    TradeDetailDO queryDetailVoucherCode(String code, Long orderId);

    TradeDetailDO getOrderAnyDetail(Long orderId);

    TradeOrderPayDO getPayOrderByIdIgnoreTenant(Long id);

    List<Map<String, Object>> getDetailInfoByDetailId(Map<String, Object> detailId);

    void updateInvoiceStatus(List<TradeOrderDO> orderList, Integer invoiceStatus);

    List<TradeVisitorBO> getInsureVisitor(Long orderId, Long productId);

    List<Map<String, Object>> getInsuranceProductFromOrder(Long orderId);

    void updateOrderInsureStatus(Long orderId, Integer status);

    List<Map<String, Object>> getContractProductFromOrder(Long orderId);

    List<TradeVisitorBO> getContractVisitor(Long orderId, Long productId);

    void updateOrderContractStatus(Long orderId, Integer status);

    List<TradeDetailRespVO> getDetailAndVisitor(Long orderId, List<String> detailVoucherList);

    void saveVisitorList(List<TradeVisitorDO> tradeVisitorDOList);

    void saveBindOrder(TradeOrderBindDO tradeOrderBindDO);

    TradeOrderBindDO getBindOrder(Long orderId, Long bindId, Integer type);

    TradeOrderBindDO getBindOrder(Long bindId, Integer type);

    TradeOrderBindDO getBindByOrder(Long orderId);

    void deleteOrderBind(Long id);

    void cancelBindOrder(TradeOrderBindDO tradeOrderBindDO);

    TradeOrderBindDO getBindOrderByBindId(Long bindId, TradeOrderBindEnum type);

    List<TradeOrderBindDO> getBindOrderByOrderId(Long orderId, TradeOrderBindEnum type);


    void insertOrUpdateVisitor(List<TradeVisitorDO> tradeVisitorDOList);

    @Async
    void updateVis(Long id);

    void updateTransOrder(TradeOrderDO tradeOrderDO);

    List<Map<String, Object>> queryNotifyFailedVoucherInfo(Map<String, Object> param);

    List<TradeDetailRespVO> getTradeDetailWithBaseByCodeAndIdcard(PdaQueryVoucherReqVO reqVO);

    TradeDetailRespVO getTradeDetailByCheckId(Long checkId);

    List<TradeOrderPdaRespVO> getOrderAndDetail(PdaQueryOrderReqVO reqVO);

    String getPlatOrderNo(String orderNo);
    BigDecimal getTotalPayByOrderNo(String orderNo);

    IPage<TradeOrderRespVO> getCheckOrder(CheckOrderPageVO reqVO);

    void delOrderDispatch(TradeOrderDispatchDO tradeOrderDispatchDO);

    void saveOrderDispatch(List<TradeOrderDispatchDO> tradeOrderDispatchDOList);

    List<Long> getOrderIdListByDispatchId(String dispatchId, String projectCode);


    void afterOrderDispatch(TreeSet<Long> orderIdList, Long tenantId);

    void updateOrderBatch(List<TradeOrderDO> tradeOrderDOList);

    Map<String, Long> getDispatchCount(Long orderId);

    List<Map<String, Object>> getOrderProduct(Long orderId);

    List<Map<String, Object>> getVisitorOrderProductCount(Long productId, LocalDateTime useDate, List<String> credentialNoList, Long excludeOrderId);

    List<Map<String, Object>> getVisitorOrderProductBaseCount(Long productBaseId, LocalDateTime useDate, List<String> credentialNoList, Long excludeOrderId);


    void updatePayOrder(TradeOrderPayDO tradeOrderPayDO);

    @TenantIgnore
    TradeOrderDO getOrderByOrderNoWithoutTenant(String orderNo);


    void saveChangeDetail(List<Long> detailList, Long orderId, Long originOrderId);

    List<TradeDetailDO> getDetailListByIds(List<Long> detailList, Long orderId);

    List<TradeDetailDO> getPlatDetailByDetailIds(List<Long> detailList, Long orderId);

    List<TradeDetailDO> getPlatDetailByOrderId(Long orderId);

    List<TradeDetailDO> getChangeDetailList(Long orderId, Long originOrderId);

    List<SmsSendconfigQueryRespVO> getCreateOrderSmsInfo(Long orderId, Integer type);
    List<SmsSendconfigQueryRespVO> getOrderSmsInfo(Long orderId, Integer type);

    void insertSmsLog(SmsSendLogDTO smsSendLogDTO);

    void updatePayAmountByMarketingRefund(Long orderId, BigDecimal payAmount);

    void updateSellNumByProduct(Long productId, int num);

    IPage<TradeVisitorBO> getVisitorListByDate(IPage<TradeVisitorBO> page, Long orderId, Date useDate, Long tenantId);

    void batchUpdate(List<TradeDetailDO> tradeDetailDOList, List<TradeDetailBaseDO> tradeDetailBaseDOList);

    void updateOrderStatusAfterCheck(Long orderId);

    List<TradeOrderDO> getCanBindOrderList(TradeBindOrderQueryBO vo);

    @Transactional
    void updateAddOrder(TradeOrderDO addOrder, TradeOrderDO mainOrder);


    int getInvoiceOrderCount(String orderNo);

    List<TradeDetailDO> getUnUsedDetailList(Long orderId);

    Long getOrderDetailCount(Long orderId);

    BigDecimal getUnUsedAmount(Long orderId);

    BigDecimal getPlatPayAmountByOriginOrderNo(String originOrderNo);

    void updateOrderPlatAmount(String orderNo, BigDecimal payAmount);


    List<TradeDetailPriceDO> getDetailPriceByDetailIds(List<Long> detailIds);

    void batchUpdateDetailPrice(List<TradeDetailPriceDO> tradeDetailPriceDOList);

    List<TradeOrderHotelDO> getHotelBookingInfoByOrderId(Long id);

    void updateOrderConfirmType(Long orderId, Integer confirmType);

    List<TradeOrderDO> getByExternalOriginOrderNo(String externalOriginOrderNo);

    Long getCheckCount(Long orderId);

    List<Map<String, Object>> selectContractByOrderId(Long orderId);

    void markChangeOrder(Long orderId, Integer type);

    int updateOrderFinishStatus(List<Integer> sellMethodList, String endDate);

    List<TradeDetailGuideRefundBO> getInnerTradeDetailWithBaseByGuideRefund(String refundId);

    List<TradeDetailGuideRefundBO> getTradeDetailWithBaseByGuideRefund(String refundId);

    Map<String, BigDecimal> getSelfDetailTotalAmount(Long detailId);

    Integer getOrderVisitorCount(Long orderId);
}
