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

export const DJIBOUTI_INCIDENT_TYPES = [
  'SEAL_BROKEN',
  'CONTAINER_OPENED',
  'CONTAINER_DAMAGED',
  'FLUID_LEAKING',
  'QUANTITY_MISMATCH',
  'WEIGHT_MISMATCH',
  'OTHER',
] as const;

export type DjiboutiIncidentType = (typeof DJIBOUTI_INCIDENT_TYPES)[number];

@Entity({ schema: 'freight', name: 'djibouti_import_incidents' })
@Index(['bookingId'])
@Index(['containerNumber'])
@Index(['incidentType'])
export class DjiboutiIncident extends BaseEntity {
  @Column({ name: 'booking_id', type: 'uuid' })
  bookingId!: string;

  @Column({ name: 'container_number', type: 'varchar', length: 80, nullable: true })
  containerNumber?: string | null;

  @Column({ name: 'cargo_id', type: 'uuid', nullable: true })
  cargoId?: string | null;

  @Column({ name: 'facility', type: 'varchar', length: 120, nullable: true })
  facility?: string | null;

  @Column({ name: 'station', type: 'varchar', length: 120, nullable: true })
  station?: string | null;

  @Column({ name: 'incident_type', type: 'varchar', length: 40 })
  incidentType!: DjiboutiIncidentType;

  @Column({ name: 'description', type: 'text' })
  description!: string;

  @Column({ name: 'photos', type: 'jsonb', default: () => "'[]'::jsonb" })
  photos!: string[];

  @Column({ name: 'reported_by', type: 'varchar', length: 120, nullable: true })
  reportedBy?: string | null;

  @Column({ name: 'reported_at', type: 'timestamptz' })
  reportedAt!: Date;
}
