import { BelongsTo, Column, CreatedAt, DataType, DeletedAt, ForeignKey, Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript';
import { InstanceDAO } from '../../../../instances/infrastructure/dataAccessObjects/instanceDAO';
import { TimeTrackingPolicyDAO } from '../policy';
import { TimeTrackingHourCategoryDAO } from './hourCategory';

export class TimeTrackingPolicyHourCategoryCreationAttributes {
    id!: string;
    instanceId!: number;
    policyId!: number;
    hourCategoryId!: number;
    requiresApproval!: boolean;
}

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

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

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

    @ForeignKey(() => TimeTrackingPolicyDAO)
    @Column
    policyId!: number;

    @BelongsTo(() => TimeTrackingPolicyDAO)
    policy?: TimeTrackingPolicyDAO;

    @ForeignKey(() => TimeTrackingHourCategoryDAO)
    @Column
    hourCategoryId!: number;

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

    @Column({ allowNull: false, type: DataType.BOOLEAN, defaultValue: false })
    requiresApproval!: boolean;

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

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

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