package shop.alien.store.service;

import com.baomidou.mybatisplus.extension.service.IService;
import shop.alien.entity.store.PlatformShopMembershipPaymentOrder;

/**
 * 平台店铺会员卡支付单（独立表）
 */
public interface PlatformShopMembershipPaymentOrderService extends IService<PlatformShopMembershipPaymentOrder> {

    PlatformShopMembershipPaymentOrder getByOutTradeNo(String outTradeNo);

    String generatePaymentNo();

    /**
     * 同一会员卡订单重新预支付时，逻辑删除该订单下指定支付方式的待支付单
     */
    int logicDeletePendingByMembershipOrderIdAndPayType(Integer membershipOrderId, String payType);

    /**
     * 测试退款：根据会员卡业务订单 ID 解析「已支付」流水（门店从订单读取）。
     * 若 {@code outTradeNo} 非空则必须与该订单、支付方式一致且已支付；否则取该订单该支付方式下最近一笔已支付单。
     *
     * @return 匹配到的支付单；无匹配时返回 null
     */
    PlatformShopMembershipPaymentOrder findPaidPaymentForMembershipTestRefund(
            Integer membershipOrderId, String payType, String outTradeNo);

    /**
     * 退款成功后：支付单标为已退款，对应会员卡业务订单标为已退款（不调整 platform_shop_membership 权益周期，需运营另行处理）。
     */
    void markPaymentAndMembershipOrderRefunded(PlatformShopMembershipPaymentOrder paymentOrder);
}
