using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using DigitalData.EmailProfiler.Domain.Common; namespace DigitalData.EmailProfiler.Domain.Entities; [Table("TBEMLP_POLL_PROFILES")] public class EmailProfile : BaseEntity, IAggregateRoot { [Key] [Column("GUID", Order = 0)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Column("PROFILE_NAME", TypeName = "varchar(100)")] [Required] [MaxLength(100)] public string ProfileName { get; set; } = string.Empty; [Column("POLL_TYPE", TypeName = "varchar(100)")] [Required] [MaxLength(100)] public string PollType { get; set; } = "IMAP"; [Column("EMAIL_CONF_ID")] [Required] public int EmailAccountId { get; set; } [Column("PROCESS_ID")] public int? ProcessId { get; set; } // Polling Configuration [Column("POLL_INTERVAL")] public int PollIntervalMinutes { get; set; } = 5; [Column("LAST_TICK")] public DateTime? LastPollTime { get; set; } // Validation [Column("VALIDATION_SQL", TypeName = "nvarchar(1024)")] [MaxLength(1024)] public string? ValidationSql { get; set; } // Status [Column("ACTIVE")] public bool IsActive { get; set; } [Column("SEQUENCE")] public int? Sequence { get; set; } [Column("COMMENT", TypeName = "varchar(500)")] [MaxLength(500)] public string? Comment { get; set; } // Audit fields [Column("ADDED_WHO", TypeName = "varchar(50)")] [MaxLength(50)] public string? AddedWho { get; set; } [Column("ADDED_WHEN")] public DateTime? AddedWhen { get; set; } [Column("CHANGED_WHO", TypeName = "varchar(50)")] [MaxLength(50)] public string? ChangedWho { get; set; } [Column("CHANGED_WHEN")] public DateTime? ChangedWhen { get; set; } // Navigation properties [ForeignKey("EmailAccountId")] public virtual EmailAccount? EmailAccount { get; set; } [ForeignKey("ProcessId")] public virtual EmailProcess? EmailProcess { get; set; } public virtual ICollection EmailHistories { get; set; } = new List(); // Domain methods public void UpdateLastPollTime() => LastPollTime = DateTime.Now; public bool ShouldPoll() { if (!IsActive) return false; if (!LastPollTime.HasValue) return true; return DateTime.Now >= LastPollTime.Value.AddMinutes(PollIntervalMinutes); } }