// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:wyatt_architecture/wyatt_architecture.dart';
import 'package:wyatt_i18n/src/core/enums/format.dart';

/// Exception thrown when the i18n file is not found.
///
/// Source can be a file path or a URL.
class SourceNotFoundException extends ClientException {
  SourceNotFoundException(String source, {required Format format})
      : super('Source `$source` (format: $format) not found.');
}

/// Exception thrown when the i18n file is not valid.
class NoLocaleException extends ClientException {
  NoLocaleException()
      : super('No `@@locale` key found in the source nor locale provided.');
}

/// Exception thrown when the i18n locale is not valid.
class InvalidLocaleException extends ClientException {
  InvalidLocaleException(String locale, String expected)
      : super('Invalid locale `$locale`. Expected `$expected`.');
}

/// Exception thrown when the key is not found in the i18n file.
class KeyNotFoundException extends ClientException {
  KeyNotFoundException(String key, [Map<String, dynamic> arguments = const {}])
      : super(
          'Key `$key` not found. ${arguments.isNotEmpty ? '($arguments)' : ''}',
        );
}

/// Exception thrown when the searched key requires arguments but none were
/// provided.
class ArgumentsRequiredException extends ClientException {
  ArgumentsRequiredException(String key, String value)
      : super('Key `$key` requires arguments. ($value)');
}

/// Exception thrown when the key references a malformed value.
class MalformedValueException extends ClientException {
  MalformedValueException(String key, String value)
      : super('Key `$key` references a malformed value. ($value)');
}

/// Exception thrown when the parser fails.
class ParserException extends ClientException {
  ParserException(String message, StackTrace? stackTrace)
      : super('$message\n\n$stackTrace');
}

/// Exception thrown when the i18n is not loaded.
class NotLoadedException extends ClientException {
  NotLoadedException() : super('I18n not loaded.');
}
