/**
 * @ai-summary Type definitions for vehicles feature
 * @ai-context Core business types, no external dependencies
 */

// TCO cost interval types
export type CostInterval = 'monthly' | 'semi_annual' | 'annual';

export const PAYMENTS_PER_YEAR: Record<CostInterval, number> = {
  monthly: 12,
  semi_annual: 2,
  annual: 1,
} as const;

export interface Vehicle {
  id: string;
  userId: string;
  vin?: string;
  make?: string;
  model?: string;
  year?: number;
  engine?: string;
  transmission?: string;
  trimLevel?: string;
  driveType?: string;
  fuelType?: string;
  nickname?: string;
  color?: string;
  licensePlate?: string;
  odometerReading: number;
  isActive: boolean;
  deletedAt?: Date;
  createdAt: Date;
  updatedAt: Date;
  imageStorageBucket?: string;
  imageStorageKey?: string;
  imageFileName?: string;
  imageContentType?: string;
  imageFileSize?: number;
  // TCO fields
  purchasePrice?: number;
  purchaseDate?: string;
  insuranceCost?: number;
  insuranceInterval?: CostInterval;
  registrationCost?: number;
  registrationInterval?: CostInterval;
  tcoEnabled?: boolean;
}

export interface CreateVehicleRequest {
  vin?: string;
  year?: number;
  make?: string;
  model?: string;
  engine?: string;
  transmission?: string;
  trimLevel?: string;
  driveType?: string;
  fuelType?: string;
  nickname?: string;
  color?: string;
  licensePlate?: string;
  odometerReading?: number;
  // TCO fields
  purchasePrice?: number;
  purchaseDate?: string;
  insuranceCost?: number;
  insuranceInterval?: CostInterval;
  registrationCost?: number;
  registrationInterval?: CostInterval;
  tcoEnabled?: boolean;
}

export interface UpdateVehicleRequest {
  vin?: string;
  year?: number;
  make?: string;
  model?: string;
  engine?: string;
  transmission?: string;
  trimLevel?: string;
  driveType?: string;
  fuelType?: string;
  nickname?: string;
  color?: string;
  licensePlate?: string;
  odometerReading?: number;
  // TCO fields
  purchasePrice?: number;
  purchaseDate?: string;
  insuranceCost?: number;
  insuranceInterval?: CostInterval;
  registrationCost?: number;
  registrationInterval?: CostInterval;
  tcoEnabled?: boolean;
}

export interface VehicleResponse {
  id: string;
  userId: string;
  vin?: string;
  make?: string;
  model?: string;
  year?: number;
  engine?: string;
  transmission?: string;
  trimLevel?: string;
  driveType?: string;
  fuelType?: string;
  nickname?: string;
  color?: string;
  licensePlate?: string;
  odometerReading: number;
  isActive: boolean;
  createdAt: string;
  updatedAt: string;
  imageUrl?: string;
  // TCO fields
  purchasePrice?: number;
  purchaseDate?: string;
  insuranceCost?: number;
  insuranceInterval?: CostInterval;
  registrationCost?: number;
  registrationInterval?: CostInterval;
  tcoEnabled?: boolean;
}

export interface VehicleImageMeta {
  imageStorageBucket: string;
  imageStorageKey: string;
  imageFileName: string;
  imageContentType: string;
  imageFileSize: number;
}

export interface VINDecodeResult {
  make: string;
  model: string;
  year: number;
  engineType?: string;
  bodyType?: string;
  rawData?: any;
}

// Fastify-specific types for HTTP handling
export interface CreateVehicleBody {
  vin?: string;
  year?: number;
  make?: string;
  model?: string;
  engine?: string;
  transmission?: string;
  trimLevel?: string;
  driveType?: string;
  fuelType?: string;
  nickname?: string;
  color?: string;
  licensePlate?: string;
  odometerReading?: number;
  // TCO fields
  purchasePrice?: number;
  purchaseDate?: string;
  insuranceCost?: number;
  insuranceInterval?: CostInterval;
  registrationCost?: number;
  registrationInterval?: CostInterval;
  tcoEnabled?: boolean;
}

export interface UpdateVehicleBody {
  vin?: string;
  year?: number;
  make?: string;
  model?: string;
  engine?: string;
  transmission?: string;
  trimLevel?: string;
  driveType?: string;
  fuelType?: string;
  nickname?: string;
  color?: string;
  licensePlate?: string;
  odometerReading?: number;
  // TCO fields
  purchasePrice?: number;
  purchaseDate?: string;
  insuranceCost?: number;
  insuranceInterval?: CostInterval;
  registrationCost?: number;
  registrationInterval?: CostInterval;
  tcoEnabled?: boolean;
}

export interface VehicleParams {
  id: string;
}

// TCO (Total Cost of Ownership) response
export interface TCOResponse {
  vehicleId: string;
  purchasePrice: number;
  insuranceCosts: number;
  registrationCosts: number;
  taxCosts: number;
  otherCosts: number;
  fuelCosts: number;
  maintenanceCosts: number;
  lifetimeTotal: number;
  costPerDistance: number;
  distanceUnit: string;
  currencyCode: string;
}
