import {
    AutoIncrement,
    BelongsTo,
    Column,
    CreatedAt,
    DataType,
    DeletedAt,
    ForeignKey,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt,
} from 'sequelize-typescript';
import { WorkScheduleDAO } from './workSchedule';

export interface WorkScheduleUsersDAOCreationAttributes {
    workScheduleId: number;
    userId: number;
    startDate: Date;
    endDate: Date | null;
    startDateString: string;
    endDateString: string;
    current: boolean;
}

@Table({ tableName: 'WorkScheduleUsers' })
export class WorkScheduleUsersDAO extends Model<WorkScheduleUsersDAO, WorkScheduleUsersDAOCreationAttributes> {
    @AutoIncrement
    @PrimaryKey
    @Column
    id!: number;

    @ForeignKey(() => WorkScheduleDAO)
    @Column
    workScheduleId!: number;

    @Column
    userId!: number;

    @Column(DataType.DATE)
    startDate!: Date;

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

    @Column
    startDateString!: string;

    @Column
    endDateString!: string;

    // WARNING eventual consistency, not immediate
    @Column
    current!: boolean;

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

    @UpdatedAt
    updatedAt?: Date;

    @DeletedAt
    deletedAt?: Date;

    @BelongsTo(() => WorkScheduleDAO)
    workSchedule!: WorkScheduleDAO;
}
