-- Aura blacklist assistant action registrations.
-- Loaded before MSUF_AssistantRegistry_AurasActions.lua; the main action file passes parser helpers in.
local addonName, MSUF = ...
MSUF = MSUF or _G.MSUF_NS or {}

local M = MSUF.MSUF2 or _G.MSUF2 or {}
MSUF.MSUF2 = M

local A = MSUF.Assistant or {}
MSUF.Assistant = A
M.Assistant = A

A.AurasRegistry = A.AurasRegistry or {}

function A.AurasRegistry.RegisterBlacklistActions(ctx)
    if type(ctx) ~= "table" then return end

    local Registry = ctx.Registry
    local AuraModel = ctx.AuraModel
    local ApplyAura = ctx.ApplyAura
    local AuraScopeLabel = ctx.AuraScopeLabel
    local ParseAuraBlacklistAddSpellAliasArgs = ctx.ParseAuraBlacklistAddSpellAliasArgs
    local ParseAuraBlacklistRemoveSpellAliasArgs = ctx.ParseAuraBlacklistRemoveSpellAliasArgs
    local ParseAuraBlacklistClearAliasArgs = ctx.ParseAuraBlacklistClearAliasArgs
    local ParseAuraBlacklistPresetAliasArgs = ctx.ParseAuraBlacklistPresetAliasArgs
    local ParseAuraBlacklistSummaryAliasArgs = ctx.ParseAuraBlacklistSummaryAliasArgs
    local RegisterBlacklistSummaryAction = A.AurasRegistry and A.AurasRegistry.RegisterBlacklistSummaryAction

    if not (Registry and type(Registry.RegisterAction) == "function") then return end
    if type(AuraModel) ~= "function" or type(ApplyAura) ~= "function" or type(AuraScopeLabel) ~= "function" then return end
    if type(ParseAuraBlacklistAddSpellAliasArgs) ~= "function" or type(ParseAuraBlacklistRemoveSpellAliasArgs) ~= "function" then return end
    if type(ParseAuraBlacklistClearAliasArgs) ~= "function" or type(ParseAuraBlacklistPresetAliasArgs) ~= "function" then return end
    if type(ParseAuraBlacklistSummaryAliasArgs) ~= "function" or type(RegisterBlacklistSummaryAction) ~= "function" then return end

    local function NativeUnitBlacklistReadOnlyMessage(scope, value, operation)
        local target = AuraScopeLabel(scope) .. " auras"
        local prefix
        if operation == "clear" then
            prefix = "I did not clear the saved hidden-aura list for " .. target .. "."
        elseif operation == "preset" then
            prefix = "I did not add that preset to the saved hidden-aura list for " .. target .. "."
        elseif operation == "remove" then
            prefix = "I did not remove " .. tostring(value or "that spell") .. " from the saved hidden-aura list for " .. target .. "."
        else
            prefix = "I did not change the saved hidden-aura list for " .. target .. "."
        end
        return prefix .. " Exact SpellID blacklist edits are legacy read-only data while the native 12.1 aura backend is active, so changing them would not affect live aura display. Use Aura Filters instead, such as player-only, raid, dispellable, crowd-control, or exclusive filter options."
    end

    Registry:RegisterAction({
        key = "aura_blacklist_add_spell",
        label = "Hide Aura Spell",
        type = "auras",
        combatSafe = true,
        aliases = {
            "blacklist", "blacklist spell", "blacklist aura", "blacklist aura spell",
            "block aura", "block aura spell", "ignore aura", "ignore aura spell",
            "hide", "suppress", "stop showing",
            "verstecke", "verstecken", "ausblenden", "aura ausblenden",
            "verstecke aura", "verstecke aura spell", "verstecke spell",
            "hide aura", "hide aura spell", "hide spell", "suppress aura", "suppress spell",
            "stop showing aura", "stop showing spell",
        },
        parseAliasArgs = ParseAuraBlacklistAddSpellAliasArgs,
        run = function(args)
            local scope = args and args.scope or "shared"
            local value = args and args.value
            if type(value) ~= "string" or value == "" then return false, "Which spell do you want me to use? A spell ID, spell link, or full spell name is enough." end
            return false, NativeUnitBlacklistReadOnlyMessage(scope, value)
        end,
    })

    Registry:RegisterAction({
        key = "aura_blacklist_remove_spell",
        label = "Allow Hidden Aura Spell",
        type = "auras",
        combatSafe = true,
        aliases = {
            "remove", "allow",
            "remove aura blacklist spell", "remove spell from aura blacklist",
            "allow aura spell", "allow spell", "allow aura",
            "unblacklist", "unblacklist spell", "unblacklist aura",
            "unblock aura", "unblock spell",
            "unhide", "stop hiding", "show", "let",
            "unhide aura", "unhide spell", "stop hiding aura", "stop hiding spell",
            "show aura again", "show spell again", "let aura show", "let spell show",
        },
        parseAliasArgs = ParseAuraBlacklistRemoveSpellAliasArgs,
        run = function(args)
            local scope = args and args.scope or "shared"
            local value = args and args.value
            if type(value) ~= "string" or value == "" then return false, "Which spell do you want me to use? A spell ID, spell link, or full spell name is enough." end
            return false, NativeUnitBlacklistReadOnlyMessage(scope, value, "remove")
        end,
    })

    Registry:RegisterAction({
        key = "aura_blacklist_clear_spells",
        label = "Clear Hidden Aura Spells",
        type = "auras",
        combatSafe = true,
        aliases = {
            "clear aura blacklist", "clear all aura blacklist", "allow all aura blacklist",
            "allow all aura blacklist spells", "remove all aura blacklist spells",
            "empty aura blacklist", "reset aura blacklist", "delete all aura blacklist spells",
            "clear player aura blacklist", "clear target aura blacklist", "clear focus aura blacklist", "clear boss aura blacklist",
            "empty player aura blacklist", "empty target aura blacklist", "empty focus aura blacklist", "empty boss aura blacklist",
            "reset player aura blacklist", "reset target aura blacklist", "reset focus aura blacklist", "reset boss aura blacklist",
            "allow all player aura blacklist spells", "allow all target aura blacklist spells",
            "allow all focus aura blacklist spells", "allow all boss aura blacklist spells",
            "delete all player aura blacklist spells", "delete all target aura blacklist spells",
            "delete all focus aura blacklist spells", "delete all boss aura blacklist spells",
        },
        parseAliasArgs = ParseAuraBlacklistClearAliasArgs,
        run = function(args)
            local scope = args and args.scope or "shared"
            return false, NativeUnitBlacklistReadOnlyMessage(scope, nil, "clear")
        end,
    })

    Registry:RegisterAction({
        key = "aura_blacklist_add_preset",
        label = "Add Hidden Aura Preset",
        type = "auras",
        combatSafe = true,
        aliases = {
            "aura blacklist", "aura blacklist preset", "blacklist preset", "blacklist aura preset",
            "add aura blacklist preset", "add blacklist preset",
            "blacklist raid buffs", "ignore raid buffs", "block raid buffs",
            "blacklist cooldowns", "ignore cooldowns", "block cooldowns",
            "blacklist self buffs", "ignore self buffs", "block self buffs",
            "blacklist preservation evoker", "ignore preservation evoker",
            "blacklist augmentation evoker", "ignore augmentation evoker",
            "blacklist resto druid", "blacklist restoration druid", "ignore resto druid",
            "blacklist disc priest", "blacklist discipline priest", "ignore disc priest",
            "blacklist holy priest", "ignore holy priest",
            "blacklist mistweaver monk", "ignore mistweaver monk",
            "blacklist resto shaman", "blacklist restoration shaman", "ignore resto shaman",
            "blacklist holy paladin", "blacklist holy pala", "ignore holy paladin",
            "blacklist blessing of the bronze", "ignore blessing of the bronze",
            "blacklist rogue poisons", "ignore rogue poisons",
            "blacklist shaman imbues", "ignore shaman imbues",
            "blacklist resource auras", "ignore resource auras",
        },
        parseAliasArgs = ParseAuraBlacklistPresetAliasArgs,
        run = function(args)
            local scope = args and args.scope or "shared"
            local preset = args and args.preset
            if type(preset) ~= "string" or preset == "" then return false, "Which hidden-aura preset do you want me to use?" end
            return false, NativeUnitBlacklistReadOnlyMessage(scope, preset, "preset")
        end,
    })

    RegisterBlacklistSummaryAction(ctx)
end
