using System;

namespace HSUI.Enums;

/// <summary>
/// HUD layout AddonNameHash values. Uses CRC32 of "AddonName_a".
/// Source: https://github.com/zacharied/FFXIV-Plugin-HudManager/blob/testing/HUDManager/Structs/ElementKind.cs
/// </summary>
public enum ElementKind : uint
{
    // Hotbars
    Hotbar1 = 0xC48D3605,        // _ActionBar_a
    Hotbar2 = 0xFB7B6E1E,        // _ActionBar01_a
    Hotbar3 = 0xF93DD047,        // _ActionBar02_a
    Hotbar4 = 0xF8FFBA70,        // _ActionBar03_a
    Hotbar5 = 0xFDB0ACF5,        // _ActionBar04_a
    Hotbar6 = 0xFC72C6C2,        // _ActionBar05_a
    Hotbar7 = 0xFE34789B,        // _ActionBar06_a
    Hotbar8 = 0xFFF612AC,        // _ActionBar07_a
    Hotbar9 = 0xF4AA5591,        // _ActionBar08_a
    Hotbar10 = 0xF5683FA6,       // _ActionBar09_a
    PetHotbar = 0xD8D188FF,      // _ActionBarEx_a
    CrossHotbar = 0xBA81E8D1,    // _ActionCross_a
    LeftWCrossHotbar = 0x6665735D,
    RightWCrossHotbar = 0x70DDFD27,

    // Player & target
    ParameterBar = 0x981EC49E,   // _ParameterWidget_a (player HP/MP)
    ProgressBar = 0xECB29811,    // _CastBar_a
    TargetBar = 0x913EC97D,      // _TargetInfo_a
    TargetInfoHp = 0xBD128377,   // _TargetInfoMainTarget_a
    TargetInfoProgressBar = 0xCB54A2EF,  // _TargetInfoCastBar_a
    TargetInfoStatus = 0x076F596B,       // _TargetInfoBuffDebuff_a
    FocusTargetBar = 0xC292F05F, // _FocusTargetInfo_a

    // Party & lists
    PartyList = 0x3D425039,      // _PartyList_a
    AllianceList1 = 0x2943729A,
    AllianceList2 = 0x2B05CCC3,
    EnemyList = 0xB8BD6685,      // _EnemyList_a

    // Misc HUD
    ExperienceBar = 0x21E53CCE,  // _Exp_a
    LimitGauge = 0xC79F450A,     // _LimitBreak_a
    StatusEffects = 0x4A569616,  // _Status_a
    StatusInfoEnhancements = 0x1F4230B4,   // _StatusCustom0_a
    StatusInfoEnfeeblements = 0x1E805A83,  // _StatusCustom1_a
    StatusInfoOther = 0x1CC6E4DA,          // _StatusCustom2_a
    StatusInfoConditionalEnhancements = 0x1D048EED,  // _StatusCustom3_a

    // Job gauges (PLD, WAR, DRK, GNB, WHM, SCH, AST, SGE, MNK, DRG, NIN, SAM, RPR, VPR, BRD, MCH, DNC, BLM, SMN, RDM, PCT)
    OathGauge = 0xEFBAFE40,      // JobHudPLD0
    BeastGauge = 0x7F5D020A,     // JobHudWAR0
    BloodGauge = 0xF04E8778,     // JobHudDRK0
    DarksideGauge = 0xF18CED4F,  // JobHudDRK1
    PowderGauge = 0xAEC2C0DF,    // JobHudGNB0
    HealingGauge = 0x7A3727B2,   // JobHudWHM0
    AetherflowGaugeSch = 0xCADD58CB,  // JobHudACN0
    FaerieGauge = 0xA1A8A487,    // JobHudSCH0
    ArcanaGauge = 0x959978B2,    // JobHudAST0
    EukrasiaGauge = 0x11D01C49,  // JobHudGFF0 (SGE)
    AddersgallGauge = 0x1012767E, // JobHudGFF1 (SGE)
    MastersGauge = 0x7251AC33,   // JobHudMNK0
    ChakraGauge = 0x7393C604,    // JobHudMNK1
    DragonGauge = 0xBA9838C0,    // JobHudDRG0
    NinkiGauge = 0x713BF2BF,     // JobHudNIN0
    Kazematoi = 0x6CD4313E,      // JobHudNIN1v70 (NIN)
    KenkiGauge = 0xECB607D5,     // JobHudSAM0
    SenGauge = 0xED746DE2,       // JobHudSAM1
    SoulGauge = 0xA2D9B660,      // JobHudRRP0 (RPR)
    DeathGauge = 0xA31BDC57,     // JobHudRRP1 (RPR)
    Vipersight = 0xB7694B56,     // JobHudRDB0 (VIP)
    SerpentOfferingsGauge = 0xB6AB2161,  // JobHudRDB1 (VIP)
    SongGauge = 0x7E747433,      // JobHudBRD0
    HeatGauge = 0x9874C76C,      // JobHudMCH0
    StepGauge = 0x90EAD514,      // JobHudDNC0
    FourfoldFeathers = 0x9128BF23,  // JobHudDNC1
    ElementalGauge = 0xDCAC125A, // JobHudBLM0
    AstralGauge = 0xDD6E786D,    // JobHudBLM1
    AetherflowGaugeSmn = 0x3BF3453A,  // JobHudSMN0
    TranceGauge = 0x3A312F0D,    // JobHudSMN1
    BalanceGauge = 0xEF0A5B00,   // JobHudRDM0
    Canvases = 0x7A6A6A42,       // JobHudRPM0 (PCT)
    PaletteGauge = 0x7BA80075,   // JobHudRPM1 (PCT)
}

