using System; using System.Collections.Generic; using System.Linq; namespace FrameworkDAL.DTO.EIPConversation { /// /// Unified Conversation DTO /// Contains: /// - DB conversation data /// - Flow configuration (Steps + Triggers) /// - Runtime execution context /// public class MessageHubConversationDTO { // ================================ // PRIMARY // ================================ public long MessageHubConversationId { get; set; } public int ClientId { get; set; } public int StatusId { get; set; } // ================================ // PLATFORM INFO // ================================ public int PlatformTypeId { get; set; } public string SessionId { get; set; } = string.Empty; // ================================ // MESSAGE SNAPSHOT // ================================ public string UserMessage { get; set; } = string.Empty; public string? ResponseMessage { get; set; } public string Recipient { get; set; } = string.Empty; public string MessageText { get; set; } = string.Empty; // ================================ // FLOW RUNTIME // ================================ public int CurrentStepId { get; set; } public bool IsCompleted { get; set; } // ================================ // STATUS // ================================ public int Status { get; set; } = 1; public bool IsActive { get; set; } = true; // ================================ // AUDIT // ================================ public int? CreatedById { get; set; } public int? ModifiedById { get; set; } public int? Version { get; set; } public DateTime CreatedOn { get; set; } = DateTime.UtcNow; public DateTime ModifiedOn { get; set; } = DateTime.UtcNow; public DateTime LastActivityOn { get; set; } = DateTime.UtcNow; public DateTime? ClosedOn { get; set; } // ================================ // FLOW CONFIGURATION // ================================ public string? DefaultFallbackMessage { get; set; } public List Steps { get; set; } = new(); public List Triggers { get; set; } = new(); // ================================ // RUNTIME CONTEXT // ================================ public Dictionary Context { get; set; } = new(); // ================================ // SAFE CONTEXT HELPERS // ================================ public T? GetContextValue(string key) { if (Context.TryGetValue(key, out var value)) { if (value is T tValue) return tValue; try { return (T)Convert.ChangeType(value, typeof(T)); } catch { return default; } } return default; } public void SetContextValue(string key, object value) { Context[key] = value; } // ================================ // DEBUG HELPER // ================================ public string Summary => $"{SessionId} | Step={CurrentStepId} | Active={IsActive} | Recipient={Recipient}"; } // ============================================================ // FLOW STEP // ============================================================ public class ConversationFlowStepDTO { public int StepId { get; set; } public string Type { get; set; } = string.Empty; public string? Message { get; set; } public string? Response { get; set; } public int? DelayMilliseconds { get; set; } public string? ActionType { get; set; } public string? ActionName { get; set; } public string? ConditionKey { get; set; } public string? ConditionValue { get; set; } public bool? AutoAdvance { get; set; } public int? DefaultNextStepId { get; set; } public int? TrueStepId { get; set; } public int? FalseStepId { get; set; } public string? ContextKey { get; set; } public ValidationConfigDTO? Validation { get; set; } public ApiConfigDTO? ApiConfig { get; set; } public Dictionary Choices { get; set; } = new(); public Dictionary DecisionMap { get; set; } = new(); public string? ServiceUrl { get; set; } public string? Method { get; set; } public string? Body { get; set; } public Dictionary? Headers { get; set; } public string? ContextKeyToSave { get; set; } public string? Platform { get; set; } public int? NextStepId { get; set; } // Conditional public List? Conditions { get; set; } // Loop public int? MaxIterations { get; set; } public int? LoopBackStepId { get; set; } public int? ExitStepId { get; set; } // Advanced public Func, int>? ConditionalNextStep { get; set; } public Func, bool>? LoopCondition { get; set; } public List? Buttons { get; set; } } // ============================================================ // TRIGGER // ============================================================ public class ConversationTriggerDTO { public List Keywords { get; set; } = new(); public int StartStepId { get; set; } } // ============================================================ // VALIDATION // ============================================================ public class ValidationConfigDTO { public bool Required { get; set; } public int? MinLength { get; set; } public int? MaxLength { get; set; } public string? Regex { get; set; } public string ErrorMessage { get; set; } = "Invalid input."; } // ============================================================ // API CONFIG // ============================================================ public class ApiConfigDTO { public string? Method { get; set; } = "GET"; public string? Url { get; set; } public Dictionary? Headers { get; set; } public string? BodyTemplate { get; set; } } // ============================================================ // RESPONSE // ============================================================ public class ConversationResponseDTO { public string Text { get; set; } = string.Empty; public List? Buttons { get; set; } } public class ConversationButtonDTO { public string Id { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; } // ============================================================ // CONDITIONAL // ============================================================ public class ConditionDTO { public string? ContextKey { get; set; } public string? Operator { get; set; } // e.g., "IN", "==", "!=" public List? Value { get; set; } // Changed from string? to List to support arrays public bool Default { get; set; } = false; // Optional default fallback public int NextStepId { get; set; } } // ============================================================ // ENUMS // ============================================================ public enum ConversationReplyType { Text = 0, Interactive = 1 } public enum MessageHubPlatformType { PostMan = 0, WhatsApp = 1, Teams = 2, Telegram = 3, Slack = 4, SMS = 5 } public enum OtpPlatform { SMS, EMAIL, WHATSAPP, TEAMS, TELEGRAM, SLACK } public class FlowDefinition { public List Steps { get; set; } = new(); } public class FlowStep { public string StepId { get; set; } public string StepType { get; set; } public string NextStepId { get; set; } public string CapabilityCode { get; set; } public string MessageTemplateKey { get; set; } } }