import { Table, Column, CreatedAt, UpdatedAt, DeletedAt, Model, ForeignKey, BelongsTo, HasMany, PrimaryKey, DataType } from 'sequelize-typescript';
import { TimeTrackingPolicyDAO } from '../../policy';
import { TimeTrackingPolicyApprovalStepResponsibleRelationDAO } from './responsibles/relation';
import { TimeTrackingPolicyApprovalStepResponsibleSegmentationItemDAO } from './responsibles/segmentationItem';
import { TimeTrackingPolicyApprovalStepResponsibleUserDAO } from './responsibles/user';

export interface TimeTrackingPolicyApprovalStepCreationAttributes {
    policyId: number | null;
    instanceId: number;
    position: number;
    designatedReviewer: boolean | null;
}

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

    @CreatedAt
    @Column
    createdAt!: Date;

    @UpdatedAt
    @Column
    updatedAt!: Date;

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

    @Column
    instanceId!: number;

    @ForeignKey(() => TimeTrackingPolicyDAO)
    @Column({ allowNull: true, type: DataType.INTEGER })
    policyId!: number | null;

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

    @Column
    position!: number;

    @Column({ allowNull: true, defaultValue: false, type: DataType.BOOLEAN })
    designatedReviewer!: boolean | null;

    @HasMany(() => TimeTrackingPolicyApprovalStepResponsibleRelationDAO, 'approvalStepId')
    responsibleRelations?: TimeTrackingPolicyApprovalStepResponsibleRelationDAO[];

    @HasMany(() => TimeTrackingPolicyApprovalStepResponsibleUserDAO, 'approvalStepId')
    responsibleUsers?: TimeTrackingPolicyApprovalStepResponsibleUserDAO[];

    @HasMany(() => TimeTrackingPolicyApprovalStepResponsibleSegmentationItemDAO, 'approvalStepId')
    responsibleSegmentationItems?: TimeTrackingPolicyApprovalStepResponsibleSegmentationItemDAO[];
}
