package com.seamew.lottery.domain.strategy.repository;

import com.seamew.lottery.domain.strategy.model.aggregates.StrategyRich;
import com.seamew.lottery.domain.strategy.model.res.AwardStockResult;
import com.seamew.lottery.domain.strategy.model.vo.AwardBriefVO;
import com.seamew.lottery.domain.strategy.model.vo.AwardDeductStockVO;

import java.util.List;

/**
 * @Author: seamew
 * @Title: IStrategyRepository
 * @CreateTime: 2023年02月13日 21:02:00
 * @Description: 策略表仓储服务
 * @Version: 1.0
 */
public interface IStrategyRepository {
    /**
     * 查询策略信息
     *
     * @param strategyId 策略ID
     * @return 策略信息
     */
    StrategyRich queryStrategyRich(Long strategyId);

    /**
     * 查询奖励配置
     *
     * @param awardId 奖励ID
     * @return 奖励信息
     */
    AwardBriefVO queryAwardInfo(String awardId);

    /**
     * 查询无库存奖品
     *
     * @param strategyId 策略ID
     * @return 无库存奖品
     */
    List<String> queryNoStockStrategyAwardList(Long strategyId);

    /**
     * 扣减库存
     *
     * @param strategyId 策略ID
     * @param awardId    奖品ID
     * @return 扣减结果
     */
    boolean deductStock(Long strategyId, String awardId);

    /**
     * 通过redis扣减库存
     *
     * @param strategyId 策略ID
     * @param awardId    奖品ID
     * @return 扣减结果
     */
    AwardStockResult deductStockByRedis(Long strategyId, String awardId);

    /**
     * 更新奖品库存
     *
     * @param awardDeductStockVO 奖品削减库存记录
     */
    void updateAwardStock(AwardDeductStockVO awardDeductStockVO);

    /**
     * 释放redis锁
     *
     * @param tokenKey 分布式 KEY 用于清理
     */
    void recoverAwardCacheStockByRedis(String tokenKey);
}
