import { BaseEntity } from '@edr/api-common';
import { Entity, Column, ManyToOne, JoinColumn, Index } from 'typeorm';
import { Vehicle } from '../../vehicles/entities/vehicle.entity';

@Entity({ name: 'fuel_consumption', schema: 'freight' })
@Index(['vehicleId', 'month'])
export class FuelConsumption extends BaseEntity {
  @Column({ name: 'vehicle_id', type: 'uuid' })
  vehicleId!: string;

  @ManyToOne(() => Vehicle, { eager: false })
  @JoinColumn({ name: 'vehicle_id' })
  vehicle!: Vehicle;

  @Column({ name: 'month', type: 'date' })
  month!: Date;

  @Column({ name: 'total_liters', type: 'numeric', precision: 10, scale: 2 })
  totalLiters!: number;

  @Column({ name: 'total_cost', type: 'numeric', precision: 14, scale: 2 })
  totalCost!: number;

  @Column({ name: 'total_distance_km', type: 'numeric', precision: 10, scale: 2, default: 0 })
  totalDistanceKm: number = 0;

  @Column({ name: 'fuel_efficiency_km_per_l', type: 'numeric', precision: 10, scale: 2, nullable: true })
  fuelEfficiencyKmPerL?: number;

  @Column({ name: 'number_of_purchases', type: 'integer', default: 0 })
  numberOfPurchases!: number;

  @Column({ name: 'average_cost_per_liter', type: 'numeric', precision: 10, scale: 2, nullable: true })
  averageCostPerLiter?: number;
}
