using System;
using System.ComponentModel.DataAnnotations;
using FreeSql.DataAnnotations;
using ZhonTai.Admin.Core.Entities;
using NPP.SmartSchedue.Api.Contracts.Core.Consts;
using NPP.SmartSchedue.Api.Contracts.Core.Enums;
namespace NPP.SmartSchedue.Api.Contracts.Domain.Notification;
///
/// 通知任务实体
/// 决策点6:定时任务,支持定时检查和触发通知
/// 决策点5:不支持多租户,继承EntityBase
///
[Table(Name = DbConsts.TableNamePrefix + "notification_task")]
public partial class NotificationTaskEntity : EntityBase
{
#region 关联信息
///
/// 通知设置ID
///
[Required(ErrorMessage = "通知设置ID不能为空")]
public long NotificationSettingId { get; set; }
#endregion
#region 任务信息
///
/// 任务名称
///
[Column(StringLength = 200)]
[Required(ErrorMessage = "任务名称不能为空")]
public string TaskName { get; set; } = "";
///
/// 任务状态
///
public int TaskStatus { get; set; } = (int)NotificationStatusEnum.Pending;
///
/// 是否启用
///
public bool IsEnabled { get; set; } = true;
#endregion
#region 执行时间配置
///
/// 计划执行时间
///
public DateTime PlannedExecutionTime { get; set; }
///
/// 下次执行时间
///
public DateTime? NextExecutionTime { get; set; }
///
/// 最后执行时间
///
public DateTime? LastExecutionTime { get; set; }
///
/// 执行次数
///
public int ExecutionCount { get; set; } = 0;
///
/// 最大执行次数(0表示无限制)
///
public int MaxExecutionCount { get; set; } = 0;
#endregion
#region 执行结果
///
/// 最后执行结果
///
[Column(StringLength = 1000)]
public string LastExecutionResult { get; set; } = "";
///
/// 最后执行错误信息
///
[Column(StringLength = 1000)]
public string LastExecutionError { get; set; } = "";
///
/// 成功执行次数
///
public int SuccessExecutionCount { get; set; } = 0;
///
/// 失败执行次数
///
public int FailedExecutionCount { get; set; } = 0;
#endregion
#region 业务上下文
///
/// 业务类型(如:工作任务提醒、设备维护提醒等)
///
[Column(StringLength = 100)]
public string BusinessType { get; set; } = "";
///
/// 业务ID
///
public long? BusinessId { get; set; }
///
/// 业务数据(JSON格式存储)
///
[Column(DbType = "text")]
public string BusinessData { get; set; } = "";
#endregion
#region Cron表达式支持
///
/// Cron表达式(用于复杂的定时规则)
///
[Column(StringLength = 100)]
public string CronExpression { get; set; } = "";
#endregion
#region 导航属性
///
/// 通知设置实体
///
[Navigate("NotificationSettingId")]
public NotificationSettingEntity? NotificationSetting { get; set; }
#endregion
}