namespace IamService.Domain.Exceptions;

/// <summary>
/// EN: Base exception for domain errors.
/// VI: Exception cơ sở cho các lỗi domain.
/// </summary>
public class DomainException : Exception
{
    public DomainException()
    {
    }

    public DomainException(string message) : base(message)
    {
    }

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

/// <summary>
/// EN: Exception thrown when a resource already exists.
/// VI: Exception được throw khi resource đã tồn tại.
/// </summary>
public class DuplicateResourceException : DomainException
{
    public string ResourceType { get; }
    public string? Identifier { get; }

    public DuplicateResourceException(string resourceType, string? identifier = null)
        : base($"{resourceType}{(identifier != null ? $" with identifier '{identifier}'" : "")} already exists")
    {
        ResourceType = resourceType;
        Identifier = identifier;
    }
}

/// <summary>
/// EN: Exception thrown when an entity is not found.
/// VI: Exception được throw khi entity không được tìm thấy.
/// </summary>
public class EntityNotFoundException : DomainException
{
    public string EntityType { get; }
    public string? Identifier { get; }

    public EntityNotFoundException(string entityType, string? identifier = null)
        : base($"{entityType}{(identifier != null ? $" with identifier '{identifier}'" : "")} not found")
    {
        EntityType = entityType;
        Identifier = identifier;
    }
}

/// <summary>
/// EN: Exception thrown when authentication fails.
/// VI: Exception được throw khi authentication thất bại.
/// </summary>
public class AuthenticationFailedException : DomainException
{
    public AuthenticationFailedException(string message = "Authentication failed")
        : base(message)
    {
    }
}

/// <summary>
/// EN: Exception thrown when business rule validation fails.
/// VI: Exception được throw khi validation business rule thất bại.
/// </summary>
public class BusinessRuleException : DomainException
{
    public string RuleName { get; }

    public BusinessRuleException(string ruleName, string message)
        : base(message)
    {
        RuleName = ruleName;
    }
}
