local name, ns = ...
ns.PLAYER_LOGIN = false

ns.AutoScrapGlobalDefaultConfig = {
    boxList = {},
    lastWowTokenPrice = 0,
    WowTokenPriceThreshold = 10000,
    WowTokenListenerGroupInstance = false,
    WowTokenFrame = {
        startPoint = "TOPLEFT" ,
        relativePoint = "TOPLEFT",
        xOfs =300,
        yOfs =-200,
    },
    WowTokenInCombinedBags = true,
    WowTokenPriceWindowEnabled = true,
}

ns.AutoScrapCharDefaultConfig = {
    cantidad = 1000,
    TSM_mercado = "dbregionmarketavg",
    usar2Mercados = false,
    venderAnillos = false,
    venderGrises = false,
    venderBlancos = false,
    iLevel = 80,
    protectedIlevel = true,
    autoscrapOn = false,
    sliderMax = 5000,
    noVenderList = {},
    sellRatio = 0.21,
    protectedRatio = false,
    protectSouldBinds = true,
    protectedConsumables = true,
    protectedRecipes = false,
    protectedCooking= true,
    protectedLeather= true,
    protectedCloths= true,
    protectedHerbs= true,
    protectedMining= true,
    protectedBoxes = true,
    protectedJewelry = true,
    protectedInscription = true,
    protectedAdvancedOptions = false,
    ringsGold = 1000000,
    ringsiLevel = 80,
    ringsRate = 1,
    whitesGold = 1000000,
    whitesiLevel = 80,
    whitesRate = 1,
    graysGold = 1000000,
    blizzardDefaultJunk = true,
    graysiLevel = 80,
    graysRate = 1,
    destinatario="",
    autoLoot = true,
    OutterFrame = {
        startPoint = "CENTER" , --TOPRIGHT
        relativePoint = "CENTER", --TOPRIGHT
        xOfs =0, -- (-35)
        yOfs =0, -- (-230)
    },
    CombatFrame = {
        startPoint = "CENTER" , --TOPRIGHT
        relativePoint = "CENTER", --TOPRIGHT
        xOfs =0, -- (-35)
        yOfs =0, -- (-230)
    },
    TimerFrame = {
        startPoint = "CENTER" ,
        relativePoint = "CENTER",
        xOfs =0,
        yOfs =0,
    },
    AutoLoot = true,
    debug = false,
    ratioData = {
        [1] = {gold=400,rate=0.08},
        [2] = {gold=800,rate=0.06},
        [3] = {gold=1000,rate=0.05},
        [4] = {gold=2000,rate=0.04},
        [5] = {gold=nil,rate=0.02}
    },
    blackList = {},
    autoSell = true,
    autoRepair = true,
    mailOptLockedBox = false,
    mailOptLockedBoxName = "",
    mailOptInventory = false,
    mailOptInventoryName = "",
    mailOptMoney = false,
    mailOptMoneyName = "",
    combatStatisticsShowAtStart = false,
    combatLocked=false,
    miniBagIcons = {
        [2] = 86547,
        [3] = 52326,
    },
    partyDirection = "horizontal",
    ErrorsFrameMoved = false,
    lastTimerconfig ={
        DBMTimer = true,
        countDownTimer = false,
        killTimer = 90,
        enableBreak = true,
        breakTimer = 75,
        autoSell = 78,
        maxRounds = 5,
        sellTimer = 105,
    },
    timerConfigSlots ={
        [1] = {
            name = "SkyShard",
            DBMTimer = false,
            countDownTimer = true,
            killTimer = 1500,
            enableBreak = false,
            breakTimer = 120,
            autoSell = 100,
            maxRounds = 20,
            sellTimer = 120,
        },
        [2]= {
            name = "Volatile Water",
            DBMTimer = true,
            countDownTimer = false,
            killTimer = 90,
            enableBreak = true,
            breakTimer = 69,
            autoSell = 78,
            maxRounds = 5,
            sellTimer = 99,
        },
        [3]= {
            name = "Volatile Fire",
            DBMTimer = true,
            countDownTimer = false,
            killTimer = 90,
            enableBreak = true,
            breakTimer = 64,
            autoSell = 82,
            maxRounds = 6,
            sellTimer = 94,
        },
        [4]= {
            name = "Primal Fire",
            DBMTimer = true,
            countDownTimer = false,
            killTimer = 90,
            enableBreak = true,
            breakTimer = 67,
            autoSell = 80,
            maxRounds = 6,
            sellTimer = 97,
        },
        [5]= {
            name = "Primal Mana",
            DBMTimer = true,
            countDownTimer = false,
            killTimer = 100,
            enableBreak = true,
            breakTimer = 49,
            autoSell = 80,
            maxRounds = 6,
            sellTimer = 79,
        }
    },
    warbandGoldCheckBox = false,
    warbandGoldMinGold = 10000000,
    warbandRefillMinGold = false,-- continue
}

