/// Custom exception class to handle various format-related errors.
class TFormatException implements Exception {
  /// The associated error message.
  final String message;

  /// Default constructor with a generic error message.
  const TFormatException([
    this.message =
        'An unexpected format error occurred. Please check your input.',
  ]);

  /// Create a format exception from a specific error message.
  factory TFormatException.fromMessage(String message) {
    return TFormatException(message);
  }

  /// Get the corresponding error message.
  String get formattedMessage => message;

  /// Create a format exception from a specific error code.
  factory TFormatException.fromCode(String code) {
    switch (code) {
      // Email and authentication formats
      case 'invalid-email-format':
        return const TFormatException(
          'The email address format is invalid. Please enter a valid email.',
        );
      case 'invalid-phone-number-format':
        return const TFormatException(
          'The provided phone number format is invalid. Please enter a valid number.',
        );

      // General data formats
      case 'invalid-date-format':
        return const TFormatException(
          'The date format is invalid. Please enter a valid date.',
        );
      case 'invalid-url-format':
        return const TFormatException(
          'The URL format is invalid. Please enter a valid URL.',
        );
      case 'invalid-credit-card-format':
        return const TFormatException(
          'The credit card format is invalid. Please enter a valid credit card number.',
        );
      case 'invalid-numeric-format':
        return const TFormatException(
          'The input should be a valid numeric format.',
        );

      // JSON and data structure formats
      case 'invalid-json-format':
        return const TFormatException(
          'Invalid JSON format. Please check your data structure.',
        );
      case 'invalid-payload-format':
        return const TFormatException(
          'Invalid data payload format. Please check your submission.',
        );

      // Supabase specific format errors
      case 'invalid-rpc-params':
        return const TFormatException(
          'Invalid parameters for database function call.',
        );
      case 'invalid-query-format':
        return const TFormatException(
          'Invalid query format. Please check your filter criteria.',
        );
      case 'malformed-request':
        return const TFormatException(
          'The request format is invalid. Please try again.',
        );
      case 'invalid-storage-path':
        return const TFormatException('The storage path format is invalid.');

      default:
        return const TFormatException();
    }
  }
}
