-- Seed data for the live /invoices/new cross-check test.
-- NOT a schema migration — this only inserts data, using the tables
-- created by 0011/0012/0013. Safe to delete afterward if you don't want
-- it lingering as real schedule/rate history for agent_042.

-- 1. Enable Special Holiday Pay and list the 3 holiday-pay-flagged dates
--    (fix 1 / fix 2 coverage — see notes below). Bonuses (Saturday / 6th
--    consecutive day) are already enabled by 0013's default and need no
--    change. Night differential is left OFF (default) — not one of the
--    5 requested cases, kept out to reduce moving parts.
update public.invoice_settings
set holiday_pay = '{"enabled":true,"rate":200,"standardHours":8,"dates":["2026-12-08","2026-12-09","2026-12-10"]}'::jsonb
where id = 1;

-- 2. A logged rate for the exact cutoff period being tested, so the
--    resolved rate comes from rate_history (fromLog: true) rather than
--    bare global settings — more realistic, and directly answers "what
--    was the rate for this period."
insert into public.rate_history (period, cut_label, rate, hourly_usd, note, saved_by)
values ('2026-12-C1', 'December 2026 Cut 1 (1st-15th)', 58, 6, 'Seed for live cross-check test', 'seed-script')
on conflict (period) do update set rate = excluded.rate, hourly_usd = excluded.hourly_usd;

-- 3. Schedule for agent_042, Dec 2-15 2026 (14 days). Dec 1 is
--    intentionally NOT seeded (it's technically part of the same ISO
--    week as Dec 2-6 and thus part of Cut 1's date range, but leaving it
--    unseeded just means it contributes 0 hours — a harmless gap, not a
--    broken window).
--
--    Layout:
--      Dec 2-7   REGULAR/SAT streak (6 consecutive working days)
--                -> Dec 5 is a real calendar Saturday (Saturday bonus)
--                -> Dec 7 is the 6th consecutive day (6th-day bonus)
--      Dec 8     plain OFF, flagged in holiday_pay.dates
--                -> tests the non-working-day holiday-pay branch
--      Dec 9     HOL_OFF, flagged in holiday_pay.dates
--                -> tests fix 2 (HOL_OFF exclusion): exactly one payment
--      Dec 10    HOL_WORK_LATE, flagged in holiday_pay.dates
--                -> tests fix 1 (HOL_WORK precedence): exactly one top-up
--      Dec 11    REGULAR (filler)
--      Dec 12    plain OFF, NOT flagged (deliberately 0 hours, so this
--                date's real-Saturday-ness doesn't create a second,
--                confusing Saturday-bonus day alongside Dec 5)
--      Dec 13-15 REGULAR (filler, rounds out the cut)
insert into public.schedule (shift_date, agent_id, shift_code) values
  ('2026-12-02', 'agent_042', 'REGULAR'),
  ('2026-12-03', 'agent_042', 'REGULAR'),
  ('2026-12-04', 'agent_042', 'REGULAR'),
  ('2026-12-05', 'agent_042', 'SAT'),
  ('2026-12-06', 'agent_042', 'REGULAR'),
  ('2026-12-07', 'agent_042', 'REGULAR'),
  ('2026-12-08', 'agent_042', 'OFF'),
  ('2026-12-09', 'agent_042', 'HOL_OFF'),
  ('2026-12-10', 'agent_042', 'HOL_WORK_LATE'),
  ('2026-12-11', 'agent_042', 'REGULAR'),
  ('2026-12-12', 'agent_042', 'OFF'),
  ('2026-12-13', 'agent_042', 'REGULAR'),
  ('2026-12-14', 'agent_042', 'REGULAR'),
  ('2026-12-15', 'agent_042', 'REGULAR')
on conflict (shift_date, agent_id) do update set shift_code = excluded.shift_code;
