-- HDG_HT_LayoutStore.lua
-- Facade over HDG.Store for House-tab layout state. Mirrors the
-- HDG_ProjectsStore.lua pattern: pure read helpers + thin write wrappers
-- that delegate to Store setters. No state of its own; lookups go through
-- HDG.Store:GetState().houseTab on every call.

local addonName, privateDB = ...
privateDB.HDG_HT = privateDB.HDG_HT or {}
local M = {}
privateDB.HDG_HT.LayoutStore = M

local function ht()
    local HDG = _G.HousingDecorGuide
    local s = HDG and HDG.Store
    return s and s.state and s.state.houseTab
end

local function store()
    local HDG = _G.HousingDecorGuide
    return HDG and HDG.Store
end

-- ---------------------------------------------------------------------------
-- Reads
-- ---------------------------------------------------------------------------
function M.IsEnabled(widgetID)
    local h = ht(); return h and h.enabled and h.enabled[widgetID]
end

function M.GetOrder()
    local h = ht(); return h and h.order or {}
end

function M.GetWidth(widgetID)
    local h = ht(); return h and h.width and h.width[widgetID]
end

function M.GetOverrides(widgetID)
    local h = ht(); return h and h.layoutOverrides and h.layoutOverrides[widgetID] or {}
end

function M.GetOverride(widgetID, key)
    local h = ht()
    return h and h.layoutOverrides and h.layoutOverrides[widgetID] and h.layoutOverrides[widgetID][key]
end

-- Read-only access to the whole sub-table for callers that need to iterate
-- (e.g. LayoutDump). MUST NOT be mutated by callers.
function M.GetAll()
    return ht()
end

-- ---------------------------------------------------------------------------
-- Writes (delegate to Store setters)
-- ---------------------------------------------------------------------------
function M.SetEnabled(widgetID, enabled)
    local s = store(); if s then s:SetWidgetEnabled(widgetID, enabled) end
end

function M.SetOrder(orderArray)
    local s = store(); if s then s:SetWidgetOrder(orderArray) end
end

function M.SetWidth(widgetID, width)
    local s = store(); if s then s:SetWidgetWidth(widgetID, width) end
end

function M.SetOverride(widgetID, key, value)
    local s = store(); if s then s:SetWidgetOverride(widgetID, key, value) end
end

function M.ResetOverrides(widgetID)
    local s = store(); if s then s:ResetWidgetOverrides(widgetID) end
end

function M.ResetAll()
    local s = store(); if s then s:ResetHouseTabLayout() end
end
