using Meezi.Core.Discover;
using Meezi.Core.Entities;
using Meezi.Core.Enums;

namespace Meezi.Infrastructure.Discover;

public record CafeBadgeDto(string Key, string Label, string Icon);

public static class DiscoverBadgeMapping
{
    public static IReadOnlyList<CafeBadgeDto> ToDtos(Cafe cafe, string lang = "fa")
    {
        if (cafe.PlanTier != PlanTier.Enterprise)
            return [];

        var keys = DiscoverBadgesSerializer.Deserialize(cafe.DiscoverBadgesJson);
        var list = new List<CafeBadgeDto>();
        foreach (var key in keys)
        {
            var def = CafeBadgeCatalog.Resolve(key);
            if (def is null) continue;
            var label = lang switch
            {
                "en" => def.LabelEn,
                "ar" => def.LabelAr,
                _ => def.LabelFa
            };
            list.Add(new CafeBadgeDto(def.Key, label, def.Icon));
        }

        return list;
    }
}
