package shop.alien.store.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import shop.alien.entity.store.PlatformShopMembershipOrder;
import shop.alien.entity.store.dto.PlatformShopMembershipOrderCreateRequest;
import shop.alien.entity.store.vo.PlatformShopMembershipOrderCreateResultVo;
import shop.alien.entity.store.vo.PlatformShopMembershipOrderItemVo;

public interface PlatformShopMembershipOrderService extends IService<PlatformShopMembershipOrder> {

    /**
     * 创建待支付会员卡订单。完整流程、防抖与 Redis 行为见实现类
     * {@link shop.alien.store.service.impl.PlatformShopMembershipOrderServiceImpl#createPendingOrder}。
     */
    PlatformShopMembershipOrderCreateResultVo createPendingOrder(PlatformShopMembershipOrderCreateRequest request);

    IPage<PlatformShopMembershipOrderItemVo> pageHistory(Integer storeId, int pageNum, int pageSize);

    /**
     * 支付查单/回调成功后更新订单与店铺会员期限（幂等）
     */
    void applyPaySuccess(Integer membershipOrderId, java.util.Date payTime, String outTradeNo,
                         String tradeNo, String paymentMethod);

    /**
     * 解析当前会员到期日对应的已支付订单（优先 validity_end 与会员 expiry 一致的最新一单，否则取最近已支付单）
     */
    PlatformShopMembershipOrder findPaidOrderForCurrentMembershipExpiry(Integer storeId, java.util.Date membershipExpiryDate);
}
