export interface Vehicle {
  id: number;
  display_name: string;
  numberplate: string;
  vin: string | null;
  mark: string;
  model: string;
  motor_type: string;
  status: string;
  connection_status: {
    label: string;
    color: string;
  };
  has_device: boolean;
  odometer: number | null;
  company: { id: number; name: string } | null;
  site: { id: number; name: string } | null;
  provider: "OEM (LINKBYCAR)" | "OEM (STELLANTIS)" | "DEVICE (FLESPI)" | null;
  created_at: string;
}

/**
 * What the provider actually did. `not_registered` means LinkByCar had no
 * record of the VIN — the vehicle was never (or no longer) collected, and only
 * the local flags were stale. Both outcomes are successes.
 */
export type LinkbycarDisconnectOutcome = "disconnected" | "not_registered";

export interface LinkbycarDisconnectResult {
  vehicle_id: number;
  outcome: LinkbycarDisconnectOutcome;
}

/** Company-wide LinkByCar link state. `company.id` is a companies.id. */
export interface LinkbycarCompanySummary {
  company: { id: number; name: string };
  vehicles_total: number;
  connected: number;
  pending: number;
  eligible: number;
  not_connected: number;
  targets: {
    /** Vehicles the local status calls connected or pending — the normal target set. */
    linked: number;
    /** Every vehicle with a VIN — the catch-up target set. */
    with_vin: number;
  };
}

/** One vehicle LinkByCar still holds, as the provider reports it. */
export interface LinkbycarRegisteredVehicle {
  vehicle_id: number;
  numberplate: string;
  vin: string;
  archived: boolean;
  /** Our column: C / P / E / N. */
  local_status: string;
  /** The provider word: ENABLED, PENDING, ... */
  provider_status: string | null;
  provider_activity_status: string | null;
}

/**
 * Answer to "are they really disconnected?", read from LinkByCar rather than
 * from our own columns — which a bulk disconnect writes itself, so they agree
 * by construction and prove nothing.
 */
export interface LinkbycarCompanyVerification {
  company: { id: number; name: string };
  /** Company vehicles with a VIN that were cross-referenced. */
  checked: number;
  /** Size of the provider's whole listing, all companies included. */
  provider_total: number;
  still_registered_count: number;
  still_registered: LinkbycarRegisteredVehicle[];
  /** Drift the other way: we call them linked, the provider has no record. */
  linked_but_absent_count: number;
  clean: boolean;
}

export interface LinkbycarBulkDisconnectResult {
  queued: number;
  batches: number;
  include_all: boolean;
}

export interface VehicleProviderOption {
  value: "linkbycar" | "stellantis" | "flespi" | "none";
  label: string;
}

export interface VehicleStats {
  total: number;
  connected: number;
  not_connected: number;
  new_last_30_days: number;
}

export interface UpdateVehiclePayload {
  numberplate?: string;
  mark?: string;
  model?: string;
  motor_type?: string;
  site_id?: number | null;
  driver_id?: number | null;
}
