-- ============================================================
-- HeavyHaul Agent — unit profile per trip (2026-09-04 driver feedback).
-- Nash: "we're creating a unit profile, a truck trailer profile for that
-- specific trip" — overall axle count ("5 Axel, 6 Axel, 7 Axel. That's very
-- important"), axle spacings and axle weights (pulled from the permits when
-- available), plus truck info and trailer info (unit number, VIN, make,
-- model, year). The driver can view and change it; every change is logged
-- to trip history so it stays transparent to everyone on the trip.
-- ============================================================

create table public.trip_units (
  id uuid primary key default gen_random_uuid(),
  trip_id uuid not null unique references public.trips (id) on delete cascade,
  axle_count integer check (axle_count between 1 and 30),
  axle_spacings_in jsonb, -- ordered list of inches between consecutive axles
  axle_weights_lbs jsonb, -- ordered list of lbs per axle
  truck_unit_number text,
  truck_vin text,
  truck_make text,
  truck_model text,
  truck_year integer,
  trailer_unit_number text,
  trailer_vin text,
  trailer_make text,
  trailer_model text,
  trailer_year integer,
  trailer_axle_count integer check (trailer_axle_count between 1 and 30),
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

alter table public.trip_units enable row level security;
