import { BaseEntity } from '@edr/api-common'; import { Column, Entity, Index, JoinColumn, OneToOne } from 'typeorm'; import { Yard } from './yard.entity'; /** * What a yard's load/unload facility can do. One record per yard flagged * `has_facility`. * * `hasWarehouse` is the line that matters: a facility with a warehouse (Indode * today) stores cargo and therefore accrues storage/demurrage through the normal * warehouse flow; the rest only move cargo on and off the train, so they record * the handling event and its GRN and nothing else. */ @Entity({ schema: 'freight', name: 'yard_facilities' }) @Index(['yardId']) export class YardFacility extends BaseEntity { @Column({ name: 'yard_id', type: 'uuid' }) yardId!: string; @OneToOne(() => Yard, { nullable: false, onDelete: 'CASCADE' }) @JoinColumn({ name: 'yard_id' }) yard?: Yard; /** Cargo can be stored here — enables the warehouse flow (storage, demurrage). */ @Column({ name: 'has_warehouse', type: 'boolean', default: false }) hasWarehouse!: boolean; /** * Containers need a reach stacker or gantry, so only the equipped facilities * (Indode, Modjo, Dire Dawa) take them. Bulk needs far less and is handled * everywhere. */ @Column({ name: 'handles_container', type: 'boolean', default: true }) handlesContainer!: boolean; @Column({ name: 'handles_bulk', type: 'boolean', default: true }) handlesBulk!: boolean; /** * Per-side capability. Loading a type onto a train and receiving it off one * need different ground: a facility can be equipped to send containers but * have no space to stage arriving ones. `handles_container` / `handles_bulk` * stay the coarse "is this type handled here at all" switch; these four say * on which side. A yard is offered as a contract origin for a freight type * when it handles the type AND the matching `_origin` flag is set, and as a * destination on the same rule with `_destination`. */ @Column({ name: 'has_container_facility_origin', type: 'boolean', default: false }) hasContainerFacilityOrigin!: boolean; @Column({ name: 'has_bulk_facility_origin', type: 'boolean', default: false }) hasBulkFacilityOrigin!: boolean; @Column({ name: 'has_container_facility_destination', type: 'boolean', default: false }) hasContainerFacilityDestination!: boolean; @Column({ name: 'has_bulk_facility_destination', type: 'boolean', default: false }) hasBulkFacilityDestination!: boolean; @Column({ name: 'equipment_notes', type: 'text', nullable: true }) equipmentNotes?: string | null; @Column({ name: 'is_active', type: 'boolean', default: true }) isActive!: boolean; }