package com.qnfhq.modules.c2c.service;


import com.qnfhq.common.page.PageData;
import com.qnfhq.common.service.BaseService;
import com.qnfhq.common.utils.Result;
import com.qnfhq.modules.c2c.dto.C2cOrderCreateDTO;
import com.qnfhq.modules.c2c.dto.C2cOrderDTO;
import com.qnfhq.modules.c2c.entity.C2cAdEntity;
import com.qnfhq.modules.c2c.entity.C2cOrderComplainEntity;
import com.qnfhq.modules.c2c.entity.C2cOrderEntity;

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

/**
 * c2c订单
 *
 * @author yelz 30262728@qq.com
 * @since 1.0.0 2025-11-17
 */
public interface C2cOrderService extends BaseService<C2cOrderEntity> {

    PageData<C2cOrderEntity> page(Map<String, Object> params);

    /**
     * c2c订单编号缓存Key
     * @return
     */
    String getC2cOrderKeyByUid(String uid);

    /**
     * 查询进行中的订单
     * @param adId
     * @return
     */
    C2cOrderEntity getTradingByAdId(long adId);


    /**
     * 查询订单
     * @param id
     * @return
     */
    C2cOrderEntity selectOrder(Long id);

    /**
     * 删除订单缓存
     * @param c2cOrder
     * @return
     */
    void deleteOrderCache(C2cOrderEntity c2cOrder);
    void deleteOrderCache(String orderId,String userId);


    /**
     * 创建订单
     * @param c2cOrder
     * @return
     * @throws Exception
     */
    public Result createC2cOrder(C2cOrderCreateDTO c2cOrder, C2cAdEntity c2cAd,BigDecimal legalCoinAmount, BigDecimal symbolNum,
                                 Long loginUserId, String realName) throws Exception;


    /**
     * 取消订单删除缓存
     * @param oldStatus
     * @param order
     * @return
     */
    int cancelC2cOrderRedis(int oldStatus,C2cOrderEntity order);

    /**
     * 用户取消订单
     * @param order
     * @param loginId
     * @return
     * @throws Exception
     */
    int cancelC2cOrder(C2cOrderEntity order,Long loginId) throws Exception;

    /**
     * 客服取消订单
     * @param order
     * @param loginId
     * @return
     * @throws Exception
     */
    int kfCancelC2cOrder(C2cOrderEntity order,Long loginId) throws Exception;

    /**
     * 确认已付款
     * @param c2cOrder
     * @return
     */
    public Result confirmPay(C2cOrderEntity c2cOrder,Long loginId) throws Exception;

    /**
     * 卖家确认收款然后放币
     */
    public int verifyReceipt(C2cOrderEntity c2cOrder,Long loginId) throws Exception;

    /**
     * 客服放币
     * @param order
     * @param loginId
     * @return
     * @throws Exception
     */
    int kfPassCoin(C2cOrderEntity order,Long loginId) throws Exception;
    /**
     * 查询订单付款凭证
     * @param orderList
     */
    public List<C2cOrderEntity> selectPaymentVoucherByOrderList(List<C2cOrderEntity> orderList);

    /**
     * 获取商户待付款订单
     * @param tranUserId
     * @return
     */
//    List<Map> selectMtUnPayCount(Long tranUserId);

    /**
     *  获取商户待放币订单
     * @param tranUserId
     * @return
     */
//    List<Map> selectMtUnReleaseCount(Long tranUserId);


    /**
     * 申诉
     * @param c2cOrder
     * @param c2cOrderComplain
     * @param loginId
     * @return
     * @throws Exception
     */
    public Result complain(C2cOrderEntity c2cOrder, C2cOrderComplainEntity c2cOrderComplain, Long loginId) throws Exception;


    /**
     * 设置商户待付款订单数
     * @param unpayCountsKey
     * @return
     */
    Integer setMtUnPayCount(String unpayCountsKey);

    /**
     * 设置商户待放币订单数
     * @param releaseCountsKey
     * @return
     */
    Integer setMtUnReleaseCount(String releaseCountsKey);

    /**
     * 检测是否交易用户
     * @param order
     * @return
     */
    boolean checkOrderTranUser(C2cOrderEntity order);

}