using System.Text.Json; using System.Text.Json.Serialization; namespace Oms.Application.Shared; public class CouponApplyScope { [JsonPropertyName("countryCodes")] public List? CountryCodes { get; set; } } public static class MarketingCouponScope { public static bool Matches(string? applyScopeJson, string? destinationCountry) { var codes = ParseCountryCodes(applyScopeJson); if (codes.Count == 0) { return true; } if (string.IsNullOrWhiteSpace(destinationCountry)) { return false; } var dest = destinationCountry.Trim(); return codes.Any(x => string.Equals(x, dest, StringComparison.OrdinalIgnoreCase)); } public static IReadOnlyList ParseCountryCodes(string? applyScopeJson) { if (string.IsNullOrWhiteSpace(applyScopeJson)) { return []; } try { var scope = JsonSerializer.Deserialize(applyScopeJson); return (scope?.CountryCodes ?? []) .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.Trim()) .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); } catch (JsonException) { return []; } } }