using System.Text.Json; namespace GB5Shared.ActionProcessor { /// /// Message payload published to and consumed from RabbitMQ action-exec-p{n} queues. /// ActionRunId maps to TEVENTACTIONRUN.ACTIONRUNID (app-generated INT). /// ActionType: 0=Email, 1=SMS, 2=Webhook, 3=Notification, 4=Report /// public class ActionEventDto { public int ActionRunId { get; set; } public int ActionId { get; set; } public int ActionType { get; set; } public int TenantId { get; set; } /// /// The tenant's real, physical database name (MSERVERCONFIG.DATABASENAME) — for /// display/logging/business-context purposes only. NOT usable for DB connection /// resolution — looks up connection strings by /// CONNECTIONNAME, not DATABASENAME. Use for that. /// public string DatabaseName { get; set; } = string.Empty; /// /// MSERVERCONFIG.CONNECTIONNAME — an arbitrary per-tenant alias (can differ from /// DatabaseName) that GB5Shared.Connection.ApplicationConnection actually keys its /// connection-string lookup on. Required for any fresh LoginDTO this action's /// handler needs to build for its own DB access (e.g. IWebhookEndpointResolver). /// public string ConnectionName { get; set; } = string.Empty; /// /// TJOBEXECUTION.JOBEXECUTIONID this action belongs to. 0 when the action was not /// generated from a scheduler run (e.g. workflow/event-driven actions) — consumers /// must skip TJOBEXECUTION finalization when this is <= 0. /// public int JobExecutionId { get; set; } // ── Email / SMS ────────────────────────────────────────────── public string? SendTo { get; set; } /// 3=direct email, 2=field name in payload, 1=mail list, 12=EnrichQualifier (SENDTO = QueryCode) public int ToDeliveryType { get; set; } /// 0=Direct, 1=Employee, 2=Party, 3=User, 4=Contact, 5=UserGroup, 6=Role. Used when DeliveryType=2. public int ToContentType { get; set; } public int TemplateId { get; set; } public string? MailCc { get; set; } /// 3=direct email, 2=field name in payload, 1=mail list, 12=EnrichQualifier public int MailCcDeliveryType { get; set; } public string? MailBcc { get; set; } /// 3=direct email, 2=field name in payload, 1=mail list, 12=EnrichQualifier public int MailBccDeliveryType { get; set; } public string? ReplyTo { get; set; } // ── Webhook ────────────────────────────────────────────────── public int WebServiceId { get; set; } public string? UriParameterValue { get; set; } // ── Report ─────────────────────────────────────────────────── public int ReportId { get; set; } // ── Attachment (generic — used by Email today; benefits any future action type) ── /// /// Optional TATTACHMENT.ATTACHMENTID to attach to the outbound message. Added for /// Correspondence (Phase 2 — CorrespondenceActionHandler sets this to /// TCORRESPONDENCE.GENERATEDATTACHMENTID) but deliberately generic: any ActionType / /// MACTION-configured action can populate it and EmailActionHandler will attach it, /// platform-wide, not just for Correspondence sends. /// public int? AttachmentId { get; set; } // ── Tracing ────────────────────────────────────────────────── public string CorrelationKey { get; set; } = string.Empty; /// /// W3C traceparent of the span active when this DTO was built (e.g. EventSubBLL's /// Dapr-subscribe span, or SchedulerActionGeneratorBLL's caller). Carried in the /// message body itself — same pattern as OutboxEventMessage.TraceParent — so /// ActionProcessorWorker.OnActionExecAsync can reconstruct the parent /// ActivityContext and keep the whole dispatch chain (Quartz fire -> ... -> Dapr /// publish/subscribe -> TACTIONOUTBOX -> RabbitMQ -> this handler -> actual send) /// under one trace, regardless of Dapr/RabbitMQ broker metadata propagation. /// public string? TraceParent { get; set; } /// W3C tracestate accompanying , if any. public string? TraceState { get; set; } // ── Enriched handler input ─────────────────────────────────── public JsonElement Payload { get; set; } // ── Workflow approval buttons (email action links) ──────────── /// When true, the email handler renders Approve/Reject/Return links using WorkflowTaskId and ApprovalBaseUrl. public bool IncludeApprovalActions { get; set; } /// TWORKFLOWTASK.WORKFLOWTASKID — embedded in the signed token for email-link approval. public int WorkflowTaskId { get; set; } /// Base URL of the framework service (e.g. https://api.example.com) used to construct /Action/Execute links. public string? ApprovalBaseUrl { get; set; } // ── Generalized direct action buttons ──────────────────────── /// FK to MDIRECTACTION header. -1 = no action buttons (one-way notification). public int DirectActionId { get; set; } = -1; /// Context PK extracted from the entity payload via MDIRECTACTION.CONTEXTIDFIELD (e.g. WorkflowTaskId). public int ContextId { get; set; } /// Assignee user ID extracted from the entity payload via MDIRECTACTION.ASSIGNEEUSERIDFIELD. public int AssigneeUserId { get; set; } = -1; /// /// Pipeline context JSON forwarded from . /// Contains EntityId, ObjectId, EventTypeId, caller Facts, and every DB_ENRICH bag value /// written by qualifier rules (e.g. MailId, ReportingToEmployeeId, DepartmentId, WorkflowInfo). /// /// Handlers use this to resolve configured field names (e.g. MACTION.SENDTO = "MailId") /// against the enriched bag when the field is absent from the entity DTO payload. /// /// Null/empty when the event arrived via the outbox background-retry path. /// public string? ContextJson { get; set; } } }