\set ON_ERROR_STOP on
-- Rio strategy-context companion postflight row-level readback.

select
  (select count(*) from public.strategy_nodes where id in (select id from (values
    ('4f3e3d77-50fa-520a-8c8b-5a4269d94a9b'::uuid),
    ('063528a6-a07c-5c14-abdf-dc12a0b10fcf'::uuid)
  ) as v(id))) as generated_strategy_node_rows,
  (select count(*) from public.strategy_node_anchors where id in (select id from (values
    ('3a0e2228-a74f-5971-b467-fb527ccdfb37'::uuid),
    ('3f7a9f84-eb2e-5d94-9ca4-afc3bad47f96'::uuid),
    ('d18eaa71-d458-53cc-baac-e5306a1779e2'::uuid),
    ('33d9eb08-c9c2-5e2d-a9a7-3d7f1b5f0f0c'::uuid),
    ('3b2a8908-120d-59a5-bbd5-d2711a123aa3'::uuid)
  ) as v(id))) as generated_strategy_anchor_rows;


select id::text,
       agent_id::text,
       node_type,
       title,
       rank,
       status,
       source_ref,
       metadata::text
from public.strategy_nodes
where id in (select id from (values
    ('4f3e3d77-50fa-520a-8c8b-5a4269d94a9b'::uuid),
    ('063528a6-a07c-5c14-abdf-dc12a0b10fcf'::uuid)
  ) as v(id))
order by rank, title;

select id::text,
       from_node_id::text,
       anchor_role,
       to_node_id::text,
       to_shared_root_id::text,
       claim_id::text,
       weight,
       left(note, 260) as note
from public.strategy_node_anchors
where id in (select id from (values
    ('3a0e2228-a74f-5971-b467-fb527ccdfb37'::uuid),
    ('3f7a9f84-eb2e-5d94-9ca4-afc3bad47f96'::uuid),
    ('d18eaa71-d458-53cc-baac-e5306a1779e2'::uuid),
    ('33d9eb08-c9c2-5e2d-a9a7-3d7f1b5f0f0c'::uuid),
    ('3b2a8908-120d-59a5-bbd5-d2711a123aa3'::uuid)
  ) as v(id))
order by from_node_id, anchor_role, id;

select id::text, status, left(text, 220) as text
from public.claims
where id in (select id from (values
    ('004195cc-ab62-526c-90fb-51cb0f826ec0'::uuid),
    ('67003e10-e1ee-5905-8b51-1b0cb263ec11'::uuid),
    ('e6ce4e36-15d2-53bc-8b74-dda0efc095c1'::uuid)
  ) as v(id))
order by id;

select id::text, title, left(body, 220) as body
from public.shared_root
where id = '6248818e-fe16-4d3b-8008-ef9752b80632'::uuid;
