-- Seed the Brentwood project. Safe to re-run: keyed on the project slug.

insert into projects (slug, name, staging_domain, live_domain)
values ('brentwood', 'Brentwood', 'dev.brentwood.example.com', 'brentwood.example.com')
on conflict (slug) do nothing;

with p as (select id from projects where slug = 'brentwood')
insert into pages (project_id, page_name, slug, status, signoff, position)
select p.id, v.page_name, v.slug, v.status, v.signoff, v.position
from p,
  (values
    ('Home',     '/',         'completed',        'approved',         0),
    ('About Us', '/about',    'revision pending', 'revision needed',  1),
    ('Services', '/services', 'finalizing',       'not ready',        2),
    ('Contact',  '/contact',  'open',             'not ready',        3)
  ) as v(page_name, slug, status, signoff, position)
where not exists (
  select 1 from pages x where x.project_id = p.id and x.page_name = v.page_name
);

-- A couple of text notes so the Notes column isn't empty on first load.
insert into notes (page_id, content)
select pg.id, 'Hero image is looking great. Approved by client on the last call.'
from pages pg join projects pr on pr.id = pg.project_id
where pr.slug = 'brentwood' and pg.page_name = 'Home'
  and not exists (select 1 from notes n where n.page_id = pg.id);

insert into notes (page_id, content)
select pg.id, 'Team bios need updating — the client sent new headshots that aren''t in yet.'
from pages pg join projects pr on pr.id = pg.project_id
where pr.slug = 'brentwood' and pg.page_name = 'About Us'
  and not exists (select 1 from notes n where n.page_id = pg.id);
