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

export interface TimeTrackingPoliciesHistoryCreationAttributes {
    userId: number;
    dateString: string;
    latenessTolerance: number | null;
    daySummaryId?: number;
}

@Table({
    paranoid: true,
    tableName: 'TimeTrackingPoliciesHistory',
})
export class TimeTrackingPoliciesHistoryDAO extends Model<TimeTrackingPoliciesHistoryDAO, TimeTrackingPoliciesHistoryCreationAttributes> {
    @PrimaryKey
    @AutoIncrement
    @Column
    id!: number;

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

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

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

    @Column
    userId!: number;

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

    @Column(DataType.INTEGER)
    latenessTolerance!: number | null;

    @ForeignKey(() => TimeTrackingDaySummaryDAO)
    @Column(DataType.INTEGER)
    daySummaryId?: number;

    @BelongsTo(() => TimeTrackingDaySummaryDAO)
    daySummary?: TimeTrackingDaySummaryDAO;
}
