import { Entity, Column } from 'typeorm';
import { BaseEntity } from '@edr/api-common';

export enum DriverStatus {
  ACTIVE = 'ACTIVE',
  INACTIVE = 'INACTIVE',
  SUSPENDED = 'SUSPENDED',
  ON_LEAVE = 'ON_LEAVE',
}

@Entity({ name: 'drivers', schema: 'freight' })
export class Driver extends BaseEntity {
  @Column({ name: 'license_number', unique: true, nullable: true })
  licenseNumber?: string;

  @Column({ name: 'first_name', nullable: true })
  firstName?: string;

  @Column({ name: 'last_name', nullable: true })
  lastName?: string;

  @Column({ unique: true, nullable: true })
  email?: string;

  @Column({ name: 'phone_number', unique: true, nullable: true })
  phoneNumber?: string;

  @Column({ name: 'date_of_birth', type: 'date', nullable: true })
  dateOfBirth?: Date;

  @Column({ name: 'license_expiry_date', type: 'date', nullable: true })
  licenseExpiryDate?: Date;

  @Column({ type: 'varchar', default: DriverStatus.ACTIVE, nullable: true })
  status?: DriverStatus;

  @Column({ name: 'vehicle_types_authorized', type: 'varchar', array: true, nullable: true })
  vehicleTypesAuthorized?: string[];

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

  @Column({ name: 'emergency_contact', type: 'varchar', nullable: true })
  emergencyContact?: string | null;

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

  @Column({ name: 'total_trips', type: 'int', default: 0, nullable: true })
  totalTrips?: number;

  @Column({ type: 'numeric', precision: 3, scale: 2, nullable: true })
  rating?: number | null;
}
