using QYZH.InteractiveMagazine.Models.Enum;

namespace QYZH.InteractiveMagazine.Models.Dto;

/// <summary>
/// 勋章创建/更新输入
/// </summary>
public class MedalInput
{
    /// <summary>
    /// 勋章名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 获得条件描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 图片地址
    /// </summary>
    public string? ImageUrl { get; set; }

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

    /// <summary>
    /// 勋章的类型: Pet, Community
    /// </summary>
    public string Type { get; set; } = MedalTypeEnum.System.ToString();

    /// <summary>
    /// 期刊id
    /// </summary>
    public long? JournalId { get; set; }

    /// <summary>
    /// 勋章规则列表
    /// </summary>
    public List<MedalRuleInput>? Rules { get; set; }
}

/// <summary>
/// 勋章输出
/// </summary>
public class MedalOutput
{
    /// <summary>
    /// 主键ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 勋章名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 获得条件描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 图片地址
    /// </summary>
    public string? ImageUrl { get; set; }

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

    /// <summary>
    /// 勋章的类型
    /// </summary>
    public string Type { get; set; } = string.Empty;

    /// <summary>
    /// 书id
    /// </summary>
    public long? JournalId { get; set; }
    /// <summary>
    /// 勋章状态
    /// </summary>
    public DefaultStatusEnum Status {  get; set; }

    /// <summary>
    /// 勋章规则列表
    /// </summary>
    public List<MedalRuleOutput>? Rules { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    public string? CreatedBy { get; set; }

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

    /// <summary>
    /// 更新人
    /// </summary>
    public string? UpdatedBy { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdatedAt { get; set; }
}

/// <summary>
/// 勋章分页查询输入
/// </summary>
public class MedalQueryInput : PageQueryModel
{
    /// <summary>
    /// 勋章名称（模糊查询）
    /// </summary>
    public string? Name { get; set; }

    /// <summary>
    /// 勋章的类型: Pet, Community
    /// </summary>
    public string? Type { get; set; }
}

/// <summary>
/// 勋章规则输入
/// </summary>
public class MedalRuleInput
{
    /// <summary>
    /// 目标表名（如：JournalPageTask、UserAction等）
    /// </summary>
    public string TargetTable { get; set; } = string.Empty;

    /// <summary>
    /// 目标字段名（如：TotalScore、LoginDays等）
    /// </summary>
    public string TargetField { get; set; } = string.Empty;

    /// <summary>
    /// 比较运算符: >=, >, =, <=, <
    /// </summary>
    public string Operator { get; set; } = ">=";

    /// <summary>
    /// 阈值数量
    /// </summary>
    public int ThresholdValue { get; set; }

    /// <summary>
    /// 额外筛选条件（JSON格式）
    /// </summary>
    public string? FilterCondition { get; set; }

    /// <summary>
    /// 时间范围类型: All/CurrentMonth/CurrentWeek/Last7Days/Custom
    /// </summary>
    public string? DateRangeType { get; set; }

    /// <summary>
    /// 自定义起始时间
    /// </summary>
    public DateTime? DateRangeStart { get; set; }

    /// <summary>
    /// 自定义结束时间
    /// </summary>
    public DateTime? DateRangeEnd { get; set; }

    /// <summary>
    /// 多规则间的逻辑关系: AND/OR
    /// </summary>
    public string LogicOperator { get; set; } = "AND";

    /// <summary>
    /// 规则执行顺序
    /// </summary>
    public int RuleOrder { get; set; }

    /// <summary>
    /// 规则说明
    /// </summary>
    public string? Description { get; set; }
}

/// <summary>
/// 勋章规则输出
/// </summary>
public class MedalRuleOutput
{
    /// <summary>
    /// 规则ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 关联的勋章ID
    /// </summary>
    public long MedalId { get; set; }

    /// <summary>
    /// 目标表名
    /// </summary>
    public string TargetTable { get; set; } = string.Empty;

    /// <summary>
    /// 目标字段名
    /// </summary>
    public string TargetField { get; set; } = string.Empty;

    /// <summary>
    /// 比较运算符
    /// </summary>
    public string Operator { get; set; } = string.Empty;

    /// <summary>
    /// 阈值数量
    /// </summary>
    public int ThresholdValue { get; set; }

    /// <summary>
    /// 额外筛选条件
    /// </summary>
    public string? FilterCondition { get; set; }

    /// <summary>
    /// 时间范围类型
    /// </summary>
    public string? DateRangeType { get; set; }

    /// <summary>
    /// 自定义起始时间
    /// </summary>
    public DateTime? DateRangeStart { get; set; }

    /// <summary>
    /// 自定义结束时间
    /// </summary>
    public DateTime? DateRangeEnd { get; set; }

    /// <summary>
    /// 多规则间的逻辑关系
    /// </summary>
    public string LogicOperator { get; set; } = string.Empty;

    /// <summary>
    /// 规则执行顺序
    /// </summary>
    public int RuleOrder { get; set; }

    /// <summary>
    /// 规则说明
    /// </summary>
    public string? Description { get; set; }

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

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdatedAt { get; set; }
}

/// <summary>
/// 微信端勋章列表输出（含拥有状态）
/// </summary>
public class WxMedalListOutput
{
    /// <summary>
    /// 勋章ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 勋章名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 获得条件描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 图片地址
    /// </summary>
    public string? ImageUrl { get; set; }

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

    /// <summary>
    /// 勋章的类型
    /// </summary>
    public string Type { get; set; } = string.Empty;

    /// <summary>
    /// 是否已拥有
    /// </summary>
    public bool IsOwned { get; set; }

    /// <summary>
    /// 获得时间（未拥有则为null）
    /// </summary>
    public DateTime? AwardedAt { get; set; }
}

/// <summary>
/// 微信端用户已拥有勋章输出
/// </summary>
public class WxUserMedalOutput
{
    /// <summary>
    /// 勋章ID
    /// </summary>
    public long MedalId { get; set; }

    /// <summary>
    /// 勋章名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 获得条件描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 图片地址
    /// </summary>
    public string? ImageUrl { get; set; }

    /// <summary>
    /// 勋章的类型
    /// </summary>
    public string Type { get; set; } = string.Empty;

    /// <summary>
    /// 获得时间
    /// </summary>
    public DateTime? AwardedAt { get; set; }

    /// <summary>
    /// 状态: Awarded, Revoked
    /// </summary>
    public string Status { get; set; } = string.Empty;
}

/// <summary>
/// 微信端激活勋章输入
/// </summary>
public class WxMedalActivateInput
{
    /// <summary>
    /// 勋章ID
    /// </summary>
    public long MedalId { get; set; }
}

/// <summary>
/// 勋章规则目标表下拉输出
/// </summary>
public class MedalRuleTableOptionOutput
{
    /// <summary>
    /// 表名
    /// </summary>
    public string TableName { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称
    /// </summary>
    public string DisplayName { get; set; } = string.Empty;
}

/// <summary>
/// 勋章规则字段下拉输出
/// </summary>
public class MedalRuleFieldOptionOutput
{
    /// <summary>
    /// 字段名
    /// </summary>
    public string FieldName { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称
    /// </summary>
    public string DisplayName { get; set; } = string.Empty;
}
