import { AutoIncrement, BelongsTo, Column, DataType, DeletedAt, ForeignKey, Model, PrimaryKey, Table } from 'sequelize-typescript';
import { TimeTrackingPolicy } from '../../business/models/timeTrackingPolicy';
import { TimeTrackingPolicyDAO } from './policy';

export class TimeTrackingPolicyUserCreationAttributes {
    policyId!: number;
    userId!: number;
    fromDate!: string;
    toDate?: string;
}

export class TimeTrackingPolicyUser extends TimeTrackingPolicyUserCreationAttributes {
    id!: number;
    policy?: TimeTrackingPolicy;
}

@Table({ tableName: 'TimeTrackingPoliciesUsers' })
export class TimeTrackingPolicyUsersDAO extends Model<TimeTrackingPolicyUsersDAO, TimeTrackingPolicyUserCreationAttributes> {
    @PrimaryKey
    @AutoIncrement
    @Column
    id!: number;

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

    @Column
    userId!: number;

    @Column
    fromDate!: string;

    @Column(DataType.STRING)
    toDate!: string | null;

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

    @DeletedAt
    @Column({ field: 'deleted_at', type: DataType.DATE })
    deletedAt!: Date | null;
}
