-- 001_init.sql — schema inicial de agents_dashboard.
-- Idempotente: usa IF NOT EXISTS. Nunca borrar ni modificar este archivo.
-- Aplica via embed.FS al arrancar la app (regla db_migrations.md).

CREATE TABLE IF NOT EXISTS connections (
    id               INTEGER PRIMARY KEY AUTOINCREMENT,
    name             TEXT    NOT NULL DEFAULT 'default',
    base_url         TEXT    NOT NULL,
    apikey_encrypted BLOB    NOT NULL,   -- DPAPI Windows / base64+xor Linux fallback
    last_used        INTEGER DEFAULT (strftime('%s', 'now'))
);

CREATE TABLE IF NOT EXISTS app_state (
    key   TEXT PRIMARY KEY,
    value TEXT
);

-- Semilla de app_state para valores por defecto
INSERT OR IGNORE INTO app_state (key, value) VALUES ('active_connection_id', '');
INSERT OR IGNORE INTO app_state (key, value) VALUES ('log_agent_id', '');
INSERT OR IGNORE INTO app_state (key, value) VALUES ('log_autoscroll', '1');
INSERT OR IGNORE INTO app_state (key, value) VALUES ('status_feed_open', '1');
