import {
    BelongsTo,
    Column,
    CreatedAt,
    DataType,
    DeletedAt,
    ForeignKey,
    HasMany,
    Index,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt,
} from 'sequelize-typescript';
import { InstanceDAO } from '../../../../instances/infrastructure/dataAccessObjects/instanceDAO';
import { ShiftRotationDayType } from '../../../business/enum/shiftManagement/shiftRotationDayType';
import { ShiftRotationDAO } from './shiftRotation';
import { ShiftRotationDayShiftDAO } from './shiftRotationDayShift';

export interface ShiftRotationDayDAOCreationFields {
    id: string;
    instanceId: number;
    shiftRotationId: string;
    dayPosition: number;
    type: ShiftRotationDayType;
}

@Table({ tableName: 'ShiftRotationDays' })
export class ShiftRotationDayDAO extends Model<ShiftRotationDayDAO, ShiftRotationDayDAOCreationFields> {
    @PrimaryKey
    @Column(DataType.UUID)
    id!: string;

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

    @Index('ShiftRotationDays_shiftRotationId_index')
    @ForeignKey(() => ShiftRotationDAO)
    @Column(DataType.UUID)
    shiftRotationId!: string;

    @Column
    dayPosition!: number;

    @Column(DataType.STRING)
    type!: ShiftRotationDayType;

    @BelongsTo(() => ShiftRotationDAO)
    rotation!: ShiftRotationDAO;

    @HasMany(() => ShiftRotationDayShiftDAO)
    shifts!: ShiftRotationDayShiftDAO[];

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

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

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