using System.Numerics;

namespace LightlessSync.UI.Tags;

/// <summary>
/// Library of tags. That's it.
/// </summary>
public sealed class ProfileTagService
{
    private static readonly IReadOnlyDictionary<int, ProfileTagDefinition> TagLibrary = CreateTagLibrary();

    public static IReadOnlyDictionary<int, ProfileTagDefinition> GetTagLibrary()
        => TagLibrary;

    public static IReadOnlyList<ProfileTagDefinition> ResolveTags(IReadOnlyList<int>? tagIds)
    {
        if (tagIds is null || tagIds.Count == 0)
            return Array.Empty<ProfileTagDefinition>();

        var result = new List<ProfileTagDefinition>(tagIds.Count);
        foreach (var id in tagIds)
        {
            if (TagLibrary.TryGetValue(id, out var tag))
                result.Add(tag);
        }

        return result;
    }

    public bool TryGetDefinition(int tagId, out ProfileTagDefinition definition)
        => TagLibrary.TryGetValue(tagId, out definition);

    private static IReadOnlyDictionary<int, ProfileTagDefinition> CreateTagLibrary()
    {
        return new Dictionary<int, ProfileTagDefinition>
        {
            [0] = ProfileTagDefinition.FromIconAndText(
                230419,
                "SFW",
                background: new Vector4(0.16f, 0.24f, 0.18f, 0.95f),
                border: new Vector4(0.32f, 0.52f, 0.34f, 0.85f),
                textColor: new Vector4(0.78f, 0.94f, 0.80f, 1f)),

            [1] = ProfileTagDefinition.FromIconAndText(
                230419,
                "NSFW",
                background: new Vector4(0.32f, 0.18f, 0.22f, 0.95f),
                border: new Vector4(0.72f, 0.32f, 0.38f, 0.85f),
                textColor: new Vector4(1f, 0.82f, 0.86f, 1f)),


            [2] = ProfileTagDefinition.FromIconAndText(
                61545,
                "RP",
                background: new Vector4(0.20f, 0.20f, 0.30f, 0.95f),
                border: new Vector4(0.42f, 0.42f, 0.66f, 0.85f),
                textColor: new Vector4(0.80f, 0.84f, 1f, 1f)),

            [3] = ProfileTagDefinition.FromIconAndText(
                61545,
                "ERP",
                background: new Vector4(0.20f, 0.20f, 0.30f, 0.95f),
                border: new Vector4(0.42f, 0.42f, 0.66f, 0.85f),
                textColor: new Vector4(0.80f, 0.84f, 1f, 1f)),

            [4] = ProfileTagDefinition.FromIconAndText(
                230420,
                "No RP",
                background: new Vector4(0.30f, 0.18f, 0.30f, 0.95f),
                border: new Vector4(0.69f, 0.40f, 0.65f, 0.85f),
                textColor: new Vector4(1f, 0.84f, 1f, 1f)),

            [5] = ProfileTagDefinition.FromIconAndText(
                230420,
                "No ERP",
                background: new Vector4(0.30f, 0.18f, 0.30f, 0.95f),
                border: new Vector4(0.69f, 0.40f, 0.65f, 0.85f),
                textColor: new Vector4(1f, 0.84f, 1f, 1f)),


            [6] = ProfileTagDefinition.FromIconAndText(
                60756,
                "Venues",
                background: new Vector4(0.18f, 0.24f, 0.28f, 0.95f),
                border: new Vector4(0.33f, 0.55f, 0.63f, 0.85f),
                textColor: new Vector4(0.78f, 0.90f, 0.97f, 1f)),

            [7] = ProfileTagDefinition.FromIconAndText(
                61546,
                "GPose",
                background: new Vector4(0.18f, 0.18f, 0.26f, 0.95f),
                border: new Vector4(0.35f, 0.34f, 0.54f, 0.85f),
                textColor: new Vector4(0.80f, 0.82f, 0.96f, 1f)),


            [8] = ProfileTagDefinition.FromIconAndText(
                60572,
                "Limsa"),

            [9] = ProfileTagDefinition.FromIconAndText(
                60573,
                "Gridania"),

            [10] = ProfileTagDefinition.FromIconAndText(
                60574,
                "Ul'dah"),


            [11] = ProfileTagDefinition.FromIconAndText(
                61397,
                "WU/T"),


            [1001] = ProfileTagDefinition.FromIcon(61806), // PVP
            [1002] = ProfileTagDefinition.FromIcon(61832), // Ultimate
            [1003] = ProfileTagDefinition.FromIcon(61802), // Raids
            [1004] = ProfileTagDefinition.FromIcon(61807), // Roulette
            [1005] = ProfileTagDefinition.FromIcon(61816), // Crafting
            [1006] = ProfileTagDefinition.FromIcon(61753), // Casual
            [1007] = ProfileTagDefinition.FromIcon(61754), // Hardcore
            [1008] = ProfileTagDefinition.FromIcon(61759), // Glamour
            [1009] = ProfileTagDefinition.FromIcon(61760),  // Mentor

            // Role Tags
            [2001] = ProfileTagDefinition.FromIconAndText(62581, "Tank"),
            [2002] = ProfileTagDefinition.FromIconAndText(62582, "Healer"),
            [2003] = ProfileTagDefinition.FromIconAndText(62583, "DPS"),
            [2004] = ProfileTagDefinition.FromIconAndText(62584, "Melee DPS"),
            [2005] = ProfileTagDefinition.FromIconAndText(62585, "Ranged DPS"),
            [2006] = ProfileTagDefinition.FromIconAndText(62586, "Physical Ranged DPS"),
            [2007] = ProfileTagDefinition.FromIconAndText(62587, "Magical Ranged DPS"),

            // Misc Role Tags
            [2101] = ProfileTagDefinition.FromIconAndText(62146, "All-Rounder"),

            // Tank Job Tags
            [2201] = ProfileTagDefinition.FromIconAndText(62119, "Paladin"),
            [2202] = ProfileTagDefinition.FromIconAndText(62121, "Warrior"),
            [2203] = ProfileTagDefinition.FromIconAndText(62132, "Dark Knight"),
            [2204] = ProfileTagDefinition.FromIconAndText(62137, "Gunbreaker"),

            // Healer Job Tags
            [2301] = ProfileTagDefinition.FromIconAndText(62124, "White Mage"),
            [2302] = ProfileTagDefinition.FromIconAndText(62128, "Scholar"),
            [2303] = ProfileTagDefinition.FromIconAndText(62133, "Astrologian"),
            [2304] = ProfileTagDefinition.FromIconAndText(62140, "Sage"),

            // Melee DPS Job Tags
            [2401] = ProfileTagDefinition.FromIconAndText(62120, "Monk"),
            [2402] = ProfileTagDefinition.FromIconAndText(62122, "Dragoon"),
            [2403] = ProfileTagDefinition.FromIconAndText(62130, "Ninja"),
            [2404] = ProfileTagDefinition.FromIconAndText(62134, "Samurai"),
            [2405] = ProfileTagDefinition.FromIconAndText(62139, "Reaper"),
            [2406] = ProfileTagDefinition.FromIconAndText(62141, "Viper"),

            // PRanged DPS Job Tags
            [2501] = ProfileTagDefinition.FromIconAndText(62123, "Bard"),
            [2502] = ProfileTagDefinition.FromIconAndText(62131, "Machinist"),
            [2503] = ProfileTagDefinition.FromIconAndText(62138, "Dancer"),

            // MRanged DPS Job Tags
            [2601] = ProfileTagDefinition.FromIconAndText(62125, "Black Mage"),
            [2602] = ProfileTagDefinition.FromIconAndText(62127, "Summoner"),
            [2603] = ProfileTagDefinition.FromIconAndText(62135, "Red Mage"),
            [2604] = ProfileTagDefinition.FromIconAndText(62142, "Pictomancer"),
            [2605] = ProfileTagDefinition.FromIconAndText(62136, "Blue Mage") // this job sucks xd

        };
    }
}
