-- Per-team_member billout rate + per-entry billout amount. Cost (what
-- Rian pays the worker) is unchanged. Billout is what Rian CHARGES the
-- client for that worker's hours, locked at entry creation time the
-- same way cost is (ADR #014).
--
-- Both columns are owner-only at the app layer. RLS on time_entries
-- and team_members is row-level, not column-level, so column-level
-- gating is enforced by the UI not the database. The values live
-- right next to cost on the same rows for simplicity.

alter table public.team_members
  add column if not exists billout_rate_usd numeric(10, 2);

comment on column public.team_members.billout_rate_usd is
  'Owner-only: USD per billout hour (i.e. per converted_duration_seconds / 3600) that the org owner charges the client for this team_member''s work. Used to compute time_entries.billout_amount_usd at entry-creation time. NULL = not set, no billout amount computed for entries pointing at this row.';

alter table public.time_entries
  add column if not exists billout_amount_usd numeric(12, 2);

comment on column public.time_entries.billout_amount_usd is
  'Owner-only: locked at entry creation. = converted_duration_seconds / 3600 × team_member.billout_rate_usd at time of write. NULL if the team_member had no billout_rate set then. Same lock-at-write semantic as billout_cost_usd (ADR #014).';
