using System.Collections.Generic;
using GitConverter.Lib.Converters;
namespace GitConverter.Lib.Factories
{
///
/// Produces instances for a given conversion option string.
///
///
///
/// The IConverterFactory interface abstracts the creation of converter instances based
/// on human-friendly format option strings (for example, "Shapefile", "GeoJson", "Csv").
/// Implementations map canonical display keys to concrete factories
/// and provide both throwing and non-throwing creation patterns to suit different callers.
///
///
/// Design guidance
/// - Use for CLI flows, interactive tooling and tests
/// where callers prefer to handle unsupported options without exceptions.
/// - Use when the caller expects a converter and prefers an exception
/// to be thrown for unsupported options (the implementation may include friendly suggestions
/// in the thrown message).
///
///
/// Thread-safety and lifetime
/// - Factory implementations are typically constructed once (during application startup) and used
/// as a read-only registry thereafter. Implementations should document whether they are safe for
/// concurrent use; recommended implementations avoid mutable shared state and are safe for
/// concurrent Create/TryCreate calls.
///
///
/// Error handling
/// - must return false when the requested option
/// cannot be resolved. Implementations may log diagnostic context but should not throw from this
/// method for unsupported options. If a factory delegate throws during instantiation it is recommended
/// that the implementation catch the exception, log it, set the out parameter to null and return false.
/// - may throw when the option is unsupported.
/// Implementations may include a helpful suggestion in the exception message (for example: "Did you mean 'GeoJson'?").
///
///
/// Testing guidance
/// - For unit tests prefer providing a test-specific factory implementation or a factory constructed
/// with a small registrations map to avoid instantiating heavy dependencies. Assert behavior of both
/// and as appropriate.
///
///
/// Example
///
/// IConverterFactory factory = new ConverterFactory();
/// if (factory.TryCreate("Shapefile", out var converter))
/// {
/// var result = converter.Convert(...);
/// }
/// else
/// {
/// Console.WriteLine("Unsupported converter option. Supported: " + string.Join(", ", factory.GetSupportedOptions()));
/// }
///
///
public interface IConverterFactory
{
///
/// Create a converter for the given option or throw if unsupported.
///
/// User-provided option (case/format tolerant).
/// An instance of configured for the requested option.
///
/// Implementations should validate and throw a
/// when the option is unsupported. Exception messages
/// may include friendly suggestions to improve CLI UX. Use this method when the caller
/// prefers an exception for control flow rather than handling a boolean result.
///
IConverter Create(string formatOption);
///
/// Try to create a converter for the given option. Returns false if unsupported.
///
/// User-provided option string.
/// When true returned, the resolved converter instance; otherwise, null.
/// True when a converter was created; false otherwise.
///
/// This non-throwing alternative is suitable for CLI parsing and tests where callers want
/// to present usage information or suggestions rather than handle exceptions. Implementations
/// should catch instantiation exceptions from underlying factory delegates, log diagnostic
/// details and return false.
///
bool TryCreate(string formatOption, out IConverter converter);
///
/// Returns the supported option keys (human-friendly).
///
/// An ordered, read-only collection of display keys suitable for help text.
///
/// The returned collection is intended for presentation to users (for example, help/usage
/// messages) and should contain stable, human-friendly display keys rather than internal
/// normalized keys.
///
IReadOnlyCollection GetSupportedOptions();
}
}