using System;
using System.Collections.Generic;
namespace FrameworkDAL.DTO.SchedulerTaskGenerator
{
public class SchedulerTaskDTO
{
// =====================================================
// 🔑 Core Identification
// =====================================================
public int JobId { get; set; }
public string JobCode { get; set; } = string.Empty;
public string JobName { get; set; } = string.Empty;
public int SchedulerId { get; set; }
// =====================================================
// 🌐 Execution / Service Info
// =====================================================
public int WebServiceId { get; set; }
public string WebServiceName { get; set; } = string.Empty;
public string EndpointUrl { get; set; } = string.Empty;
public string HttpMethod { get; set; } = "POST";
///
/// MJOBDEFINE.URIPARAMETERVALUE — substituted into EndpointUrl's remaining
/// {placeholder} token(s) by IWebhookEndpointResolver (after {BaseURI} is resolved).
///
public string? UriParameterValue { get; set; }
public int CriteriaConfigId { get; set; }
// =====================================================
// ⏰ Scheduling Core
// =====================================================
public DateTime? LastRunOn { get; set; }
public DateTime? NextRunOn { get; set; }
public string CronExpression { get; set; } = string.Empty;
public string SchedulerName { get; set; } = string.Empty;
public string TimeZoneId { get; set; } = "India Standard Time";
// =====================================================
// 🕒 NON-CRON RULES (THIS FIXES YOUR ERROR)
// =====================================================
///
/// Daily fixed execution time (HH:mm or HH:mm:ss)
/// Example: "10:30"
///
public string OccursAtTime { get; set; } = string.Empty;
///
/// Interval-based scheduling (hours)
///
public int EveryNoOfHours { get; set; }
///
/// Interval-based scheduling (minutes)
///
public int EveryNoOfMinutes { get; set; }
// =====================================================
// 📆 Monthly / Weekly (future-ready)
// =====================================================
public string SelectedDays { get; set; } = string.Empty;
public string SelectedDates { get; set; } = string.Empty;
public short? OccurrenceNo { get; set; }
public short? OccurrenceDay { get; set; }
// =====================================================
// 🏢 Tenant / Org
// =====================================================
public int TenantId { get; set; }
public int OrganizationUnitId { get; set; }
// =====================================================
// 📌 Status
// =====================================================
public int Status { get; set; }
public SchedulerJobStatus JobStatus
{
get => (SchedulerJobStatus)Status;
set => Status = (int)value;
}
// =====================================================
// 📌 Execution Status (from TJOBEXECUTION — separate from job Status)
// =====================================================
///
/// STATUS from TJOBEXECUTION row — a varchar(20) string enum
/// (PENDING/PROCESSING/COMPLETED/FAILED/DLQ, see SchedulerExecutionStatus),
/// matching TJOBQUEUE's own STATUS convention. Populated by LoadJobDetails
/// and ClaimDueExecutions.
///
public string? ExecutionStatus { get; set; }
// =====================================================
// 🔁 Retry / DLQ
// =====================================================
public int RetryCount { get; set; }
public int MaxRetry { get; set; } = 3;
public int RetryDelaySeconds { get; set; } = 60;
// =====================================================
// 🧪 Execution Result
// =====================================================
public string FailureReason { get; set; } = string.Empty;
public long JobExecutionId { get; set; }
// =====================================================
// ⚙️ MJOBDEFINE — execution policy (added with 2026-08-13 schema)
// =====================================================
public int TimeoutSeconds { get; set; } = 300;
public bool IsConcurrent { get; set; }
public string? JobCategory { get; set; }
public string? SourceModule { get; set; }
public int? SourceObjectId { get; set; }
public string? DaprPubSubTopic { get; set; }
// =====================================================
// 🗓️ TSCHEDULER — extended schedule fields (added with 2026-08-13 schema)
// =====================================================
public string? SchedulerType { get; set; }
public int? IntervalSeconds { get; set; }
public DateTime? ScheduledDate { get; set; }
public string? SchedulerDescription { get; set; }
///
/// TSCHEDULER.STATUS — only populated by LoadJobForSync. Distinct from the
/// job-level Status above; QuartzSyncService needs both (job AND scheduler
/// must be active) to decide whether to register or remove a Quartz trigger.
///
public int? SchedulerStatus { get; set; }
// =====================================================
// 🔖 TJOBEXECUTION — dispatch metadata (added with 2026-08-13 schema)
// =====================================================
public string? TriggerType { get; set; }
public string? CorrelationId { get; set; }
public string? HostInstance { get; set; }
///
/// W3C traceparent/tracestate of the "JobScheduler" root span opened when Quartz fired
/// this job (SchedulerJobExecutorQuartzJob). SchedulerExecutionDeliveryService
/// reconstructs this as the parent context for its own span, so the whole pipeline —
/// Quartz fire through the eventual action dispatch — stays under one trace.
///
public string? TraceParent { get; set; }
public string? TraceState { get; set; }
// =====================================================
// 👤 RunAs Context — stored in MJOBDEFINE at scheduling time
// so the executor can build a correct LoginDTO per-job
// instead of using a generic system login (UserId=-1).
// Impersonation prevention: AutoSchedulerBLL always writes
// the *scheduling user's* identity here — never a dropdown value.
// Deactivated-user guard: ClaimDueExecutions skips rows where
// MUSER.STATUS != 1 for RUNASUSEID.
// =====================================================
public int RunAsUserId { get; set; }
public string? RunAsUserName { get; set; }
public int RunAsRoleId { get; set; }
public int RunAsOUId { get; set; }
public int RunAsBranchId { get; set; }
public int RunAsWorkPartyId { get; set; }
public int RunAsStoreId { get; set; }
public int RunAsPeriodId { get; set; }
// =====================================================
// 🔗 Child Actions
// =====================================================
public List Actions { get; set; } = new();
}
public enum SchedulerJobStatus
{
Draft = 0,
Ready = 1,
InProgress = 2,
Success = 3,
Failed = 4,
Disabled = 5,
DeadLettered = 6
}
}