namespace HoneyBox.Admin.Business.Models.Rank;

#region Request Models

/// <summary>
/// 排行榜奖品列表查询请求
/// </summary>
public class RankPrizeListRequest : PagedRequest
{
    /// <summary>
    /// 奖品名称关键词（模糊搜索）
    /// </summary>
    public string? Keyword { get; set; }
}

/// <summary>
/// 创建排行榜奖品请求
/// </summary>
public class RankPrizeCreateRequest
{
    /// <summary>
    /// 排名
    /// </summary>
    public int Rank { get; set; }

    /// <summary>
    /// 奖品名称
    /// </summary>
    public string Title { get; set; } = string.Empty;

    /// <summary>
    /// 奖品图片URL
    /// </summary>
    public string ImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 售价
    /// </summary>
    public decimal Price { get; set; }

    /// <summary>
    /// 采购价
    /// </summary>
    public decimal CostPrice { get; set; }

    /// <summary>
    /// 奖品等级ID
    /// </summary>
    public int PrizeTypeId { get; set; }
}

/// <summary>
/// 更新排行榜奖品请求
/// </summary>
public class RankPrizeUpdateRequest : RankPrizeCreateRequest
{
}

/// <summary>
/// 排行榜中奖记录列表查询请求
/// </summary>
public class RankLogListRequest : PagedRequest
{
    /// <summary>
    /// 用户ID
    /// </summary>
    public int? UserId { get; set; }

    /// <summary>
    /// 手机号
    /// </summary>
    public string? Mobile { get; set; }
}

/// <summary>
/// 用户排行榜查询请求
/// </summary>
public class UserRankListRequest : PagedRequest
{
    /// <summary>
    /// 排行榜类型：invite-邀请新人, loss-亏损补贴, dada-达达券, diamond-钻石, uu-UU币
    /// </summary>
    public string Type { get; set; } = "invite";
}

#endregion

#region Response Models

/// <summary>
/// 排行榜奖品响应模型
/// </summary>
public class RankPrizeResponse
{
    /// <summary>
    /// 奖品ID
    /// </summary>
    public int Id { get; set; }

    /// <summary>
    /// 排名
    /// </summary>
    public int Rank { get; set; }

    /// <summary>
    /// 奖品名称
    /// </summary>
    public string Title { get; set; } = string.Empty;

    /// <summary>
    /// 奖品图片URL
    /// </summary>
    public string ImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 售价
    /// </summary>
    public decimal Price { get; set; }

    /// <summary>
    /// 采购价
    /// </summary>
    public decimal CostPrice { get; set; }

    /// <summary>
    /// 奖品等级ID
    /// </summary>
    public int PrizeTypeId { get; set; }

    /// <summary>
    /// 奖品等级名称
    /// </summary>
    public string PrizeTypeName { get; set; } = string.Empty;

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime? CreatedAt { get; set; }
}


/// <summary>
/// 排行榜中奖记录响应模型
/// </summary>
public class RankLogResponse
{
    /// <summary>
    /// 记录ID
    /// </summary>
    public int Id { get; set; }

    /// <summary>
    /// 用户ID
    /// </summary>
    public int UserId { get; set; }

    /// <summary>
    /// 用户UID
    /// </summary>
    public string Uid { get; set; } = string.Empty;

    /// <summary>
    /// 用户昵称
    /// </summary>
    public string Nickname { get; set; } = string.Empty;

    /// <summary>
    /// 用户头像
    /// </summary>
    public string HeadImg { get; set; } = string.Empty;

    /// <summary>
    /// 用户手机号
    /// </summary>
    public string Mobile { get; set; } = string.Empty;

    /// <summary>
    /// 排名
    /// </summary>
    public int Rank { get; set; }

    /// <summary>
    /// 奖品名称
    /// </summary>
    public string PrizeTitle { get; set; } = string.Empty;

    /// <summary>
    /// 奖品图片URL
    /// </summary>
    public string PrizeImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 消费金额
    /// </summary>
    public decimal ConsumeAmount { get; set; }

    /// <summary>
    /// 统计时间范围
    /// </summary>
    public string TimeRange { get; set; } = string.Empty;

    /// <summary>
    /// 添加时间
    /// </summary>
    public DateTime CreatedAt { get; set; }
}

/// <summary>
/// 用户排行榜响应模型
/// </summary>
public class UserRankResponse
{
    /// <summary>
    /// 排名
    /// </summary>
    public int Rank { get; set; }

    /// <summary>
    /// 用户ID
    /// </summary>
    public int UserId { get; set; }

    /// <summary>
    /// 用户UID
    /// </summary>
    public string Uid { get; set; } = string.Empty;

    /// <summary>
    /// 用户昵称
    /// </summary>
    public string Nickname { get; set; } = string.Empty;

    /// <summary>
    /// 用户头像
    /// </summary>
    public string HeadImg { get; set; } = string.Empty;

    /// <summary>
    /// 数值（邀请人数/货币数量等）
    /// </summary>
    public decimal Value { get; set; }

    /// <summary>
    /// 单位
    /// </summary>
    public string Unit { get; set; } = string.Empty;

    /// <summary>
    /// 消耗金额（亏损排行榜特有）
    /// </summary>
    public decimal? ConsumeAmount { get; set; }

    /// <summary>
    /// 达达券金额（亏损排行榜特有）
    /// </summary>
    public decimal? DadaCoinAmount { get; set; }

    /// <summary>
    /// 出货金额（亏损排行榜特有）
    /// </summary>
    public decimal? ShipAmount { get; set; }

    /// <summary>
    /// 亏损率（亏损排行榜特有）
    /// </summary>
    public decimal? LossRate { get; set; }
}

/// <summary>
/// 奖品类型响应模型
/// </summary>
public class PrizeTypeResponse
{
    /// <summary>
    /// 类型ID
    /// </summary>
    public int Id { get; set; }

    /// <summary>
    /// 类型名称
    /// </summary>
    public string Title { get; set; } = string.Empty;

    /// <summary>
    /// 排序
    /// </summary>
    public int Sort { get; set; }
}

#endregion

#region Helper Classes

/// <summary>
/// 用户排行榜类型枚举
/// </summary>
public static class UserRankTypes
{
    public const string Invite = "invite";     // 邀请新人
    public const string Loss = "loss";         // 亏损补贴
    public const string DadaCoin = "dada";     // 达达券
    public const string Diamond = "diamond";   // 钻石
    public const string UUCoin = "uu";         // UU币

    public static string GetTypeName(string type) => type switch
    {
        Invite => "邀请新人",
        Loss => "亏损补贴",
        DadaCoin => "达达券",
        Diamond => "钻石",
        UUCoin => "UU币",
        _ => "未知类型"
    };

    public static bool IsValid(string type) => type switch
    {
        Invite or Loss or DadaCoin or Diamond or UUCoin => true,
        _ => false
    };
}

#endregion
