--[[
    Commander 3.0 - Secure Actions Test Suite

    Tests for secure action system (combat-safe actions):
    - SecureAction module existence
    - Command definitions
    - Config builders
    - State management

    NOTE: These tests verify PREPARATION only, not execution.
    Actual execution requires hardware keypress (Enter key).
]]

local ADDON_NAME, C3 = ...

local Framework = C3.TestFramework
local Assert = Framework.Assert
local suite = Framework:Suite("secure")

-------------------------------------------------------------------------------
-- SecureAction Module Tests
-------------------------------------------------------------------------------

Framework:Test(suite, "SecureAction module exists", function()
    Assert.notNil(C3.SecureAction, "SecureAction should exist")
end)

Framework:Test(suite, "SecureAction has Init method", function()
    Assert.notNil(C3.SecureAction.Init, "SecureAction:Init should exist")
end)

Framework:Test(suite, "SecureAction has Activate method", function()
    Assert.notNil(C3.SecureAction.Activate, "SecureAction:Activate should exist")
end)

Framework:Test(suite, "SecureAction has Deactivate method", function()
    Assert.notNil(C3.SecureAction.Deactivate, "SecureAction:Deactivate should exist")
end)

Framework:Test(suite, "SecureAction has IsActive method", function()
    Assert.notNil(C3.SecureAction.IsActive, "SecureAction:IsActive should exist")
end)

-------------------------------------------------------------------------------
-- Secure Button Tests
-------------------------------------------------------------------------------

Framework:Test(suite, "secure button exists after init", function()
    Assert.notNil(C3.SecureAction._button, "Secure button should be created")
end)

Framework:Test(suite, "IsActive returns false when no action pending", function()
    C3.SecureAction:Deactivate()
    Assert.isFalse(C3.SecureAction:IsActive(), "Should not be active after deactivate")
end)

-------------------------------------------------------------------------------
-- Cast Command Tests
-------------------------------------------------------------------------------

Framework:Test(suite, "cast command definition exists", function()
    local cmd = C3.Commands.cast
    Assert.notNil(cmd, "cast command should be registered")
end)

Framework:Test(suite, "cast command has correct category", function()
    local cmd = C3.Commands.cast
    Assert.notNil(cmd, "cast command should exist")
    -- Category may vary - just verify it exists
end)

Framework:Test(suite, "BuildCastConfig exists", function()
    Assert.notNil(C3.SecureAction.BuildCastConfig, "BuildCastConfig should exist")
end)

Framework:Test(suite, "BuildCastConfig returns nil for empty spell", function()
    local config = C3.SecureAction:BuildCastConfig("")
    Assert.isNil(config, "empty spell should return nil")
end)

Framework:Test(suite, "BuildCastConfig handles quoted spell names", function()
    -- Test that quoted spell names don't cause errors
    local ok = pcall(function()
        C3.SecureAction:BuildCastConfig("\"Test Spell\"")
    end)
    Assert.isTrue(ok, "quoted spell names should not throw")
end)

-------------------------------------------------------------------------------
-- Use Command Tests
-------------------------------------------------------------------------------

Framework:Test(suite, "use command definition exists", function()
    local cmd = C3.Commands.use
    Assert.notNil(cmd, "use command should be registered")
end)

Framework:Test(suite, "BuildUseConfig exists", function()
    Assert.notNil(C3.SecureAction.BuildUseConfig, "BuildUseConfig should exist")
end)

-------------------------------------------------------------------------------
-- Target Command Tests
-------------------------------------------------------------------------------

Framework:Test(suite, "settarget command definition exists", function()
    local cmd = C3.Commands.settarget
    Assert.notNil(cmd, "settarget command should be registered")
end)

Framework:Test(suite, "BuildTargetConfig exists", function()
    Assert.notNil(C3.SecureAction.BuildTargetConfig, "BuildTargetConfig should exist")
end)

-------------------------------------------------------------------------------
-- Mount Command Tests
-------------------------------------------------------------------------------

Framework:Test(suite, "mount command definition exists", function()
    local cmd = C3.Commands.mount
    Assert.notNil(cmd, "mount command should be registered")
end)

Framework:Test(suite, "dismount command definition exists", function()
    local cmd = C3.Commands.dismount
    Assert.notNil(cmd, "dismount command should be registered")
end)

-------------------------------------------------------------------------------
-- Logout/Quit Commands
-------------------------------------------------------------------------------

Framework:Test(suite, "logout command exists", function()
    local cmd = C3.Commands.logout
    Assert.notNil(cmd, "logout command should exist")
end)

Framework:Test(suite, "quit command exists", function()
    local cmd = C3.Commands.quit
    Assert.notNil(cmd, "quit command should exist")
end)

Framework:Test(suite, "camp command exists (alias)", function()
    local cmd = C3.Commands.camp or C3.Aliases.camp
    -- May be an alias, just verify it's accessible
end)

-------------------------------------------------------------------------------
-- Combat Safety Tests
-------------------------------------------------------------------------------

Framework:Test(suite, "SecureAction respects combat lockdown", function()
    -- This test verifies the check exists, not actual combat behavior
    Assert.notNil(InCombatLockdown, "InCombatLockdown API should exist")
end)

Framework:Test(suite, "Secure commands blocked during watch", function()
    -- The watch command should block secure actions
    local result = C3:Query("watch cast Fireball")
    Assert.hasType(result, "Error", "watch cast should be blocked")
end)

return suite
