import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { AvailabilitySchedule } from './AvailabilitySchedule.entity';
import type { TimeInterval } from '../../utils/timezone';

@Entity('availability_date_overrides')
export class AvailabilityDateOverride {
  @PrimaryColumn('char', { length: 36 })
  id!: string;

  @Column({ name: 'schedule_id', type: 'char', length: 36 })
  scheduleId!: string;

  @Column({ name: 'override_date', type: 'date' })
  overrideDate!: string;

  @Column({ type: 'tinyint', width: 1, default: 0 })
  available!: boolean;

  @Column({ type: 'json', nullable: true })
  intervals!: TimeInterval[] | null;

  @ManyToOne(() => AvailabilitySchedule, (s) => s.dateOverrides, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'schedule_id' })
  schedule!: AvailabilitySchedule;
}
