using HoneyBox.Model.Entities;
using HoneyBox.Model.Models.Lottery;

namespace HoneyBox.Core.Interfaces;

/// <summary>
/// 抽奖引擎接口
/// 提供完整的抽奖流程，包括概率计算、权重选择、库存扣减、记录创建
/// </summary>
public interface ILotteryEngine
{
    /// <summary>
    /// 执行单次抽奖（基于库存概率）
    /// 适用于一番赏等使用库存作为概率权重的抽奖类型
    /// </summary>
    /// <param name="request">抽奖请求</param>
    /// <returns>抽奖结果</returns>
    Task<LotteryDrawResult> DrawAsync(LotteryDrawRequest request);

    /// <summary>
    /// 执行多次抽奖（基于库存概率）
    /// 循环调用DrawAsync执行多次抽奖
    /// </summary>
    /// <param name="request">抽奖请求</param>
    /// <param name="count">抽奖次数</param>
    /// <returns>抽奖结果列表</returns>
    Task<List<LotteryDrawResult>> DrawMultipleAsync(LotteryDrawRequest request, int count);

    /// <summary>
    /// 执行单次无限赏抽奖（基于真实概率 real_pro）
    /// 适用于无限赏等使用固定概率的抽奖类型
    /// </summary>
    /// <param name="request">抽奖请求</param>
    /// <returns>抽奖结果</returns>
    Task<LotteryDrawResult> DrawInfiniteAsync(LotteryDrawRequest request);

    /// <summary>
    /// 执行多次无限赏抽奖（基于真实概率 real_pro）
    /// 循环调用DrawInfiniteAsync执行多次抽奖
    /// </summary>
    /// <param name="request">抽奖请求</param>
    /// <param name="count">抽奖次数</param>
    /// <returns>抽奖结果列表</returns>
    Task<List<LotteryDrawResult>> DrawInfiniteMultipleAsync(LotteryDrawRequest request, int count);

    /// <summary>
    /// 计算奖品概率（基于库存）
    /// 概率公式：单个奖品概率 = (该奖品剩余库存 / 所有可抽奖品总剩余库存) * 100%
    /// </summary>
    /// <param name="goodsId">商品ID</param>
    /// <param name="num">箱号</param>
    /// <returns>奖品概率列表</returns>
    Task<List<PrizeProbability>> CalculateProbabilitiesAsync(int goodsId, int num);

    /// <summary>
    /// 计算奖品概率（基于真实概率 real_pro）
    /// 用于无限赏等使用固定概率的抽奖类型
    /// </summary>
    /// <param name="goodsId">商品ID</param>
    /// <param name="num">箱号</param>
    /// <returns>奖品概率列表</returns>
    Task<List<PrizeProbability>> CalculateProbabilitiesByRealProAsync(int goodsId, int num);

    /// <summary>
    /// 验证抽奖结果
    /// </summary>
    /// <param name="result">抽奖结果</param>
    /// <returns>是否有效</returns>
    Task<bool> ValidateDrawResultAsync(LotteryDrawResult result);

    /// <summary>
    /// 创建抽奖记录
    /// 用于外部调用创建抽奖记录（如道具卡抽奖、特殊抽奖等）
    /// </summary>
    /// <param name="request">抽奖请求</param>
    /// <param name="prize">选中的奖品</param>
    /// <returns>创建的订单详情记录</returns>
    Task<OrderItem> CreateDrawRecordAsync(LotteryDrawRequest request, PrizeProbability prize);

    /// <summary>
    /// 生成唯一奖品编码
    /// </summary>
    /// <returns>奖品编码</returns>
    string GeneratePrizeCode();

    /// <summary>
    /// 生成幸运号码
    /// </summary>
    /// <param name="goodsId">商品ID</param>
    /// <param name="num">箱号</param>
    /// <returns>幸运号码</returns>
    Task<int> GenerateLuckNoAsync(int goodsId, int num);
}
