using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace GisConverter.Lib.Models { /// /// Canonical set of supported target format option keys used by the library, host and tests. /// /// /// /// Purpose /// - Provide a single, discoverable, immutable source of truth for the friendly target option /// keys used across the codebase (for example "GeoJson", "Shapefile", "Csv"). /// - Consumers (ConverterFactory, tests, UI lists, README documentation) should reference this /// collection rather than duplicating literal strings to reduce maintenance and avoid drift. /// /// /// /// API & usage /// - Use to enumerate the supported option keys in a stable, read-only form. /// - Use for a simple, case-insensitive membership check. /// - The collection is intentionally small and stable; callers should not attempt to mutate it. /// /// /// /// Relationship with other components /// - Keep this set synchronized with: /// - ConverterFactory registrations so the factory can resolve display keys. /// - FileExtensionHelpers and ConverterUtils.ConversionOptionToDriver mappings so /// option keys map to expected drivers and extensions. /// - Integration test helpers (for example IntegrationTestConstants) and TestData folders. /// /// /// /// Thread-safety & lifetime /// - The underlying collection is an immutable, read-only snapshot and therefore safe for concurrent use. /// - The backing field is initialized once and never modified. /// /// /// /// Maintenance guidance /// - Adding a new target option: /// 1. Add the friendly key to the s_values array below. /// 2. Register the converter in ConverterFactory (or update test injection maps). /// 3. Add/adjust driver and extension mappings in ConverterUtils and FileExtensionHelpers. /// 4. Add corresponding unit/integration tests and TestData samples. /// - When renaming or removing a key, update callers and tests in the same change to avoid transient breakage. /// /// /// /// Test guidance /// - Tests that iterate supported targets should consume rather than embedding literals. /// - Assertion guidance: prefer membership checks and stable token assertions; avoid asserting on exact ordering unless /// ordering is a documented contract. /// /// /// public static class SupportedFormats { private static readonly IReadOnlyList s_values = new ReadOnlyCollection(new[] { "Csv", "EsriJson", "Gdb", "GeoJson", "GeoJsonSeq", "GeoPackage", "Gml", "Gpx", "Kml", "Kmz", "MapInfoInterchange", "MapInfoTab", "Osm", "Shapefile", "TopoJson" }); /// /// Immutable snapshot of supported target option keys. /// public static IReadOnlyList Values => s_values; /// /// Case-insensitive membership check for a candidate option key. /// /// Candidate option key to test. /// True when the option is one of the supported keys; false otherwise. public static bool Contains(string option) { if (string.IsNullOrWhiteSpace(option)) return false; return s_values.Any(s => string.Equals(s, option.Trim(), StringComparison.OrdinalIgnoreCase)); } } }