PRAGMA foreign_keys = ON;

CREATE TABLE IF NOT EXISTS admin_events (
  id TEXT PRIMARY KEY,
  kind TEXT NOT NULL,
  subscriber_id TEXT,
  list_id TEXT,
  title TEXT,
  detail TEXT,
  entity_type TEXT,
  entity_id TEXT,
  metadata TEXT,
  created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
);

CREATE INDEX IF NOT EXISTS idx_admin_events_created ON admin_events(created_at);
CREATE INDEX IF NOT EXISTS idx_admin_events_kind ON admin_events(kind);
CREATE INDEX IF NOT EXISTS idx_admin_events_subscriber ON admin_events(subscriber_id);
CREATE INDEX IF NOT EXISTS idx_admin_events_list ON admin_events(list_id);
CREATE INDEX IF NOT EXISTS idx_admin_events_entity ON admin_events(entity_type, entity_id);

CREATE TABLE IF NOT EXISTS admin_settings (
  id TEXT PRIMARY KEY,
  notifications_enabled INTEGER NOT NULL DEFAULT 1,
  notification_types TEXT,
  created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
  updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
);
