import {
    Model,
    Table,
    Column,
    PrimaryKey,
    AutoIncrement,
    DataType,
    CreatedAt,
    UpdatedAt,
    DeletedAt,
    ForeignKey,
    Index,
    BelongsTo,
} from 'sequelize-typescript';
import { InstanceDAO } from '../../../../instances/infrastructure/dataAccessObjects/instanceDAO';
import { ShiftDAO } from './shift';

export interface ShiftTimeSlotForCreation {
    instanceId: number;
    shiftId: number;
    startTime: string;
    endTime: string;
}

@Table({
    indexes: [
        {
            fields: ['shiftId'],
        },
        {
            fields: ['instanceId'],
        },
    ],
    tableName: 'ShiftTimeSlots',
})
export class ShiftTimeSlotDAO extends Model<ShiftTimeSlotDAO, ShiftTimeSlotForCreation> {
    @PrimaryKey
    @AutoIncrement
    @Column
    id!: number;

    @Index('shift_time_slots_instance_id_index')
    @ForeignKey(() => InstanceDAO)
    @Column
    instanceId!: number;

    @Index('shift_time_slots_shift_id_index')
    @ForeignKey(() => ShiftDAO)
    @Column
    shiftId!: number;

    @Column
    startTime!: string;

    @Column
    endTime!: string;

    @CreatedAt
    @Column(DataType.DATE)
    createdAt!: Date;

    @UpdatedAt
    @Column(DataType.DATE)
    updatedAt!: Date;

    @DeletedAt
    @Column(DataType.DATE)
    deletedAt!: Date | null;

    @BelongsTo(() => ShiftDAO)
    shift!: ShiftDAO;
}
