--[[
ConfigData.lua - Mr. Mythical Gear Check Configuration

Purpose: Default settings and configuration constants for gear validation
Dependencies: None
Author: Braunerr
--]]

local MrMythicalGearCheck = MrMythicalGearCheck or {}
MrMythicalGearCheck.ConfigData = {}

local ConfigData = MrMythicalGearCheck.ConfigData

--- Configuration constants for gear validation
ConfigData.CONSTANTS = {
    -- Equipment slot IDs (single source of truth)
    SLOT_IDS = {
        HEAD = 1,
        NECK = 2,
        SHOULDER = 3,
        BODY = 4,
        CHEST = 5,
        BELT = 6,
        LEGS = 7,
        FEET = 8,
        WRIST = 9,
        HANDS = 10,
        RING1 = 11,
        RING2 = 12,
        TRINKET1 = 13,
        TRINKET2 = 14,
        CLOAK = 15,
        MAIN_HAND = 16,
        OFF_HAND = 17
    },

    -- Midnight enchantable slots. Neck, wrist, hands, belt, cloak, and trinkets
    -- are not enchanted this expansion. Off-hand holdables and shields are skipped in GearUtils.
    -- Revisit this list on patch day (see Data/SeasonData.lua and README).
    ENCHANTABLE_SLOTS = {
        [1] = true,   -- Head
        [3] = true,   -- Shoulder
        [5] = true,   -- Chest
        [7] = true,   -- Legs
        [8] = true,   -- Feet
        [11] = true,  -- Ring 1
        [12] = true,  -- Ring 2
        [16] = true,  -- Main Hand
        [17] = true   -- Off Hand
    },
    
    -- Slots where enchant material quality (premium vs cheap) matters.
    -- Expansion 11 uses a 2-rank system; leave empty to disable premium-material checks.
    -- Re-populate when an expansion reintroduces cheap vs premium materials per slot.
    QUALITY_CHECK_SLOTS = {
    },

    -- Weapon slots for Death Knight rune checking
    WEAPON_SLOTS = {
        [16] = true,  -- Main Hand
        [17] = true   -- Off Hand
    },
    
    -- Slots that can have gems in Expansion 11.
    -- Neck and ring sockets are no longer treated as expected sockets; we only validate empty sockets when present.
    GEMABLE_SLOTS = {
        [1] = 1,      -- Head (1 socket)
        [2] = 0,      -- Neck (check empty sockets only)
        [6] = 1,      -- Belt (1 socket)
        [9] = 1,      -- Wrist (1 socket)
        [11] = 0,     -- Ring 1 (check empty sockets only)
        [12] = 0      -- Ring 2 (check empty sockets only)
    },
    
    -- Gem parsing configuration (item string: itemId:enchant:gem1:gem2:gem3:...)
    GEM_SLOT_POSITIONS = {3, 4, 5}
}

--- Helper to get defaults from Options module
local function getDefaults()
    return (MrMythicalGearCheck.Options and MrMythicalGearCheck.Options.DEFAULTS) or {}
end

--- Gets the user's preferred minimum enchant rank setting
--- @return number Minimum enchant rank (1-2, defaults to 2)
function ConfigData:GetMinEnchantRank()
    local db = MrMythicalGearCheckDB or {}
    return db.MIN_ENCHANT_RANK or getDefaults().MIN_ENCHANT_RANK or 2
end

--- Returns true when any slots are configured for premium-material enchant checks
--- @return boolean
function ConfigData:HasEnchantQualityChecks()
    local slots = self.CONSTANTS and self.CONSTANTS.QUALITY_CHECK_SLOTS
    if not slots then
        return false
    end
    for _ in pairs(slots) do
        return true
    end
    return false
end

