-- Schema für eldov.win
-- Singleton-Modell: `profile` hat immer genau eine Zeile (id=1).
-- `projects` wird per `slug` adressiert und vom Admin gecrud'd.

PRAGMA journal_mode = WAL;
PRAGMA foreign_keys = ON;

CREATE TABLE IF NOT EXISTS profile (
  id          INTEGER PRIMARY KEY CHECK (id = 1),
  handle      TEXT NOT NULL,
  real_name   TEXT NOT NULL,
  role        TEXT NOT NULL,
  location    TEXT NOT NULL,
  bio_de      TEXT NOT NULL,
  bio_en      TEXT NOT NULL,
  facts_de    TEXT NOT NULL DEFAULT '[]',  -- JSON array<string>
  facts_en    TEXT NOT NULL DEFAULT '[]',
  links_json  TEXT NOT NULL DEFAULT '[]',  -- JSON array<{label, href, kind}>
  updated_at  TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS projects (
  slug         TEXT PRIMARY KEY,
  number       TEXT NOT NULL,
  status       TEXT NOT NULL,
  category     TEXT NOT NULL,
  stack        TEXT NOT NULL,
  href         TEXT,
  featured     INTEGER NOT NULL DEFAULT 0,
  summary_de   TEXT NOT NULL,
  summary_en   TEXT NOT NULL,
  body_de      TEXT NOT NULL,
  body_en      TEXT NOT NULL,
  stance_de    TEXT NOT NULL DEFAULT '',
  stance_en    TEXT NOT NULL DEFAULT '',
  sort_index   INTEGER NOT NULL DEFAULT 0,
  created_at   TEXT NOT NULL DEFAULT (datetime('now')),
  updated_at   TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE INDEX IF NOT EXISTS idx_projects_featured ON projects(featured);
CREATE INDEX IF NOT EXISTS idx_projects_sort ON projects(sort_index);

CREATE TABLE IF NOT EXISTS sessions (
  -- Wird derzeit nicht aktiv genutzt, da HMAC-Token selbst-validierend ist.
  -- Platzhalter für zukünftiges Server-seitiges Session-Tracking / Forced Logout.
  id          TEXT PRIMARY KEY,
  created_at  TEXT NOT NULL DEFAULT (datetime('now')),
  expires_at  TEXT NOT NULL,
  meta        TEXT NOT NULL DEFAULT '{}'
);
