using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace CredentialManager.Models; /// /// Modello per lo storico delle esecuzioni delle schedulazioni /// public class ScheduleExecutionHistory { [Key] public int Id { get; set; } // Relazione con la schedulazione [Required] public int ScheduleId { get; set; } [ForeignKey(nameof(ScheduleId))] public virtual ProfileSchedule Schedule { get; set; } = null!; // Relazione con il profilo (denormalizzato per storico) [Required] public int ProfileId { get; set; } [Required] [MaxLength(200)] public string ProfileName { get; set; } = string.Empty; // Informazioni dell'esecuzione [Required] public DateTime StartTime { get; set; } public DateTime? EndTime { get; set; } public TimeSpan? Duration => EndTime - StartTime; [Required] [MaxLength(20)] public string Status { get; set; } = string.Empty; // "success", "failed", "running", "cancelled" [MaxLength(2000)] public string? Message { get; set; } public int RecordsProcessed { get; set; } = 0; public int? RecordsWithErrors { get; set; } // Dettagli dell'errore se presente [MaxLength(5000)] public string? ErrorDetails { get; set; } // Informazioni sul trigger [Required] [MaxLength(20)] public string TriggerType { get; set; } = string.Empty; // "manual", "automatic" [MaxLength(100)] public string? TriggeredBy { get; set; } // Configurazioni al momento dell'esecuzione (per storico) [MaxLength(50)] public string? SourceType { get; set; } [MaxLength(50)] public string? DestinationType { get; set; } [MaxLength(500)] public string? SourceInfo { get; set; } // Informazioni aggiuntive sulla sorgente utilizzata [MaxLength(500)] public string? DestinationInfo { get; set; } // Informazioni aggiuntive sulla destinazione utilizzata // Metadati public DateTime CreatedAt { get; set; } = DateTime.UtcNow; [MaxLength(2000)] public string? AdditionalInfo { get; set; } // JSON per informazioni aggiuntive // Helper methods public bool IsCompleted => Status == "success" || Status == "failed" || Status == "cancelled"; public bool IsSuccessful => Status == "success"; public string GetStatusDisplayText() => Status switch { "success" => "Completato con successo", "failed" => "Fallito", "running" => "In esecuzione", "cancelled" => "Cancellato", _ => "Sconosciuto" }; public string GetStatusColorClass() => Status switch { "success" => "text-success", "failed" => "text-danger", "running" => "text-primary", "cancelled" => "text-warning", _ => "text-muted" }; }