using System.Text.Json.Serialization;

namespace HoneyBox.Model.Models.Rank;

/// <summary>
/// 排行榜响应 - 匹配PHP接口格式
/// </summary>
public class RankResponse
{
    /// <summary>
    /// 日期范围显示 (如: "01月01日-01月07日")
    /// </summary>
    [JsonPropertyName("date")]
    public string Date { get; set; } = string.Empty;

    /// <summary>
    /// 结束时间戳
    /// </summary>
    [JsonPropertyName("end_date")]
    public long EndDate { get; set; }

    /// <summary>
    /// 当前用户排名信息
    /// </summary>
    [JsonPropertyName("my_rank")]
    public MyRankDto MyRank { get; set; } = new();

    /// <summary>
    /// 排行榜列表 (前30名)
    /// </summary>
    [JsonPropertyName("data")]
    public List<RankItemDto> Data { get; set; } = new();
}

/// <summary>
/// 当前用户排名信息
/// </summary>
public class MyRankDto
{
    /// <summary>
    /// 排名 (字符串，未上榜时为"暂未上榜")
    /// </summary>
    [JsonPropertyName("my_rank")]
    public object MyRank { get; set; } = "暂未上榜";

    /// <summary>
    /// 奖品标题
    /// </summary>
    [JsonPropertyName("my_prize_title")]
    public object MyPrizeTitle { get; set; } = 0;

    /// <summary>
    /// 奖品图片
    /// </summary>
    [JsonPropertyName("my_prize_imgurl")]
    public object MyPrizeImgurl { get; set; } = 0;

    /// <summary>
    /// 消费金额
    /// </summary>
    [JsonPropertyName("my_order_total")]
    public decimal MyOrderTotal { get; set; }

    /// <summary>
    /// 用户昵称
    /// </summary>
    [JsonPropertyName("my_nickname")]
    public string MyNickname { get; set; } = string.Empty;

    /// <summary>
    /// 用户头像
    /// </summary>
    [JsonPropertyName("my_headimg")]
    public string MyHeadimg { get; set; } = string.Empty;
}

/// <summary>
/// 排行榜项DTO
/// </summary>
public class RankItemDto
{
    /// <summary>
    /// 排名
    /// </summary>
    [JsonPropertyName("rank")]
    public int Rank { get; set; }

    /// <summary>
    /// 用户ID
    /// </summary>
    [JsonPropertyName("user_id")]
    public int UserId { get; set; }

    /// <summary>
    /// 昵称
    /// </summary>
    [JsonPropertyName("nickname")]
    public string Nickname { get; set; } = string.Empty;

    /// <summary>
    /// 头像
    /// </summary>
    [JsonPropertyName("headimg")]
    public string Headimg { get; set; } = string.Empty;

    /// <summary>
    /// 消费金额
    /// </summary>
    [JsonPropertyName("order_total")]
    public decimal OrderTotal { get; set; }

    /// <summary>
    /// 奖品标题
    /// </summary>
    [JsonPropertyName("prize_title")]
    public string PrizeTitle { get; set; } = string.Empty;

    /// <summary>
    /// 奖品图片
    /// </summary>
    [JsonPropertyName("prize_imgurl")]
    public string PrizeImgurl { get; set; } = string.Empty;
}

/// <summary>
/// 用户排名DTO (旧版本兼容)
/// </summary>
public class UserRankDto
{
    /// <summary>
    /// 排名 (0表示未上榜)
    /// </summary>
    public int Rank { get; set; }

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

    /// <summary>
    /// 距离上一名差距
    /// </summary>
    public decimal Gap { get; set; }
}

/// <summary>
/// 通用排行榜项DTO - 用于getRankList接口
/// </summary>
public class GenericRankItemDto
{
    /// <summary>
    /// 排名
    /// </summary>
    [JsonPropertyName("rank")]
    public int Rank { get; set; }

    /// <summary>
    /// 用户ID
    /// </summary>
    [JsonPropertyName("user_id")]
    public int UserId { get; set; }

    /// <summary>
    /// 昵称
    /// </summary>
    [JsonPropertyName("nickname")]
    public string Nickname { get; set; } = string.Empty;

    /// <summary>
    /// 头像
    /// </summary>
    [JsonPropertyName("headimg")]
    public string Headimg { get; set; } = string.Empty;

    /// <summary>
    /// 数值 (钻石/积分/达达卷/邀请人数/亏损金额)
    /// </summary>
    [JsonPropertyName("value")]
    public decimal Value { get; set; }

    /// <summary>
    /// 单位 (钻石/UU币/达达卷/人/元)
    /// </summary>
    [JsonPropertyName("unit")]
    public string Unit { get; set; } = string.Empty;
}

/// <summary>
/// 亏损排行榜项DTO - 包含更多详细信息
/// </summary>
public class LossRankItemDto : GenericRankItemDto
{
    /// <summary>
    /// 微信消费金额
    /// </summary>
    [JsonPropertyName("consume_money")]
    public decimal ConsumeMoney { get; set; }

    /// <summary>
    /// 达达卷金额
    /// </summary>
    [JsonPropertyName("dada_money")]
    public decimal DadaMoney { get; set; }

    /// <summary>
    /// 出货金额
    /// </summary>
    [JsonPropertyName("output_money")]
    public decimal OutputMoney { get; set; }

    /// <summary>
    /// 亏损率(%)
    /// </summary>
    [JsonPropertyName("loss_rate")]
    public decimal LossRate { get; set; }
}

/// <summary>
/// 消费记录排行榜项DTO - 用于record接口
/// </summary>
public class ConsumeRecordItemDto
{
    /// <summary>
    /// 用户ID
    /// </summary>
    [JsonPropertyName("user_id")]
    public int UserId { get; set; }

    /// <summary>
    /// 昵称
    /// </summary>
    [JsonPropertyName("nickname")]
    public string Nickname { get; set; } = string.Empty;

    /// <summary>
    /// 头像
    /// </summary>
    [JsonPropertyName("headimg")]
    public string Headimg { get; set; } = string.Empty;

    /// <summary>
    /// 手机号
    /// </summary>
    [JsonPropertyName("mobile")]
    public string Mobile { get; set; } = string.Empty;

    /// <summary>
    /// 消费金额
    /// </summary>
    [JsonPropertyName("price")]
    public decimal Price { get; set; }
}

/// <summary>
/// 消费记录排行榜响应
/// </summary>
public class ConsumeRecordResponse
{
    /// <summary>
    /// 排行榜列表
    /// </summary>
    [JsonPropertyName("list")]
    public List<ConsumeRecordItemDto> List { get; set; } = new();
}

/// <summary>
/// 排行榜类型枚举
/// </summary>
public enum RankType
{
    /// <summary>
    /// 钻石排行榜
    /// </summary>
    Diamond,

    /// <summary>
    /// UU币排行榜
    /// </summary>
    Integral,

    /// <summary>
    /// 达达卷排行榜
    /// </summary>
    Dadajuan,

    /// <summary>
    /// 邀请新人排行榜
    /// </summary>
    Invite,

    /// <summary>
    /// 亏损补贴排行榜
    /// </summary>
    Loss
}
