local NS = rawget(_G, "MCDVoiceCooldownNS") or {}
_G.MCDVoiceCooldownNS = NS

NS.TestController = NS.TestController or {}

local TestController = NS.TestController
local CONST = NS.Constants or {}
local OBJECT_TYPE_SPELL = CONST.OBJECT_TYPE_SPELL or "spell"

local function GetApi()
    return NS.API
end

function TestController:TestBloodlustConfig(aceOptions)
    local api = GetApi()
    local state = aceOptions and aceOptions.GetState and aceOptions:GetState() or {}
    if not api or type(api.PlayBloodlustNotification) ~= "function" then
        return
    end

    api.PlayBloodlustNotification({
        customSoundPaths = type(state.bloodlustPaths) == "table" and state.bloodlustPaths or {},
    })
end

function TestController:TestCurrent(aceOptions)
    local api = GetApi()
    local state = aceOptions and aceOptions.GetState and aceOptions:GetState() or {}
    if not api then
        return
    end

    local modeTts, modeSound = api.GetModes()
    local soundFields = aceOptions:ResolveSoundSourceFields(state, modeTts, modeSound)
    local notifyMode = soundFields.notifyMode
    local soundPath = aceOptions:NormalizeSoundPath(soundFields.soundPath or "")

    local cfg = {
        spellId = tonumber(state.spellId) or 0,
        objectType = tostring(state.objectType or OBJECT_TYPE_SPELL),
        spellName = tostring(state.spellName or ""),
        notifyMode = notifyMode,
        ttsText = tostring(state.ttsText or ""),
        ttsRate = math.max(-10, math.min(10, tonumber(state.ttsRate) or 0)),
        soundPath = soundPath,
    }

    if tostring(state.entryType or "") == "cast" and type(api.PlayCastSuccessNotification) == "function" then
        api.PlayCastSuccessNotification(cfg)
    elseif type(api.PlayReadyNotification) == "function" then
        api.PlayReadyNotification(cfg)
    end
end
