package com.sonic.lion.service;

import com.sonic.lion.domain.bo.SubscriptionBo;
import com.sonic.lion.domain.entity.UserSubscriptionNotify;
import com.sonic.lion.domain.entity.UserSubscription;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author code
 */
public interface UserSubscriptionService {

    /**
     * 绑定 stripe 订阅 和 续订
     * @param subscriptionBo
     */
    void bindStripe(SubscriptionBo subscriptionBo);

    /**
     * 订阅 或 续订
     *
     * @param subscriptionId
     * @param platform
     * @param exptime
     * @param purchaseDate
     * @param productId
     */
    default void bind(String subscriptionId, UserSubscription.Platform platform, LocalDateTime exptime, LocalDateTime purchaseDate, String productId) {
        bind(subscriptionId, platform, exptime, purchaseDate, productId, null, null, null);
    }

    /**
     * 订阅 或 续订
     * @param subscriptionId
     * @param platform
     * @param exptime
     * @param purchaseDate
     * @param productId
     * @param userId
     * @param purchaseToken
     * @param ip
     */
    void bind(String subscriptionId, UserSubscription.Platform platform, LocalDateTime exptime, LocalDateTime purchaseDate, String productId, Long userId, String purchaseToken, String ip);

    /**
     * 根据订阅ID 获取 最近的一次 订阅。
     *
     * @param subscriptionId
     * @return
     */
    UserSubscription getBySubscriptionId(String subscriptionId);

    /**
     * 增加回调记录
     *
     * @param subscriptionId
     * @param content
     * @param type
     */
    Long addSubscriptionNotify(String subscriptionId, String messageId, String content, String type, UserSubscriptionNotify.Platform platform);

    /**
     * 增加回调记录
     *
     * @param subscriptionId
     * @param content
     * @param type
     */
    Long addSubscriptionNotifyV2(String subscriptionId, String messageId, String content, String extend, String type, UserSubscriptionNotify.Platform platform);

    /**
     * google token 设置
     *
     * @param id
     * @param token
     */
    void setPurchaseToken(Long id, String token);

    /**
     * 退订
     *
     * @param subscriptionId
     * @param platform
     * @param expTime
     */
    void cancel(String subscriptionId, UserSubscription.Platform platform, Long expTime);

    /**
     * 完成记录 通知日志
     *
     * @param notifyId
     */
    void completeNotify(Long notifyId);

    /**
     * 完成记录 通知日志
     * @param notifyId
     * @param subscriptionId
     */
    void updateStatusAndSubscriptionId(Long notifyId, String subscriptionId);

    /**
     * 更新通知日志 extend
     * @param notifyId
     * @param appleRefundRecordId
     * @param extend
     */
    void updateNotifyExtend(Long notifyId, Long appleRefundRecordId, String extend);

    /**
     * 通知日志 处理失败
     *
     * @param notifyId
     */
    void failNotify(Long notifyId);

    /**
     * 续期失败发送系统消息
     *
     * @param subscriptionId
     * @param platform
     */
    void payFailSystemMessage(String subscriptionId, UserSubscription.Platform platform);

    /**
     * 更新订阅状态 三方通知
     * @param subscriptionId
     * @param platform
     * @param productId
     * @param autoRenew
     */
    void updateStatusByThird(String subscriptionId, UserSubscription.Platform platform, String productId, Boolean autoRenew);

    /**
     * 查询用户是否是会员
     * @param userIdList
     * @return
     */
    List<Long> queryUserIsSubscribe(List<Long> userIdList);
}