import {
    AllowNull,
    Column,
    CreatedAt,
    DataType,
    DeletedAt,
    ForeignKey,
    HasMany,
    Index,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt,
} from 'sequelize-typescript';
import { InstanceDAO } from '../../../../instances/infrastructure/dataAccessObjects/instanceDAO';
import { ShiftRotationDayDAO } from './shiftRotationDay';

export interface ShiftRotationDAOCreationFields {
    id: string;
    instanceId: number;
    name: string;
    description: string | null;
}

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

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

    @Column({ type: DataType.STRING(250) })
    name!: string;

    @AllowNull(true)
    @Column({ type: DataType.TEXT })
    description!: string | null;

    @HasMany(() => ShiftRotationDayDAO)
    days!: ShiftRotationDayDAO[];

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

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

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