// ===== FIRST MILE INTERFACES =====
export interface FirstMileRoute {
  id: number;
  routeType: string;
  type: string;
  facilityId: string;
  facilityName: string;
  totalStops: number;
  pendingStops: number;
  successfulStops: number;
  failedStops: number;
  withProblemStops: number;
  partiallyCollectedStops: number;
  stopsPercentage: number;
  estimatedPackages: number;
  collectedPackages: number;
  preparedPackages: number;
  status: string;
  vehicleName: string;
  vehicleType: string;
  vehicleTypeID: number;
  vehicleLicensePlate: string;
  driverId: number;
  driverName: string;
  carrierName: string;
  currentDay: boolean;
  isPartiallyCollected: boolean;
  performance: string;
  arrivedAtFacility: boolean;
  inboundStarted: boolean;
  wayToFacility: boolean;
  warnings: FirstMileWarning[];
  plannedStartTime: number;
  plannedFinishTime: number;
  initDate: number;
  finishDate: number;
  loadedVolume: number | null;
  firstStopDate: number;
  notesQuantity: number;
  stopsToReattribute: number;
}

export interface FirstMileWarning {
  warning: string;
  label: string;
}

// ===== LINE HAUL INTERFACES =====
export interface LineHaulRoute {
  carrier_id: number;
  carrier: string;
  code: string;
  date: string;
  departure_date: string;
  driver_id: number;
  drivers: LineHaulDriver[];
  expected_departure_date: string;
  finish_date: string;
  id: number;
  incidents: any[];
  rostering_assign_id: number;
  route_section: number;
  site_id: string;
  status: string;
  substatus: string;
  total_route: number;
  vehicle_id: number;
  vehicle_license_plate: string;
  vehicle_type: string;
  vehicles: LineHaulVehicle[];
  route: number;
  general_status: string;
  general_substatus: string;
  steps: LineHaulStep[];
  stops: LineHaulStop[];
}

export interface LineHaulDriver {
  id: number;
  sequence: number;
  name: string;
}

export interface LineHaulVehicle {
  id: number;
  sequence: number;
  license_plate: string;
  is_traction: boolean;
}

export interface LineHaulStep {
  route_id: number;
  sequence: number;
  status: string;
  substatus: string;
  origin: LineHaulLocation;
  destination: LineHaulLocation;
}

export interface LineHaulLocation {
  stop_id: number;
  status: string;
  type: string;
  facility: string;
  facility_id: string;
  init_date?: string;
  finish_date?: string;
  expected_init_date: string;
  expected_finish_date: string;
  latitude: number;
  longitude: number;
  pickup?: LineHaulCargo;
  dropoff?: LineHaulCargo;
  arrival_estimation?: LineHaulArrivalEstimation;
}

export interface LineHaulCargo {
  hu: number;
  shipment: number;
  total_items: number;
  accumulated_shipments: number;
}

export interface LineHaulArrivalEstimation {
  expected_arrival_date: string;
  computed_date: string;
  distance_text: string;
  distance_value: string;
}

export interface LineHaulStop {
  stop_id: number;
  status: string;
  type: string;
  facility: string;
  facility_id: string;
  sequence: number;
  current: boolean;
  total_handling_unit: number;
  total_packages: number;
  is_next_stop: boolean;
}

// ===== LAST MILE INTERFACES =====
export interface LastMileRoute {
  id: string;
  cluster: string;
  status: string;
  substatus: string;
  type: string;
  initDate: number;
  finalDate: number;
  driver: LastMileDriver;
  carrierId: string;
  carrier: string;
  addressTypes: string[];
  hasBusinessAddress: boolean;
  hasResidentialAddress: boolean;
  hasNotTaggedAddress: boolean;
  plannedRoute: LastMilePlannedRoute;
  vehicle: LastMileVehicle;
  dateFirstMovement: number;
  hasHelper: boolean;
  hasPlaces: number;
  hasBulky: boolean;
  hasPickup: boolean;
  hasBags: boolean;
  deliveryType: string;
  facilityId: string;
  facilityType: string | null;
  timezone: string;
  initHour: string;
  counters: LastMileCounters;
  hasShipmentsNotDelivered: boolean;
  claims: any[];
  incidentTypes: any[];
  hasAmbulance: boolean;
  claimsFilter: number;
  outRangeDeliveryFilter: number;
  failedDeliveryIndex: LastMileFailedDeliveryIndex;
  flags: LastMileFlags;
  routePerformanceScore: string;
  timingData: LastMileTimingData;
  shipmentData: LastMileShipmentData;
  tocTotalCases: number;
  isLineHaul: boolean;
  notesQuantity: number;
}

export interface LastMileDriver {
  driverName: string;
  driverClaims: number;
  contactRate: string;
  loyalty: LastMileDriverLoyalty;
}

export interface LastMileDriverLoyalty {
  name: string;
  stats: string[];
}

export interface LastMilePlannedRoute {
  duration: number;
  progressPercent: string;
  distance: number;
  cycleName: string;
}

export interface LastMileVehicle {
  description: string;
  license: string;
}

export interface LastMileCounters {
  total: number;
  delivered: number;
  notDelivered: number;
  pending: number;
  fromRoutes: number;
  toRoutes: number;
  totalBags: number;
  residential: number;
  business: number;
}

export interface LastMileFailedDeliveryIndex {
  percent: string;
  shouldDisplayBadge: boolean;
}

export interface LastMileFlags {
  claimsCount: number;
  failedDeliveryIndex: LastMileFailedDeliveryIndex;
  hasAmbulance: boolean;
  hasInitialDelay: boolean;
  outRangeDelivery: LastMileOutRangeDelivery;
}

export interface LastMileOutRangeDelivery {
  delivered: number;
  notDelivered: number;
}

export interface LastMileTimingData {
  orh: number;
  ozh: number;
  stemOut: number;
  stemIn: number;
  inactivity: LastMileInactivity;
}

export interface LastMileInactivity {
  inactivityValue: number;
  inactivityAlert: boolean;
}

export interface LastMileShipmentData {
  spr: number;
  delivered: number;
  failedDeliveries: number;
}

// ===== UNION TYPE FOR ALL ROUTE TYPES =====
export type MercadoLiveRouteRaw = FirstMileRoute | LineHaulRoute | LastMileRoute; 