import { OptionalNullable } from '@humand-packages/common';
import { Incidence } from '../../../infrastructure/constants/incidences';
import { State } from '../../../infrastructure/constants/state';
import { AutoCloseFallback } from '../../enum/timeTracking/autoCloseFallback';
import { TimeTrackingPolicyAutoCloseMode } from '../../enum/timeTracking/policy';
import { TimeTrackingEntryPrototype } from '../timeTrackingEntry';
import { TimeTrackingAutoCloseEntry } from './autoCloseEntry';
import { TimeSlot } from './scheduleData';

export interface AutoCloseDataContext {
    estimatedHours: number;
    timeSlots: TimeSlot[] | null;
    dateString: string;
    timezone: string;
    allEntries: TimeTrackingEntryPrototype[];
}

export type AutoCloseResult = {
    autoCloseEntryTime: Date | undefined;
    autoCloseTime: Date | undefined;
    autoCloseFallback: AutoCloseFallback | null;
};

export class AutoCloseFixedHoursData {
    constructor(properties: OptionalNullable<AutoCloseFixedHoursData>) {
        this.autoCloseEntryTime = properties.autoCloseEntryTime;
        this.autoCloseTime = properties.autoCloseTime;
    }

    autoCloseEntryTime: Date | undefined;
    autoCloseTime: Date | undefined;
}

export class AutoCloseData extends AutoCloseFixedHoursData {
    constructor(properties: OptionalNullable<AutoCloseData>) {
        super(properties);
        this.autoCloseMode = properties.autoCloseMode;
        this.autoCloseFallback = properties.autoCloseFallback ?? null;
    }

    autoCloseMode: TimeTrackingPolicyAutoCloseMode;
    autoCloseFallback: AutoCloseFallback | null;
}

export class SummaryDataToUpdate {
    constructor(properties: OptionalNullable<SummaryDataToUpdate>) {
        this.instanceId = properties.instanceId;
        this.id = properties.id;
        this.dateString = properties.dateString;
        this.autoCloseEntryTime = properties.autoCloseEntryTime;
        this.autoCloseTime = properties.autoCloseTime;
        this.incidences = properties.incidences;
        this.state = properties.state;
        this.workedHours = properties.workedHours;
    }

    autoCloseEntryTime?: Date;
    autoCloseTime?: Date;
    dateString: string;
    instanceId: number;
    id: number;
    incidences?: Incidence[];
    state: State;
    workedHours: number;
}

export class SummaryDataToCorrect {
    constructor(properties: OptionalNullable<SummaryDataToCorrect>) {
        this.instanceId = properties.instanceId;
        this.summaryId = properties.summaryId;
        this.autoCloseEntryTime = properties.autoCloseEntryTime;
        this.autoCloseTime = properties.autoCloseTime;
        this.dateString = properties.dateString;
        this.userId = properties.userId;
    }

    instanceId: number;
    summaryId: number;
    autoCloseEntryTime?: Date;
    autoCloseTime?: Date;
    dateString: string;
    userId: number;
}

export interface AutoCloseNotificationBatch {
    instanceId: number;
    autoCloseEntries: TimeTrackingAutoCloseEntry[];
    summaryDateStringMap: Map<number, string>;
}

export class EntryDataToDelete {
    constructor(properties: OptionalNullable<EntryDataToDelete>) {
        this.instanceId = properties.instanceId;
        this.id = properties.id;
    }

    instanceId: number;
    id: number;
}
