import { BelongsTo, Column, CreatedAt, DataType, ForeignKey, DeletedAt, Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript';
import { InstanceDAO } from '../../../../instances/infrastructure/dataAccessObjects/instanceDAO';
import { TimeTrackingCategorizedHourAttributes } from '../../../business/models/timeTracking/timeTrackingCategorizedHour';
import { TimeTrackingCategorizedHourStatus } from '../../constants/timeTracking/categorizedHourStatus';
import { TimeTrackingHourCategoryDAO } from './hourCategory';

@Table({ tableName: 'TimeTrackingCategorizedHours' })
export class TimeTrackingCategorizedHourDAO extends Model<TimeTrackingCategorizedHourDAO, TimeTrackingCategorizedHourAttributes> {
    @PrimaryKey
    @Column({ type: DataType.UUID })
    id!: string;

    @Column({ type: DataType.FLOAT })
    hours!: number;

    @Column({ type: DataType.INTEGER })
    @ForeignKey(() => TimeTrackingHourCategoryDAO)
    hourCategoryId!: number;

    @BelongsTo(() => TimeTrackingHourCategoryDAO)
    hourCategory?: TimeTrackingHourCategoryDAO;

    @Column
    userId!: number;

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

    @BelongsTo(() => InstanceDAO)
    instance?: InstanceDAO;

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

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

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

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

    @Column({
        allowNull: false,
        defaultValue: TimeTrackingCategorizedHourStatus.PENDING,
        type: DataType.ENUM(...Object.values(TimeTrackingCategorizedHourStatus)),
    })
    status!: TimeTrackingCategorizedHourStatus;

    @Column({
        allowNull: true,
        type: DataType.TEXT,
    })
    note?: string;

    @Column({
        allowNull: true,
        type: DataType.INTEGER,
    })
    statusOverriddenByAdminId?: number | null;

    @Column({
        allowNull: true,
        type: DataType.TEXT,
    })
    statusOverrideComment?: string | null;

    @Column({
        allowNull: true,
        type: DataType.ARRAY(DataType.INTEGER),
    })
    entryIds?: number[] | null;
}
