using QYZH.InteractiveMagazine.Models.Enum;

namespace QYZH.InteractiveMagazine.Models.Dto.Compensation;

/// <summary>
/// 创建补偿任务输入
/// </summary>
public class CreateCompensationTaskInput
{
    /// <summary>
    /// 任务类型（使用 CompensationTaskTypeEnum 枚举）
    /// </summary>
    public CompensationTaskTypeEnum TaskType { get; set; }

    /// <summary>
    /// 业务来源（如 CheckIn、Purchase）
    /// </summary>
    public string BusinessSource { get; set; } = string.Empty;

    /// <summary>
    /// 关联业务记录Id
    /// </summary>
    public string? BusinessId { get; set; }

    /// <summary>
    /// 关联用户Id
    /// </summary>
    public long UserId { get; set; }

    /// <summary>
    /// 处理参数（匿名对象或字典，会自动序列化为JSON）
    /// </summary>
    public object Payload { get; set; } = new { };

    /// <summary>
    /// 异常消息
    /// </summary>
    public string ErrorMessage { get; set; } = string.Empty;

    /// <summary>
    /// 异常来源（类名.方法名，如 CheckInService.CheckInAsync）
    /// </summary>
    public string ErrorSource { get; set; } = string.Empty;

    /// <summary>
    /// 最大重试次数（默认3次）
    /// </summary>
    public int MaxRetries { get; set; } = 3;
}

/// <summary>
/// 补偿任务输出
/// </summary>
public class CompensationTaskOutput
{
    public long Id { get; set; }
    public CompensationTaskTypeEnum TaskType { get; set; }
    public string BusinessSource { get; set; } = string.Empty;
    public string? BusinessId { get; set; }
    public long UserId { get; set; }
    public string Payload { get; set; } = string.Empty;
    public string ErrorMessage { get; set; } = string.Empty;
    public string ErrorSource { get; set; } = string.Empty;
    public int RetryCount { get; set; }
    public int MaxRetries { get; set; }
    public CompensationTaskStatusEnum Status { get; set; }
    public DateTime? ProcessedAt { get; set; }
    public DateTime? ScheduledAt { get; set; }
    public string? ResultMessage { get; set; }
    public DateTime CreatedAt { get; set; }
}

/// <summary>
/// 查询补偿任务输入（供外部项目按条件拉取）
/// </summary>
public class GetCompensationTasksInput
{
    /// <summary>
    /// 按用户Id筛选
    /// </summary>
    public long? UserId { get; set; }

    /// <summary>
    /// 按状态筛选
    /// </summary>
    public CompensationTaskStatusEnum? Status { get; set; }

    /// <summary>
    /// 按任务类型筛选
    /// </summary>
    public CompensationTaskTypeEnum? TaskType { get; set; }

    /// <summary>
    /// 按业务来源筛选
    /// </summary>
    public string? BusinessSource { get; set; }

    /// <summary>
    /// 获取数量上限（默认50）
    /// </summary>
    public int Limit { get; set; } = 50;
}

/// <summary>
/// 更新补偿任务状态输入（供外部处理项目回调）
/// </summary>
public class UpdateCompensationStatusInput
{
    /// <summary>
    /// 目标状态（使用 CompensationTaskStatusEnum 枚举）
    /// </summary>
    public CompensationTaskStatusEnum Status { get; set; }

    /// <summary>
    /// 处理结果描述
    /// </summary>
    public string? ResultMessage { get; set; }

    /// <summary>
    /// 更新重试次数（可选）
    /// </summary>
    public int? RetryCount { get; set; }

    /// <summary>
    /// 下次计划执行时间（用于退避重试，可选）
    /// </summary>
    public DateTime? ScheduledAt { get; set; }
}
