import type { QualityIssueRow } from '../api/types';

export type VehicleLookup = {
  key: string;
  label: string;
};

export function isLikelyVIN(value?: string) {
  return /^[A-HJ-NPR-Z0-9]{17}$/i.test(value?.trim() ?? '');
}

export function qualityIssueVehicleLookup(row: QualityIssueRow): VehicleLookup {
  const vin = row.vin?.trim();
  if (vin && vin !== 'unknown') {
    return { key: vin, label: '车辆服务' };
  }
  const plate = row.plate?.trim();
  if (plate) {
    return { key: plate, label: '按车牌查车' };
  }
  const phone = row.phone?.trim();
  if (phone) {
    return { key: phone, label: '按手机号查车' };
  }
  return { key: '', label: '车辆服务' };
}
