/** Vehicle-like object with minimal fields for display purposes */
export interface VehicleLike {
  year?: number | null;
  make?: string | null;
  model?: string | null;
  trimLevel?: string | null;
  nickname?: string | null;
  vin?: string | null;
  id?: string | null;
}

/** Primary display name with fallback chain: nickname -> year/make/model -> VIN -> ID */
export const getVehicleLabel = (vehicle: VehicleLike | undefined): string => {
  if (!vehicle) return 'Unknown Vehicle';
  if (vehicle.nickname?.trim()) return vehicle.nickname.trim();
  const parts = [vehicle.year, vehicle.make, vehicle.model, vehicle.trimLevel].filter(Boolean);
  if (parts.length > 0) return parts.join(' ');
  if (vehicle.vin) return vehicle.vin;
  return vehicle.id ? `${vehicle.id.substring(0, 8)}...` : 'Unknown Vehicle';
};

/** Subtitle line: "Year Make Model" with null safety. Returns empty string if insufficient data. */
export const getVehicleSubtitle = (vehicle: VehicleLike | undefined): string => {
  if (!vehicle) return '';
  const parts = [vehicle.year?.toString(), vehicle.make, vehicle.model].filter(Boolean);
  return parts.length >= 2 ? parts.join(' ') : '';
};
