do $$
declare
  v_admin uuid := 'eeb4190f-1e7f-47b6-9d92-62193646f755';
  v_cust uuid; v_room uuid; v_svc uuid; v_booking uuid; v_invoice uuid;
  v_payment uuid; v_claim uuid; v_cat uuid; v_expacct uuid; v_bank uuid; v_cash uuid;
begin
  perform set_config('role', 'authenticated', true);
  perform set_config('request.jwt.claims', json_build_object('sub', v_admin, 'role', 'authenticated')::text, true);

  select id into v_cust from public.customers where customer_code = 'CUS-1001';
  select id into v_room from public.rooms where name = 'Studio A - Main Floor';
  select id into v_svc from public.services where code = 'SVC-HOURLY';
  select c.id, c.account_id into v_cat, v_expacct from public.expense_categories c where c.name = 'Props, Sets & Consumables';
  select id into v_bank from public.accounts where code = '1110';
  select id into v_cash from public.accounts where code = '1010';

  insert into public.bookings (booking_number, customer_id, room_id, service_id, booking_date, start_time, end_time,
                              price, discount, tax, total, status, notes)
  values (public.next_number('booking'), v_cust, v_room, v_svc, current_date, '10:00', '14:00',
          10000, 0, 0, 10000, 'booked', 'Rupali Weddings - 4 hour bridal shoot, Studio A')
  returning id into v_booking;

  perform public.submit_booking_for_approval(v_booking, 'Confirmed with client, 50% advance agreed');
  perform public.approve_booking(v_booking, 'Approved by studio manager', true);

  v_invoice := public.create_invoice_from_booking(v_booking);
  perform public.post_invoice(v_invoice);

  v_payment := public.record_customer_payment(
    v_cust, current_date, 5000, v_bank, 'bank', 'BKTRX-778211', '50% advance for bridal shoot',
    json_build_array(json_build_object('invoice_id', v_invoice, 'amount', 5000))::jsonb);

  v_claim := public.submit_expense_claim(current_date, v_expacct, v_cash, 1800, v_cat, null,
    'cash', 'MEMO-3391', 'Floral props and backdrop for Rupali Weddings shoot', null);
  perform public.approve_expense_claim(v_claim, 'Receipt verified', true);

  perform set_config('role', 'postgres', true);
  perform set_config('request.jwt.claims', '', true);
end $$;