/**
 * @ai-summary Type definitions for fuel logs feature
 * @ai-context Tracks fuel purchases and calculates MPG
 */

export interface FuelLog {
  id: string;
  userId: string;
  vehicleId: string;
  date: Date;
  odometer: number;
  gallons: number;
  pricePerGallon: number;
  totalCost: number;
  station?: string;
  location?: string;
  notes?: string;
  createdAt: Date;
  updatedAt: Date;
}

export interface CreateFuelLogRequest {
  vehicleId: string;
  date: string; // ISO date string
  odometer: number;
  gallons: number;
  pricePerGallon: number;
  totalCost: number;
  station?: string;
  location?: string;
  notes?: string;
}

export interface UpdateFuelLogRequest {
  date?: string;
  odometer?: number;
  gallons?: number;
  pricePerGallon?: number;
  totalCost?: number;
  station?: string;
  location?: string;
  notes?: string;
}

export interface FuelLogResponse {
  id: string;
  userId: string;
  vehicleId: string;
  date: string;
  odometer: number;
  gallons: number;
  pricePerGallon: number;
  totalCost: number;
  station?: string;
  location?: string;
  notes?: string;
  createdAt: string;
  updatedAt: string;
}

// Enhanced types for upgraded schema (Phase 2/3)
export enum FuelType {
  GASOLINE = 'gasoline',
  DIESEL = 'diesel',
  ELECTRIC = 'electric'
}

export type FuelGrade = '87' | '88' | '89' | '91' | '93' | '#1' | '#2' | null;

export interface LocationData {
  address?: string;
  coordinates?: { latitude: number; longitude: number };
  googlePlaceId?: string;
  stationName?: string;
}

export interface EnhancedCreateFuelLogRequest {
  vehicleId: string;
  dateTime: string; // ISO
  odometerReading?: number;
  tripDistance?: number;
  fuelType: FuelType;
  fuelGrade?: FuelGrade;
  fuelUnits: number;
  costPerUnit: number;
  locationData?: LocationData;
  notes?: string;
}

export interface EnhancedUpdateFuelLogRequest {
  dateTime?: string;
  odometerReading?: number;
  tripDistance?: number;
  fuelType?: FuelType;
  fuelGrade?: FuelGrade;
  fuelUnits?: number;
  costPerUnit?: number;
  locationData?: LocationData;
  notes?: string;
}

export interface EnhancedFuelLogResponse {
  id: string;
  userId: string;
  vehicleId: string;
  dateTime: string;
  odometerReading?: number;
  tripDistance?: number;
  fuelType: FuelType;
  fuelGrade?: FuelGrade;
  fuelUnits: number;
  costPerUnit: number;
  totalCost: number;
  locationData?: LocationData;
  efficiency?: number;
  efficiencyLabel: string;
  notes?: string;
  createdAt: string;
  updatedAt: string;
}

export interface FuelStats {
  totalGallons: number;
  totalCost: number;
  averagePricePerGallon: number;
  averageMPG: number;
  totalMiles: number;
  logCount: number;
}

// Fastify-specific types for HTTP handling
export interface CreateFuelLogBody {
  vehicleId: string;
  date: string;
  odometer: number;
  gallons: number;
  pricePerGallon: number;
  totalCost: number;
  station?: string;
  location?: string;
  notes?: string;
}

export interface UpdateFuelLogBody {
  date?: string;
  odometer?: number;
  gallons?: number;
  pricePerGallon?: number;
  totalCost?: number;
  station?: string;
  location?: string;
  notes?: string;
}

export interface FuelLogParams {
  id: string;
}

export interface VehicleParams {
  vehicleId: string;
}
