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

export const REVIEW_NOTE_TYPES = ['CHANGES_REQUESTED', 'REJECTION', 'STAFF_NOTE'] as const;
export type ReviewNoteType = (typeof REVIEW_NOTE_TYPES)[number];

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

  @ManyToOne(() => Booking, (b) => b.reviewNotes, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'booking_id' })
  booking?: Booking;

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

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

  @Column({ name: 'type', type: 'varchar', length: 30 })
  type!: ReviewNoteType;
}
