-- VDS_Palette
-- ============================================================================
-- Scheme-INVARIANT color source. Sits parallel to VDS.Theme. Brand colors
-- (expansion, faction, source-type, etc.) live here so they don't change
-- when the user swaps themes. See cookbook 05.
--
-- ADDON: populate the per-namespace color tables for your domain. Default
-- starter ships an empty Palette with the namespace contract intact.

VDS = VDS or {}
VDS.Palette = VDS.Palette or {}

VDS.Palette.OWNED_NAMESPACES = {
    accent = true,  -- brand accent colors (selection markers, active-tab bars)
}

-- Brand-accent tokens; survive theme switches. Donor source: scheme.accent
-- in VDS_SchemeConstants.lua -- hoisted here because it's identity, not theming.
VDS.Palette._COLORS = {
    ["accent.teal"] = { r = 0.08, g = 0.72, b = 0.65, a = 1.00 },
    ["accent.gold"] = { r = 1.00, g = 0.82, b = 0.10, a = 1.00 }, -- selected-row ring
}

local function _checkNamespace(token)
    local ns = token:match("^([^.]+)")
    if not VDS.Palette.OWNED_NAMESPACES[ns] then
        local hint = ""
        if VDS.Theme.OWNED_COLOR_NAMESPACES[ns] then -- Theme loaded before Palette; strict read
            hint = " -- use VDS.Theme:ColorCode instead"
        end
        error(("Palette:ColorCode: namespace %q not owned by Palette%s"):format(ns, hint), 3)
    end
end

function VDS.Palette:GetColor(token)
    return self._COLORS[token]
end

function VDS.Palette:ColorCode(token)
    _checkNamespace(token)
    local c = self:GetColor(token)
    if not c then error(("Palette:ColorCode: token %q does not resolve"):format(token), 2) end
    return string.format("|cFF%02X%02X%02X",
        math.floor(c.r * 255 + 0.5),
        math.floor(c.g * 255 + 0.5),
        math.floor(c.b * 255 + 0.5))
end
