namespace SatelliteProvider.Common.Enums; // AZ-484: contract v1.0.0 stores TileSource as a snake_case string // ('google_maps', 'uav'). Dapper's TypeHandler for enum types is bypassed // during deserialization (Dapper issue #259), so we cannot rely on a Dapper // handler to round-trip enum<->wire string. Instead, TileEntity stores the // wire value as a plain string and producers/consumers convert through this // helper at the boundary, preserving type safety in business code while // avoiding the Dapper enum read bug. public static class TileSourceConverter { public const string GoogleMapsWireValue = "google_maps"; public const string UavWireValue = "uav"; public static string ToWireValue(TileSource value) => value switch { TileSource.GoogleMaps => GoogleMapsWireValue, TileSource.Uav => UavWireValue, _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TileSource"), }; public static TileSource FromWireValue(string wireValue) { ArgumentNullException.ThrowIfNull(wireValue); return wireValue.ToLowerInvariant() switch { GoogleMapsWireValue => TileSource.GoogleMaps, UavWireValue => TileSource.Uav, _ => throw new ArgumentException($"'{wireValue}' is not a defined member of enum TileSource", nameof(wireValue)), }; } public static bool IsValidWireValue(string? wireValue) => wireValue is GoogleMapsWireValue or UavWireValue; }