using SqlSugar;
using QYZH.InteractiveMagazine.Models.Enum;

namespace QYZH.InteractiveMagazine.Models.Entity
{
    /// <summary>
    /// 补偿任务表 — 记录业务执行失败后需要异步重试的操作
    /// </summary>
    [SugarTable("CompensationTask")]
    public partial class CompensationTask : SqlSugarBaseEntity
    {
        public CompensationTask() { }

        /// <summary>
        /// Desc:任务类型，决定补偿处理逻辑
        ///      PetFeeding — 宠物喂养补偿
        ///      UserPoints — 用户积分补偿
        ///      UserGrowth — 用户成长值补偿
        ///      SendNotification — 发送通知补偿
        /// Default:
        /// Nullable:False
        /// </summary>
        public int TaskType { get; set; }

        /// <summary>
        /// Desc:业务来源（如 CheckIn、Purchase、Activity）
        /// Default:
        /// Nullable:False
        /// </summary>
        public string BusinessSource { get; set; }

        /// <summary>
        /// Desc:关联业务记录Id（如签到记录Id、订单Id）
        /// Default:
        /// Nullable:True
        /// </summary>
        public string? BusinessId { get; set; }

        /// <summary>
        /// Desc:关联用户Id
        /// Default:
        /// Nullable:False
        /// </summary>
        public long UserId { get; set; }

        /// <summary>
        /// Desc:处理参数（JSON格式，不同TaskType对应不同结构）
        /// Default:
        /// Nullable:False
        /// </summary>
        public string Payload { get; set; }

        /// <summary>
        /// Desc:原始异常消息
        /// Default:
        /// Nullable:False
        /// </summary>
        public string ErrorMessage { get; set; }

        /// <summary>
        /// Desc:异常来源（如 CheckInService.CheckInAsync）
        /// Default:
        /// Nullable:False
        /// </summary>
        public string ErrorSource { get; set; }

        /// <summary>
        /// Desc:已重试次数
        /// Default:0
        /// Nullable:False
        /// </summary>
        public int RetryCount { get; set; }

        /// <summary>
        /// Desc:最大重试次数
        /// Default:3
        /// Nullable:False
        /// </summary>
        public int MaxRetries { get; set; }


        /// <summary>
        /// Desc:最后处理时间
        /// Default:
        /// Nullable:True
        /// </summary>
        public DateTime? ProcessedAt { get; set; }

        /// <summary>
        /// Desc:下次计划执行时间（用于退避重试）
        /// Default:
        /// Nullable:True
        /// </summary>
        public DateTime? ScheduledAt { get; set; }

        /// <summary>
        /// Desc:处理结果描述（成功/失败原因）
        /// Default:
        /// Nullable:True
        /// </summary>
        public string? ResultMessage { get; set; }
    }
}
