namespace MktZaloService.Domain.Exceptions;

/// <summary>
/// EN: Base exception for Zalo domain-specific errors.
/// VI: Exception cơ sở cho các lỗi cụ thể của domain Zalo.
/// </summary>
public class ZaloDomainException : DomainException
{
    public ZaloDomainException(string message) : base(message)
    {
    }

    public ZaloDomainException(string message, Exception innerException)
        : base(message, innerException)
    {
    }
}

/// <summary>
/// EN: Exception thrown when conversation is in invalid state.
/// VI: Exception khi cuộc hội thoại ở trạng thái không hợp lệ.
/// </summary>
public class ConversationClosedException : ZaloDomainException
{
    public Guid ConversationId { get; }

    public ConversationClosedException(Guid conversationId)
        : base($"Cannot perform operation on closed conversation: {conversationId}")
    {
        ConversationId = conversationId;
    }
}

/// <summary>
/// EN: Exception thrown when a required customer is not found.
/// VI: Exception khi không tìm thấy khách hàng cần thiết.
/// </summary>
public class CustomerNotFoundException : ZaloDomainException
{
    public string ZaloUserId { get; }

    public CustomerNotFoundException(string zaloUserId)
        : base($"Customer not found with Zalo user ID: {zaloUserId}")
    {
        ZaloUserId = zaloUserId;
    }
}

/// <summary>
/// EN: Exception thrown when chatbot rule has invalid configuration.
/// VI: Exception khi quy tắc chatbot có cấu hình không hợp lệ.
/// </summary>
public class InvalidRuleConfigurationException : ZaloDomainException
{
    public Guid RuleId { get; }

    public InvalidRuleConfigurationException(Guid ruleId, string reason)
        : base($"Invalid rule configuration for rule {ruleId}: {reason}")
    {
        RuleId = ruleId;
    }
}

/// <summary>
/// EN: Exception thrown when ZNS template parameters are missing.
/// VI: Exception khi thiếu tham số mẫu ZNS.
/// </summary>
public class MissingTemplateParametersException : ZaloDomainException
{
    public IReadOnlyList<string> MissingParameters { get; }

    public MissingTemplateParametersException(IEnumerable<string> missingParameters)
        : base($"Missing required template parameters: {string.Join(", ", missingParameters)}")
    {
        MissingParameters = missingParameters.ToList().AsReadOnly();
    }
}
