-- test_catalog_selectors.lua
-- Verifies the 4 catalog lifecycle selectors register + return correct values.
dofile("wow_mock.lua")
dofile("../Core/HDGR_Constants.lua")
dofile("../Core/HDGR_Actions.lua")
dofile("../Core/HDGR_Resolvers.lua")
dofile("../Core/HDGR_Format.lua")
dofile("../Core/HDGR_StoreFurnishings.lua")
dofile("../Core/HDGR_Store.lua")
dofile("../UI/HDGR_Selectors.lua")
dofile("../UI/HDGR_Selectors_Catalog.lua")

HDG.Store:LoadFromSavedVariables()

local s = HDG.Store:GetState()
local status = HDG.Selectors:Call("catalog.loadingStatus", s, {})
assert(status == "idle", "loadingStatus idle by default")

local pending = HDG.Selectors:Call("catalog.refreshPending", s, {})
assert(pending == false, "refreshPending false by default")

local gen = HDG.Selectors:Call("catalog.resolverTick", s, {})
assert(gen == 0, "catalog resolver tick 0 by default")

local variants = HDG.Selectors:Call("catalog.variantsLoaded", s, {})
assert(variants == false, "variantsLoaded false by default")

-- After dispatching REFRESH_QUEUED -> refreshPending true
HDG.Store:Dispatch({ type = HDG.Constants.ACTIONS.CATALOG_REFRESH_QUEUED })
local pending2 = HDG.Selectors:Call("catalog.refreshPending", HDG.Store:GetState(), {})
assert(pending2 == true, "refreshPending true after REFRESH_QUEUED")

-- Boolean state selectors (added Task 3.3)

-- Reset state to idle
s.session.catalog.status = "idle"
assert(HDG.Selectors:Call("catalog.isLoading", s, {}) == true,  "isLoading true when status=idle")
assert(HDG.Selectors:Call("catalog.isReady",   s, {}) == false, "isReady false when status=idle")

-- Transition to loading
s.session.catalog.status = "loading"
assert(HDG.Selectors:Call("catalog.isLoading", s, {}) == true,  "isLoading true when status=loading")
assert(HDG.Selectors:Call("catalog.isReady",   s, {}) == false, "isReady false when status=loading")

-- Transition to ready
s.session.catalog.status = "ready"
assert(HDG.Selectors:Call("catalog.isLoading", s, {}) == false, "isLoading false when status=ready")
assert(HDG.Selectors:Call("catalog.isReady",   s, {}) == true,  "isReady true when status=ready")

print("test_catalog_selectors: boolean state selectors PASS")
print("test_catalog_selectors: PASS")
