create table if not exists agent_skills (
  id          uuid        primary key default gen_random_uuid(),
  name        text        not null,
  description text        not null default '',
  content     text        not null,
  tags        text[]      not null default '{}',
  created_at  timestamptz not null default now(),
  updated_at  timestamptz not null default now(),
  constraint agent_skills_name_unique unique (name)
);

create table if not exists agent_guardrails (
  id          uuid        primary key default gen_random_uuid(),
  name        text        not null,
  description text        not null default '',
  content     text        not null,
  severity    text        not null default 'medium' check (severity in ('low', 'medium', 'high', 'critical')),
  tags        text[]      not null default '{}',
  created_at  timestamptz not null default now(),
  updated_at  timestamptz not null default now(),
  constraint agent_guardrails_name_unique unique (name)
);

create table if not exists project_skills (
  project_id  uuid        not null references projects(guid) on delete cascade,
  skill_id    uuid        not null references agent_skills(id) on delete cascade,
  created_at  timestamptz not null default now(),
  primary key (project_id, skill_id)
);

create table if not exists project_guardrails (
  project_id    uuid        not null references projects(guid) on delete cascade,
  guardrail_id  uuid        not null references agent_guardrails(id) on delete cascade,
  created_at    timestamptz not null default now(),
  primary key (project_id, guardrail_id)
);

create index if not exists project_skills_project_id_idx on project_skills (project_id);
create index if not exists project_guardrails_project_id_idx on project_guardrails (project_id);
