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

export enum ComplianceType {
  INSPECTION = 'INSPECTION',
  INSURANCE = 'INSURANCE',
  ROADWORTHINESS = 'ROADWORTHINESS',
  PERMIT = 'PERMIT',
  TAX = 'TAX',
}

export enum ComplianceStatus {
  VALID = 'VALID',
  EXPIRING = 'EXPIRING',
  EXPIRED = 'EXPIRED',
}

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

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

  @Column({ name: 'type', type: 'varchar' })
  type!: ComplianceType;

  @Column({ name: 'document_number', type: 'varchar', nullable: true })
  documentNumber?: string;

  @Column({ name: 'issued_date', type: 'date', nullable: true })
  issuedDate?: string;

  @Column({ name: 'expiry_date', type: 'date' })
  expiryDate!: string;

  @Column({ name: 'status', type: 'varchar', default: ComplianceStatus.VALID })
  status!: ComplianceStatus;

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