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

export enum PaymentMethod {
  CASH = 'CASH',
  CARD = 'CARD',
  FUEL_CARD = 'FUEL_CARD',
  TRANSFER = 'TRANSFER',
  CHEQUE = 'CHEQUE',
}

@Entity({ name: 'fuel_purchases', schema: 'freight' })
export class FuelPurchase extends BaseEntity {
  @Column({ name: 'vehicle_id', type: 'uuid' })
  vehicleId!: string;

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

  @Column({ name: 'purchase_date', type: 'timestamptz' })
  purchaseDate!: Date;

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

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

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

  @Column({ name: 'fuel_station', nullable: true })
  fuelStation?: string;

  @Column({ name: 'payment_method', type: 'varchar', default: PaymentMethod.CASH })
  paymentMethod!: PaymentMethod;

  @Column({ name: 'odometer_reading', type: 'numeric', nullable: true })
  odometerReading?: number;

  @Column({ name: 'driver_id', type: 'uuid', nullable: true })
  driverId?: string;

  @Column({ name: 'receipt_number', nullable: true })
  receiptNumber?: string;

  @Column({ type: 'text', nullable: true })
  notes?: string;
}
