using System; using System.Collections.Generic; using System.Linq; namespace FrameworkDAL.DTO.SchedulerTaskGenerator { // ───────────────────────────────────────────────────────────────── // ActionType constants // Matches MACTION.ACTIONTYPE values // ───────────────────────────────────────────────────────────────── public static class SchedulerActionType { public const int Mail = 0; public const int SMS = 1; public const int ReportMail = 2; public const int Notify = 3; public const int DocMerge = 4; public const int WebService = 5; public const int FileBased = 6; public const int WhatsApp = 7; public const int Teams = 8; public const int Telegram = 9; public const int Slack = 10; public static string GetLabel(int actionType) => actionType switch { Mail => "Mail", SMS => "SMS", ReportMail => "Report Mail", Notify => "Notify", DocMerge => "Doc Merge", WebService => "Web Service", FileBased => "File Based", WhatsApp => "WhatsApp", Teams => "Teams", Telegram => "Telegram", Slack => "Slack", _ => $"Type{actionType}" }; } // ───────────────────────────────────────────────────────────────── // ExecutionStatus constants // Matches TJOBEXECUTION.STATUS values — a varchar(20) string enum // (2026-08-20), mirroring TJOBQUEUE's own STATUS convention // (PENDING/PROCESSING/COMPLETED/FAILED/DLQ) so both tables read the // same way instead of needing two different numeric codings memorized. // ───────────────────────────────────────────────────────────────── public static class SchedulerExecutionStatus { public const string Pending = "PENDING"; public const string InProgress = "PROCESSING"; public const string Success = "COMPLETED"; public const string Failed = "FAILED"; public const string DLQ = "DLQ"; public static string GetLabel(string? status) => status switch { Pending => "Pending", InProgress => "Running", Success => "Success", Failed => "Failed", DLQ => "DLQ", _ => "Not Started" }; } // ───────────────────────────────────────────────────────────────── // SchedulerMonitorDTO // One row per job — flat result from LoadSchedulerMonitor query. // ───────────────────────────────────────────────────────────────── public sealed class SchedulerMonitorDTO { // Job identity public int JobId { get; set; } public string JobName { get; set; } = string.Empty; public int TenantId { get; set; } public int JobStatus { get; set; } // Scheduler config public string? SchedulerName { get; set; } public string? CronExpression { get; set; } public string? OccursAtTime { get; set; } public int EveryNoOfHours { get; set; } public int EveryNoOfMinutes { get; set; } // Latest execution public int? JobExecutionId { get; set; } public string? ExecutionStatus { get; set; } public DateTime? NextRunOn { get; set; } public DateTime? LastRunOn { get; set; } public DateTime? FireRunOn { get; set; } public DateTime? EndRunOn { get; set; } public int? DurationMs { get; set; } public int RetryCount { get; set; } public string? LastError { get; set; } public string? LastSuccess { get; set; } // Actions /// Comma-separated ActionType ints e.g. "0,3,5" — from STRING_AGG in SQL public string? ActionTypes { get; set; } public int ActionCount { get; set; } // ── Computed display helpers ────────────────────────────────── /// Human-readable execution status label. public string ExecutionStatusLabel => SchedulerExecutionStatus.GetLabel(ExecutionStatus); /// Human-readable action type names from ActionTypes CSV. public IReadOnlyList ActionTypeLabels => string.IsNullOrWhiteSpace(ActionTypes) ? Array.Empty() : ActionTypes .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(a => int.TryParse(a.Trim(), out var n) ? SchedulerActionType.GetLabel(n) : a) .ToList(); } // ───────────────────────────────────────────────────────────────── // SchedulerMonitorSummaryDTO // Counts by status — shown as stats bar in the monitor UI. // ───────────────────────────────────────────────────────────────── public sealed class SchedulerMonitorSummaryDTO { public int Total { get; set; } public int Pending { get; set; } public int Running { get; set; } public int Success { get; set; } public int Failed { get; set; } public int DLQ { get; set; } public int NotStarted { get; set; } } // ───────────────────────────────────────────────────────────────── // SchedulerMonitorResponseDTO // Full monitor response — summary counts + job list. // ───────────────────────────────────────────────────────────────── public sealed class SchedulerMonitorResponseDTO { public SchedulerMonitorSummaryDTO Summary { get; set; } = new(); public IReadOnlyList Jobs { get; set; } = Array.Empty(); } }