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

export const EMPTY_CONTAINER_RETURN_STATUSES = [
  'RETURNED',
  'ASSIGNED_STORAGE',
  'DOCUMENTATION_CLEARED',
  'WAGON_ALLOCATED',
  'TRANSPORTED_TO_DJIBOUTI',
  'HANDOVER_ISSUED',
  'COMPLETED',
] as const;

export type EmptyContainerReturnStatus = (typeof EMPTY_CONTAINER_RETURN_STATUSES)[number];

@Entity({ schema: 'freight', name: 'empty_container_returns' })
@Index(['containerNumber'])
@Index(['bookingId'])
@Index(['status'])
export class EmptyContainerReturn extends BaseEntity {
  @Column({ name: 'container_number', type: 'varchar', length: 80 })
  containerNumber!: string;

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

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

  @Column({ name: 'return_date', type: 'timestamptz' })
  returnDate!: Date;

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

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

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

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

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

  @Column({ name: 'status', type: 'varchar', length: 40, default: 'RETURNED' })
  status!: EmptyContainerReturnStatus;

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

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