-- Migration 003: Add system configuration table
--
-- Stores organization-level configuration including:
-- - Organization name
-- - Domain type (government/enterprise/education)
-- - Initialization state

------------------------------------------------------------------------
-- System configuration table
------------------------------------------------------------------------

CREATE TABLE IF NOT EXISTS system_config (
    id                        INTEGER PRIMARY KEY CHECK (id = 1),
    organization_name         TEXT    NOT NULL DEFAULT 'My Organization',
    domain_type               TEXT    NOT NULL DEFAULT 'enterprise'
                                CHECK(domain_type IN ('government', 'enterprise', 'education')),
    initialized               INTEGER NOT NULL DEFAULT 0,
    init_completed_at         INTEGER,
    created_at                INTEGER NOT NULL,
    updated_at                INTEGER NOT NULL
);

-- Seed default configuration row
INSERT OR IGNORE INTO system_config (id, created_at, updated_at)
VALUES (1, unixepoch('now', 'subsec') * 1000, unixepoch('now', 'subsec') * 1000);

------------------------------------------------------------------------
-- Extend system_settings for additional preferences
------------------------------------------------------------------------

ALTER TABLE system_settings ADD COLUMN theme_mode TEXT NOT NULL DEFAULT 'light'
    CHECK(theme_mode IN ('light', 'dark', 'auto'));

------------------------------------------------------------------------
-- End of migration
------------------------------------------------------------------------