import { BaseEntity } from '@edr/api-common'; import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm'; import { Contract } from './contract.entity'; /** * One pre-booking clearance round on a contract (Path B). GENERAL contracts run * many cycles; ONE_TIME uses cycle_number = 1. The booking GL creates is linked * back via bookingId. See §5.16. */ @Entity({ schema: 'freight', name: 'contract_clearance_cycles' }) @Index(['contractId']) export class ContractClearanceCycle extends BaseEntity { @Column({ name: 'contract_id', type: 'uuid' }) contractId!: string; @ManyToOne(() => Contract, (c) => c.clearanceCycles, { onDelete: 'CASCADE' }) @JoinColumn({ name: 'contract_id' }) contract?: Contract; @Column({ name: 'cycle_number', type: 'int' }) cycleNumber!: number; @Column({ name: 'status', type: 'varchar', length: 40, default: 'AWAITING_DOCUMENTS' }) status!: string; @Column({ name: 'booking_id', type: 'uuid', nullable: true }) bookingId?: string | null; @Column({ name: 'started_at', type: 'timestamptz', default: () => 'now()' }) startedAt!: Date; @Column({ name: 'clearance_ready_at', type: 'timestamptz', nullable: true }) clearanceReadyAt?: Date | null; @Column({ name: 'completed_at', type: 'timestamptz', nullable: true }) completedAt?: Date | null; /** ET GL toggle: whether customer must pay duty/tax before DO collection (import). */ @Column({ name: 'duty_required', type: 'boolean', nullable: true }) dutyRequired?: boolean | null; /** Export RO vessel departure date (Path B export). */ @Column({ name: 'vessel_departure_date', type: 'date', nullable: true }) vesselDepartureDate?: string | null; @Column({ name: 'ro_amendment_requested_at', type: 'timestamptz', nullable: true }) roAmendmentRequestedAt?: Date | null; @Column({ name: 'ro_hold_reason', type: 'text', nullable: true }) roHoldReason?: string | null; @Column({ name: 'current_phase', type: 'varchar', length: 40, nullable: true }) currentPhase?: string | null; /** ET GL confirms import pre-clearance complete — unlocks Djibouti DO upload. */ @Column({ name: 'pre_clearance_finalized_at', type: 'timestamptz', nullable: true }) preClearanceFinalizedAt?: Date | null; }