--- Gets whether high quality enchant materials are required
--- @return boolean Whether to require high quality materials (defaults to false)
function ConfigData:RequirePremiumEnchants()
    -- Exp 11 has no quality-check slots; keep stored preference but treat as inactive.
    if not self:HasEnchantQualityChecks() then
        return false
    end
    local db = MrMythicalGearCheckDB or {}
    if db.REQUIRE_PREMIUM_ENCHANTS == nil then
        return getDefaults().REQUIRE_PREMIUM_ENCHANTS or false
    end
    return db.REQUIRE_PREMIUM_ENCHANTS
end

--- Whether premium-material enchant checks apply to a slot
--- @param slotId number Equipment slot ID
--- @return boolean
function ConfigData:ShouldCheckEnchantQuality(slotId)
    if not slotId or not self:RequirePremiumEnchants() then
        return false
    end
    local slots = self.CONSTANTS and self.CONSTANTS.QUALITY_CHECK_SLOTS
    return slots and slots[slotId] == true
end

--- Gets the minimum gem rank requirement
--- @return number Minimum gem rank (defaults to 2)
function ConfigData:GetMinGemRank()
    local db = MrMythicalGearCheckDB or {}
    return db.MIN_GEM_RANK or getDefaults().MIN_GEM_RANK or 2
end

--- Gets whether the gear summary panel should be shown on the character info screen
--- @return boolean Whether to show the character panel (defaults to true)
function ConfigData:GetShowCharacterPanel()
    local db = MrMythicalGearCheckDB or {}
    if db.SHOW_CHARACTER_PANEL == nil then
        local default = getDefaults().SHOW_CHARACTER_PANEL
        return default == nil and true or default
    end
    return db.SHOW_CHARACTER_PANEL
end

--- Gets whether the character panel should only display detected issues
--- @return boolean Whether to show issue-only output on the character panel (defaults to false)
function ConfigData:GetShowCharacterPanelIssuesOnly()
    local db = MrMythicalGearCheckDB or {}
    if db.SHOW_CHARACTER_PANEL_ISSUES_ONLY == nil then
        local default = getDefaults().SHOW_CHARACTER_PANEL_ISSUES_ONLY
        return default == nil and false or default
    end
    return db.SHOW_CHARACTER_PANEL_ISSUES_ONLY
end

--- Gets the low durability threshold percentage
--- @return number Percentage below which durability is considered low (defaults to 50)
function ConfigData:GetLowDurabilityThreshold()
    local db = MrMythicalGearCheckDB or {}
    return db.LOW_DURABILITY_THRESHOLD or getDefaults().LOW_DURABILITY_THRESHOLD or 50
end

--- Average equipped item-level gate. 0 disables the check.
--- @return number
function ConfigData:GetMinAvgItemLevel()
    local db = MrMythicalGearCheckDB or {}
    return db.MIN_AVG_ITEM_LEVEL or getDefaults().MIN_AVG_ITEM_LEVEL or 0
end

--- Per-piece equipped item-level gate. 0 disables the check.
--- @return number
function ConfigData:GetMinEquippedItemLevel()
    local db = MrMythicalGearCheckDB or {}
    return db.MIN_EQUIPPED_ITEM_LEVEL or getDefaults().MIN_EQUIPPED_ITEM_LEVEL or 0
end

--- Minimum Unique-Equipped: Embellished pieces required. 0 disables the check.
--- @return number
function ConfigData:GetMinEmbellishments()
    local db = MrMythicalGearCheckDB or {}
    return db.MIN_EMBELLISHMENTS or getDefaults().MIN_EMBELLISHMENTS or 0
end

--- Whether to warn when an enchant or gem primary stat does not match the spec.
--- @return boolean
function ConfigData:GetSpecAwareHints()
    local db = MrMythicalGearCheckDB or {}
    if db.SPEC_AWARE_HINTS == nil then
        local default = getDefaults().SPEC_AWARE_HINTS
        return default == nil and true or default
    end
    return db.SPEC_AWARE_HINTS
end

-- Ensure global access
_G.MrMythicalGearCheck = MrMythicalGearCheck
