GuildHelper = GuildHelper or {}

local addon = GuildHelper

local function deepCopy(value)
    if type(value) ~= "table" then
        return value
    end

    local copy = {}

    for key, nestedValue in pairs(value) do
        copy[key] = deepCopy(nestedValue)
    end

    return copy
end

addon.Schema = addon.Schema or {}

addon.Schema.defaults = {
    schemaVersion = 3,
    profile = {
        combat = {
            pauseDuringCombat = true,
        },
        debug = false,
        perf = {
            enabled = false,
            sampleLimit = 80,
            thresholdMs = 8,
        },
        features = {
            bis = true,
            groups = true,
            mythics = true,
            raidbingo = true,
        },
        gratsU = {
            achievementMessages = {},
            settings = {
                achievementCooldownSeconds = 120,
                antiSpamSeconds = 300,
                enableAchievement = true,
                enableWelcome = true,
                ignoreSelf = true,
                minOfflineSeconds = 120,
                welcomeDelaySeconds = 20,
            },
            stats = {
                achievementSent = 0,
                lastSentAt = 0,
                welcomeSent = 0,
            },
            welcomeMessages = {},
        },
        toonCelebrations = {
            birthdayMessages = {},
            birthdayUpcomingMessages = {},
            birthdayTodayMessages = {},
            birthdayRecentMessages = {},
            anniversaryMonthMessages = {},
            anniversaryMonthUpcomingMessages = {},
            anniversaryMonthTodayMessages = {},
            anniversaryMonthRecentMessages = {},
            anniversarySixMonthMessages = {},
            anniversarySixMonthUpcomingMessages = {},
            anniversarySixMonthTodayMessages = {},
            anniversarySixMonthRecentMessages = {},
            anniversaryYearMessages = {},
            anniversaryYearUpcomingMessages = {},
            anniversaryYearTodayMessages = {},
            anniversaryYearRecentMessages = {},
            history = {},
            ignoredHistory = {},
            settings = {
                enableAnniversary = true,
                enableBirthday = true,
                lookaheadDays = 14,
                lookbackDays = 7,
            },
            stats = {
                anniversaryMonthSent = 0,
                anniversarySixMonthSent = 0,
                anniversaryYearSent = 0,
                birthdaySent = 0,
                lastSentAt = 0,
            },
        },
        myCharacters = {},
        recruiter = {
            blacklist = {},
            pending = {},
            recentContacts = {},
            settings = {
                batchSize = 5,
                currentZoneOnly = false,
                highLevel = 80,
                lowLevel = 10,
                primaryMessage = "",
                querySuffix = "",
                repeatInviteCooldownDays = 30,
                usePrimaryWhisper = false,
            },
        },
        bis = {
            filters = {
                collectionSort = "default",
                ownership = "all",
                sourceType = "all",
            },
            records = {},
            seasonId = "current",
            selectedSlotKey = "head",
            selectedToonId = nil,
        },
        mythics = {
            activePane = "toons",
            overlay = {
                enabled = true,
                locked = false,
                point = "TOP",
                relativePoint = "TOP",
                x = 0,
                y = -130,
            },
            planner = {
                selectedDungeonId = nil,
                targetKeyLevel = 10,
            },
            seasonId = "current",
            selectedToonId = nil,
            showUnratedAlts = false,
        },
        raidBingo = {
            card = {
                locked = false,
                numbers = {},
                processed = {},
                rolledNumbers = {},
                selectedIndices = {},
                sessionId = nil,
                updatedAt = 0,
            },
            exportWindow = {
                height = 320,
                width = 420,
            },
            ui = {
                prizePool = "",
                selectedSession = "current",
            },
            session = {
                createdAt = 0,
                id = nil,
                leader = nil,
                memberSelections = {},
                prizePool = "",
                rolledNumbers = {},
                startedAt = 0,
                status = "idle",
            },
        },
        minimap = {
            angle = 220,
            hidden = false,
            radius = 108,
        },
        ui = {
            fonts = {
                paneBody = "default",
                paneTitle = "morpheus",
            },
            frame = {
                point = "CENTER",
                x = 0,
                y = 0,
                width = 1280,
                height = 820,
            },
            selectedView = "dashboard",
        },
        sync = {
            manualOnly = false,
            verbose = false,
        },
    },
    guild = {
        federation = {
            homeGuild = nil,
            linkedGuilds = {},
            permissions = {},
        },
        roster = {},
        content = {},
        groups = {},
        needs = {
            rules = {
                raid = {
                    tanks = 2,
                    healers = 4,
                    melee = 5,
                    ranged = 7,
                    dps = 12,
                },
                party = {
                    tanks = 1,
                    healers = 1,
                    melee = 1,
                    ranged = 2,
                    dps = 3,
                },
            },
            snapshots = {},
        },
        maintenance = {
            exclusions = {},
            familyBlocks = {},
            selectedMembers = {},
            selectedPromotionMembers = {},
            staleMembers = {},
            pendingDeletes = {},
            auditLog = {},
            auditMeta = {
                baselineGuild = "",
                baselineCapturedAt = 0,
                lastRosterCaptureCount = 0,
            },
            auditOfficerNoteSignatures = {},
            settings = {
                staleAfterDays = 30,
                purgeAfterDays = 90,
                kickScope = "all",
                kickLinkedAltsWithMain = false,
                promoteFromRank = "Initiate",
                promoteToRank = "Member",
                auditEnabled = true,
                auditLogJoins = true,
                auditLogLeaves = true,
                auditLogKicks = true,
                auditLogRanks = true,
                auditLogNotes = true,
                auditLogOfficerNotes = true,
                auditUseColors = true,
                auditTextColors = {
                    join = { 0.24, 0.84, 0.36, 1 },
                    leave = { 0.66, 0.66, 0.66, 1 },
                    kick = { 0.96, 0.28, 0.28, 1 },
                    rank = { 0.96, 0.84, 0.24, 1 },
                    note = { 0.76, 0.5, 0.92, 1 },
                    officerNote = { 0.14, 0.56, 0.22, 1 },
                },
                auditColorTheme = "classic",
                auditMaxRows = 500,
                auditRetentionDays = 90,
            },
        },
    },
    sync = {
        prefix = "GH3SYNC",
        lastSyncAt = nil,
        lastRosterSync = {},
        mythics = {},
        mytoons = {},
        rosterJournal = {
            byGuild = {},
            watermarks = {},
        },
        peers = {},
        conflicts = {},
        resolutions = {},
        tableMeta = {
            roster = { checksum = "", updatedAt = 0 },
            mytoons = { checksum = "", updatedAt = 0 },
            mythics = { checksum = "", updatedAt = 0 },
            content = { checksum = "", updatedAt = 0 },
            groups = { checksum = "", updatedAt = 0 },
            federation = { checksum = "", updatedAt = 0 },
        },
    },
}

function addon.Schema:CreateDefaults()
    return deepCopy(self.defaults)
end
