-- Fixes column types on commslayer_reports discovered by testing the
-- real live API response directly (not assumed from Code.js, which
-- treated these as whole-number counts): first_response_secs,
-- avg_response_secs, resolution_secs, ticket_handle_time_secs, and
-- one_touch_tickets all come back fractional in real data (e.g.
-- avg_response_time: 427290.7, ticket_handle_time: 2025.5,
-- one_touch_tickets: 27.6) — an integer column would reject these
-- inserts outright. closed_tickets/tickets_replied/messages_sent/
-- messages_received are left as integer — every real sample seen so far
-- for those is a whole number.
--
-- This also resolves the one_touch_tickets ambiguity flagged in 0021:
-- real values (27.6, 8.3, 11.9, 100, 0) are clearly rate/percentage-like,
-- not a raw ticket count — Code.js's `a.one_touch_tickets || 0` treated
-- it as a plain count, but the legacy trend chart's 20%-target/100-max
-- treatment was the one that actually matched reality.

alter table public.commslayer_reports
  alter column first_response_secs      type numeric using first_response_secs::numeric,
  alter column avg_response_secs        type numeric using avg_response_secs::numeric,
  alter column resolution_secs          type numeric using resolution_secs::numeric,
  alter column ticket_handle_time_secs  type numeric using ticket_handle_time_secs::numeric,
  alter column one_touch_tickets        type numeric using one_touch_tickets::numeric;

alter table public.commslayer_reports
  alter column one_touch_tickets set default 0;