AutoScrap_CharSettings = AutoScrap_CharSettings or ns.AutoScrapCharDefaultConfig -- inicialización prematura
AutoScrap_GlobalSettings = AutoScrap_GlobalSettings or ns.AutoScrapGlobalDefaultConfig
-- tener en cuenta que la variable global no se carga con el script, si no después de un tiempo y hay que esperar el evento.
-- la primera vez aunque la variable sea nil también se lanza el evento.

ns.variablesCargadas= function (...)
    if name == ... then
        if AutoScrap_CharSettings == nil then
            AutoScrap_CharSettings = ns.AutoScrapCharDefaultConfig
        else
            for k, v in pairs(ns.AutoScrapCharDefaultConfig) do
                if AutoScrap_CharSettings[k] == nil then
                    AutoScrap_CharSettings[k] = v
                end
            end
        end
        if AutoScrap_GlobalSettings == nil then
            AutoScrap_GlobalSettings = ns.AutoScrapGlobalDefaultConfig
        else
            for k, v in pairs(ns.AutoScrapGlobalDefaultConfig) do
                if AutoScrap_GlobalSettings[k] == nil then
                    AutoScrap_GlobalSettings[k] = v
                end
            end
        end

        ns.changeItemClass("Consumables",not AutoScrap_CharSettings.protectedConsumables)
        ns.changeItemClass("Recipes",not AutoScrap_CharSettings.protectedRecipes)
        ns.changeItemClass("Cooking",not AutoScrap_CharSettings.protectedCooking)
        ns.changeItemClass("Leather",not AutoScrap_CharSettings.protectedLeather)
        ns.changeItemClass("Cloths",not AutoScrap_CharSettings.protectedCloths)
        ns.changeItemClass("Herbs",not AutoScrap_CharSettings.protectedHerbs)
        ns.changeItemClass("Mining",not AutoScrap_CharSettings.protectedMining)
        ns.changeItemClass("Jewelry",not AutoScrap_CharSettings.protectedJewelry)
        ns.changeItemClass("Inscription",not AutoScrap_CharSettings.protectedInscription)
        ns.newChanges = true
        ns.setRatioData()
        ns.setAdvOptions(AutoScrap_CharSettings.protectedAdvancedOptions)
        ns.updateUI()
        ns.AddOnValueChangedLater()
        ns.AddDestinatario(AutoScrap_CharSettings.destinatario)
        ns.setMailOpt(AutoScrap_CharSettings.mailOptLockedBox,AutoScrap_CharSettings.mailOptInventory,AutoScrap_CharSettings.mailOptMoney,AutoScrap_CharSettings.mailOptLockedBoxName,AutoScrap_CharSettings.mailOptInventoryName,AutoScrap_CharSettings.mailOptMoneyName)
        ns.setOFPosition()
        ns.setCombatOFPosition()
        ns.setCombatLocked(AutoScrap_CharSettings.combatLocked)
        ns.showDebug(AutoScrap_CharSettings.debug)
        if AutoScrap_CharSettings.combatStatisticsShowAtStart and not ns.isCombatShown()then
            ns.combatToggle()
        end
        ns.moveErrorsFrame()
        ns.setTimerFramePosition()
        ns.timerADVOoptionesUpdateList()
        ns.actualizarCheckBoxGoldWarband()
        ns.runWowTokenListener()
        --las posiciones de una ventana ahora son guardadas por el juego como variable de char
        --entonces si quieres tener en todos los jugadores guardado la misma posición de la notificación
        --al cambiar de char se pondría primero la global, después de esta línea la última posición del propio char que puede ser otra
        --entonces hay que cambiarla un frame después.
        C_Timer.After(0,ns.setWowTokenPanelPosition)
        ns.wowTokenConfigUpdateUI()
    end
end


