-- CV corpus schema: mirrors the YAML shapes under ../docs.
CREATE TABLE profile (
  id INTEGER PRIMARY KEY,
  full_name TEXT NOT NULL,
  email TEXT,
  phone TEXT,
  website TEXT,
  linkedin TEXT,
  github TEXT,
  twitter TEXT
);

CREATE TABLE summaries (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  role TEXT NOT NULL,
  summary TEXT NOT NULL
);

CREATE TABLE experience (
  slug TEXT PRIMARY KEY,
  title TEXT NOT NULL,
  company TEXT NOT NULL,
  start_date TEXT NOT NULL,
  end_date TEXT,
  location TEXT,
  profile_heading TEXT
);

CREATE TABLE projects (
  slug TEXT PRIMARY KEY,
  title TEXT NOT NULL,
  start_date TEXT,
  end_date TEXT,
  url TEXT,
  -- slug of the experience (or 'education') this project belongs to
  associated_with TEXT
);

-- One row per "- " bullet from the YAML description block scalars.
CREATE TABLE bullets (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  parent_type TEXT NOT NULL CHECK (parent_type IN ('experience', 'project')),
  parent_slug TEXT NOT NULL,
  position INTEGER NOT NULL,
  text TEXT NOT NULL
);
CREATE INDEX idx_bullets_parent ON bullets (parent_type, parent_slug);

-- Canonical skill names attached to experience/project/education entries.
CREATE TABLE item_skills (
  parent_type TEXT NOT NULL CHECK (parent_type IN ('experience', 'project', 'education')),
  parent_slug TEXT NOT NULL,
  skill TEXT NOT NULL
);
CREATE INDEX idx_item_skills_skill ON item_skills (skill);

-- The skill inventory (docs/skills/*): languages carry a tier,
-- frameworks carry a group parsed from the YAML comment headers.
CREATE TABLE skills (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  category TEXT NOT NULL CHECK (category IN ('language', 'framework', 'methodology')),
  grp TEXT,
  tier TEXT,
  position INTEGER NOT NULL
);

CREATE TABLE education (
  id INTEGER PRIMARY KEY,
  school TEXT NOT NULL,
  degree TEXT,
  field TEXT,
  start_date TEXT,
  end_date TEXT,
  activities TEXT
);

CREATE TABLE honors (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  title TEXT NOT NULL,
  date TEXT,
  institution TEXT
);

CREATE TABLE organizations (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  url TEXT,
  title TEXT
);
