namespace Meezi.Core.Discover;

public record CafeBadgeDefinition(string Key, string LabelFa, string LabelEn, string LabelAr, string Icon);

public static class CafeBadgeCatalog
{
    public static readonly IReadOnlyList<CafeBadgeDefinition> All =
    [
        new("verified_partner", "شریک تأییدشده", "Verified partner", "شريك موثّق", "✓"),
        new("award_winner", "برنده جایزه", "Award winner", "فائز بجمة", "🏆"),
        new("roastery", "رستری تخصصی", "Specialty roastery", "محمصة متخصصة", "☕"),
        new("eco_friendly", "دوستدار محیط زیست", "Eco-friendly", "صديق للبيئة", "🌿"),
        new("women_owned", "مدیریت زنان", "Women-owned", "إدارة نسائية", "👩"),
        new("pet_friendly", "مجاز حیوان خانگی", "Pet-friendly", "يسمح بالحيوانات", "🐾"),
    ];

    private static readonly Dictionary<string, CafeBadgeDefinition> ByKey =
        All.ToDictionary(x => x.Key, StringComparer.OrdinalIgnoreCase);

    public static bool IsValidKey(string? key) =>
        !string.IsNullOrWhiteSpace(key) && ByKey.ContainsKey(key.Trim());

    public static CafeBadgeDefinition? Resolve(string key) =>
        ByKey.TryGetValue(key.Trim(), out var def) ? def : null;

    public static IReadOnlyList<string> NormalizeKeys(IEnumerable<string>? keys)
    {
        if (keys is null) return [];
        return keys
            .Select(k => k.Trim())
            .Where(IsValidKey)
            .Distinct(StringComparer.OrdinalIgnoreCase)
            .Take(8)
            .ToList();
    }
}
