-- User asked: Kenn, Bjorn, Berry (and Edwin) should all be able to
-- approve time off, with a visible "stamp" showing who decided each
-- request. Checked current state before writing anything: Berry and
-- Kenn already have 'time_off' can_write=true (migration 0040), Edwin
-- already has it via is_admin -- only Bjorn was missing. Same user_id
-- already confirmed correct in migration 0037 (Bjorn's invoicing
-- view-only grant): '2a60b0c9-c88a-4e08-b10f-6cf50f12ce63'.
--
-- The "stamp" itself needs NO schema change -- time_off_requests
-- already has decided_by/decided_at (migration 0040), and
-- /api/time-off/decide already populates both on every approve/deny/
-- revoke. The gap was purely that the UI never displayed them
-- anywhere; that's a code-only fix (src/app/settings/time-off/page.js,
-- src/app/time-off/page.js), not a migration.

insert into public.permissions (user_id, feature_key, can_view, can_write) values
  ('2a60b0c9-c88a-4e08-b10f-6cf50f12ce63', 'time_off', true, true) -- Bjorn
on conflict (user_id, feature_key) do update
  set can_view = true, can_write = true;

-- ============================================================
-- Self-verification guard
-- ============================================================

do $migration_guard$
declare
  bjorn_perm_count int;
begin
  select count(*) into bjorn_perm_count from public.permissions
    where user_id = '2a60b0c9-c88a-4e08-b10f-6cf50f12ce63' and feature_key = 'time_off' and can_view = true and can_write = true;
  if bjorn_perm_count <> 1 then
    raise exception 'Aborting 0046: expected Bjorn to have exactly 1 time_off permissions row with view+write, found %', bjorn_perm_count;
  end if;
end $migration_guard$;
