local _, addon = ...

-- Prepare API object
addon.API = {}

addon.data = {};
addon.data.quest = {};
addon.data.item = {};
addon.data.speech = {}

-- Expose object as global for other addon integration
CzechQuestsAddon = {}
CzechQuestsAddon.data = addon.data

local function InitStore()
    -- Init Store
    CzechQuestsAddon_Store = CzechQuestsAddon_Store or {}
    CzechQuestsAddon_Store.config = CzechQuestsAddon_Store.config or {}

    -- General Settings
    CzechQuestsAddon_Store.config.DEBUG_MODE = CzechQuestsAddon_Store.config.DEBUG_MODE or false

    -- Quest Settings
    CzechQuestsAddon_Store.config.QUEST_ENABLED = CzechQuestsAddon_Store.config.QUEST_ENABLED or true
    CzechQuestsAddon_Store.config.QUEST_DARK_MODE = CzechQuestsAddon_Store.config.QUEST_DARK_MODE or false
    CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_SIZE = CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_SIZE or 18
    CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_SIZE = CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_SIZE or 14
    CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_NAME = CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_NAME or 'morpheus_cz.ttf'
    CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_NAME = CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_NAME or 'frizquadratatt_cz.ttf'
    CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA = CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA or 80
    CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING = CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING or true

    -- Speech Settings
    CzechQuestsAddon_Store.config.SPEECH_ENABLED = CzechQuestsAddon_Store.config.SPEECH_ENABLED or true
    CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE = CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE or 15
    CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME = CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME or 'frizquadratatt_cz.ttf'
    CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH = CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH or 320
    CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING = CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING or false
    CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION = CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION or { x = 0, y = 0}
end

-- Event handler frame
local frame = CreateFrame("Frame")
local function OnEvent(self, event, addonName, ...)
    if event == "ADDON_LOADED" and addonName == 'CzechQuests' then
        InitStore()
        addon.API.InitOptions()
        addon.API.InitQuests()
        addon.API.InitSpeeches()
        self:UnregisterEvent("ADDON_LOADED")
    end
end

-- Register the event
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", OnEvent)