export type VehicleSchemaCar = {
  make: string;
  model: string;
  year: number;
  price: number;
  mileage: number;
  fuel: string;
  transmission: string;
  bodyType: string;
  color: string;
  sold?: boolean;
  vin?: string;
};

type VehicleJsonLdInput = {
  car: VehicleSchemaCar;
  canonicalUrl: string;
  imageUrl: string;
};

export const vehicleJsonLd = ({ car, canonicalUrl, imageUrl }: VehicleJsonLdInput) => ({
  '@context': 'https://schema.org',
  '@type': 'Vehicle',
  name: `${car.year} ${car.make} ${car.model}`,
  brand: {
    '@type': 'Brand',
    name: car.make,
  },
  model: car.model,
  vehicleModelDate: car.year,
  mileageFromOdometer: {
    '@type': 'QuantitativeValue',
    value: car.mileage,
    unitCode: 'KMT',
  },
  fuelType: car.fuel,
  vehicleTransmission: car.transmission,
  bodyType: car.bodyType,
  color: car.color,
  ...(car.vin ? { vehicleIdentificationNumber: car.vin } : {}),
  image: imageUrl,
  url: canonicalUrl,
  offers: {
    '@type': 'Offer',
    price: car.price,
    priceCurrency: 'EUR',
    availability: car.sold ? 'https://schema.org/SoldOut' : 'https://schema.org/InStock',
    url: canonicalUrl,
  },
});
