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

import { Yard } from '../../rule-engine/entities/yard.entity';
import { Route } from './route.entity';

@Entity({ schema: 'freight', name: 'route_milestones' })
@Index(['routeId', 'sequenceNo'], { unique: true })
export class RouteMilestone extends BaseEntity {
  @Column({ name: 'route_id', type: 'uuid' })
  routeId!: string;

  @ManyToOne(() => Route, (route) => route.milestones, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'route_id' })
  route?: Route;

  @Column({ name: 'yard_id', type: 'uuid' })
  yardId!: string;

  @ManyToOne(() => Yard)
  @JoinColumn({ name: 'yard_id' })
  yard?: Yard;

  @Column({ name: 'sequence_no', type: 'int' })
  sequenceNo!: number;
}
