-- Phase 3 — Projects, Steps, Ideas

CREATE TABLE ordinarthur_os.projects (
  id          UUID        PRIMARY KEY DEFAULT gen_random_uuid(),
  name        TEXT        NOT NULL,
  description TEXT,
  status      TEXT        NOT NULL DEFAULT 'active',
  created_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE ordinarthur_os.project_steps (
  id          UUID        PRIMARY KEY DEFAULT gen_random_uuid(),
  project_id  UUID        NOT NULL REFERENCES ordinarthur_os.projects(id) ON DELETE CASCADE,
  title       TEXT        NOT NULL,
  status      TEXT        NOT NULL DEFAULT 'backlog',
  position    REAL        NOT NULL DEFAULT 0,
  created_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE ordinarthur_os.project_ideas (
  id          UUID        PRIMARY KEY DEFAULT gen_random_uuid(),
  project_id  UUID        NOT NULL REFERENCES ordinarthur_os.projects(id) ON DELETE CASCADE,
  content     TEXT        NOT NULL,
  priority    SMALLINT,
  created_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX project_steps_project_id_idx ON ordinarthur_os.project_steps(project_id);
CREATE INDEX project_ideas_project_id_idx ON ordinarthur_os.project_ideas(project_id);
