import {
    AutoIncrement,
    BelongsTo,
    Column,
    CreatedAt,
    DataType,
    DeletedAt,
    ForeignKey,
    Model,
    PrimaryKey,
    Table,
    AllowNull,
    UpdatedAt,
} from 'sequelize-typescript';
import { TIME_OFF_POLICY_TYPE_ACTIVITY_TYPES } from '../../../timeOff/business/types/policyTypes/activityTypes';
import { TIME_OFF_REQUEST_CONSUMPTION_TYPES } from '../../../timeOff/business/types/requests/timeOffRequestConsumptionTypes';
import { TimeOffRequestDAO } from '../../../timeOff/infrastructure/dataAccessObjects/requests/timeOffRequestDAO';
import { TimeTrackingDaySummaryDAO } from './daySummary';

export interface TimeTrackingDaySummaryTimeOffCreationAttributes {
    daySummaryId: number;
    timeOffRequestId: number;
    timeOffPolicyTypeName: string;
    timeOffPolicyTypeIcon: string | null;
    hours: number | null;
    fromTime: string | null;
    toTime: string | null;
    consumptionType: TIME_OFF_REQUEST_CONSUMPTION_TYPES | null;
    activityType: TIME_OFF_POLICY_TYPE_ACTIVITY_TYPES | null;
    fromDate: string | null;
    toDate: string | null;
}

@Table({
    tableName: 'TimeTrackingDaySummariesTimeOff',
})
export class TimeTrackingDaySummaryTimeOffDAO extends Model<TimeTrackingDaySummaryTimeOffDAO, TimeTrackingDaySummaryTimeOffCreationAttributes> {
    @PrimaryKey
    @AutoIncrement
    @Column
    id!: number;

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

    @Column(DataType.INTEGER)
    @ForeignKey(() => TimeOffRequestDAO)
    timeOffRequestId!: number;

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

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

    @Column(DataType.FLOAT)
    hours!: number | null;

    @Column(DataType.TIME)
    fromTime!: string | null;

    @Column(DataType.TIME)
    toTime!: string | null;

    @AllowNull(true)
    @Column(DataType.ENUM(...Object.values(TIME_OFF_REQUEST_CONSUMPTION_TYPES)))
    consumptionType!: TIME_OFF_REQUEST_CONSUMPTION_TYPES | null;

    @AllowNull(true)
    @Column(DataType.ENUM(...Object.values(TIME_OFF_POLICY_TYPE_ACTIVITY_TYPES)))
    activityType!: TIME_OFF_POLICY_TYPE_ACTIVITY_TYPES | null;

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

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

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

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

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

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