\set ON_ERROR_STOP on
-- Governance/concept companion postflight row-level readback.

select
  (select count(*) from public.concept_maps where id = 'f013126c-0937-5bc8-b021-9697e59057d0'::uuid) as generated_concept_map_rows,
  (select count(*) from public.claim_concept_map_links where id = 'af4ce1b9-db03-5bde-a21b-0e16ca0f48b8'::uuid) as generated_concept_link_rows,
  (select count(*) from public.claim_governance_gate_links where id in (select id from (values
    ('1f81e105-af5e-5db8-a7be-08cc6cc4e13a'::uuid),
    ('af04a87e-c1da-57e9-b11c-60d79daa5648'::uuid)
  ) as v(id))) as generated_governance_link_rows;


select id::text, key, title, status, source_ref, metadata::text
from public.concept_maps
where id = 'f013126c-0937-5bc8-b021-9697e59057d0'::uuid;

select id::text,
       claim_id::text,
       concept_map_id::text,
       relation,
       weight,
       left(rationale, 220) as rationale,
       source_ref
from public.claim_concept_map_links
where id = 'af4ce1b9-db03-5bde-a21b-0e16ca0f48b8'::uuid;

select id::text,
       claim_id::text,
       governance_gate_id::text,
       relation,
       weight,
       left(rationale, 220) as rationale,
       source_ref
from public.claim_governance_gate_links
where id in (select id from (values
    ('1f81e105-af5e-5db8-a7be-08cc6cc4e13a'::uuid),
    ('af04a87e-c1da-57e9-b11c-60d79daa5648'::uuid)
  ) as v(id))
order by governance_gate_id;