public static class ElementKindHelper
{
    public static ElementKind ElementKindByHotBarId(int hotBarId)
    {
        return hotBarId switch
        {
            0 => ElementKind.Hotbar1,
            1 => ElementKind.Hotbar2,
            2 => ElementKind.Hotbar3,
            3 => ElementKind.Hotbar4,
            4 => ElementKind.Hotbar5,
            5 => ElementKind.Hotbar6,
            6 => ElementKind.Hotbar7,
            7 => ElementKind.Hotbar8,
            8 => ElementKind.Hotbar9,
            9 => ElementKind.Hotbar10,
            10 => ElementKind.PetHotbar,
            _ => throw new ArgumentOutOfRangeException(nameof(hotBarId))
        };
    }

    /// <summary>Returns ElementKind hashes for the current job's gauges (0-4 gauges per job).</summary>
    public static ElementKind[] GetJobGaugeElementKinds(uint jobId)
    {
        return jobId switch
        {
            19 => new[] { ElementKind.OathGauge },                                    // PLD
            21 => new[] { ElementKind.MastersGauge, ElementKind.ChakraGauge },        // MNK
            22 => new[] { ElementKind.BeastGauge },                                   // WAR
            23 => new[] { ElementKind.DragonGauge },                                  // DRG
            24 => new[] { ElementKind.SongGauge },                                    // BRD
            25 => new[] { ElementKind.HealingGauge },                                 // WHM
            27 => new[] { ElementKind.ElementalGauge, ElementKind.AstralGauge },      // BLM
            28 => new[] { ElementKind.AetherflowGaugeSmn, ElementKind.TranceGauge },  // SMN
            29 => new[] { ElementKind.AetherflowGaugeSch, ElementKind.FaerieGauge },  // SCH
            30 => new[] { ElementKind.NinkiGauge, ElementKind.Kazematoi },            // NIN
            31 => new[] { ElementKind.HeatGauge },                                    // MCH
            32 => new[] { ElementKind.BloodGauge, ElementKind.DarksideGauge },        // DRK
            33 => new[] { ElementKind.ArcanaGauge },                                  // AST
            34 => new[] { ElementKind.KenkiGauge, ElementKind.SenGauge },             // SAM
            35 => new[] { ElementKind.BalanceGauge },                                 // RDM
            37 => new[] { ElementKind.PowderGauge },                                  // GNB
            38 => new[] { ElementKind.StepGauge, ElementKind.FourfoldFeathers },      // DNC
            39 => new[] { ElementKind.SoulGauge, ElementKind.DeathGauge },            // RPR
            40 => new[] { ElementKind.EukrasiaGauge, ElementKind.AddersgallGauge },   // SGE
            41 => new[] { ElementKind.Vipersight, ElementKind.SerpentOfferingsGauge },// VPR
            42 => new[] { ElementKind.Canvases, ElementKind.PaletteGauge },           // PCT
            _ => Array.Empty<ElementKind>()
        };
    }
}
