import { OptionalNullable } from '@humand-packages/common';
import { User } from '../../../../users/business/models/user';
import { TimeTrackingCategorizedHourStatus } from '../../../infrastructure/constants/timeTracking/categorizedHourStatus';
import { TimeTrackingEntryBasicData } from '../timeTrackingEntry';
import { TimeSlot } from './scheduleData';

// This is to keep consistent with the API response. To be removed when getCategorizedHoursForDaySummaries is updated.
export interface TimeTrackingCategorizedHourCategory {
    name: string;
}
// This is to keep consistent with the API response. To be removed when getCategorizedHoursForDaySummaries is updated.
export class TimeTrackingCategorizedHourForDaySummary {
    constructor(props: { category: TimeTrackingCategorizedHourCategory; hours: number }) {
        this.category = props.category;
        this.hours = props.hours;
    }

    category: TimeTrackingCategorizedHourCategory;
    hours: number;
}

export class TimeTrackingCategorizedHourForCreation {
    constructor(props: OptionalNullable<TimeTrackingCategorizedHourForCreation>) {
        this.hourCategoryId = props.hourCategoryId;
        this.hours = props.hours;
        this.status = props.status;
        this.dateString = props.dateString;
        this.instanceId = props.instanceId;
        this.userId = props.userId;
        this.entryIds = props.entryIds ?? null;
        this.statusOverriddenByAdminId = props.statusOverriddenByAdminId ?? null;
        this.statusOverrideComment = props.statusOverrideComment ?? null;
    }

    hourCategoryId: number;
    hours: number;
    status: TimeTrackingCategorizedHourStatus;
    dateString: string;
    instanceId: number;
    userId: number;
    entryIds: number[] | null;
    statusOverriddenByAdminId: number | null;
    statusOverrideComment: string | null;
}

export type TimeTrackingCategorizedHourAttributes = TimeTrackingCategorizedHourForCreation & { id: string };

export class TimeTrackingCategorizedHour extends TimeTrackingCategorizedHourForCreation {
    constructor(props: OptionalNullable<TimeTrackingCategorizedHour>) {
        super(props);
        this.id = props.id;
        this.note = props.note ?? null;
    }

    id: string;
    note: string | null;

    // Populated by enrichment in hourCategorizationService, not persisted
    statusOverriddenByAdmin?: User | null;
}

export class TimeTrackingCategorizedHourWithCategoryData extends TimeTrackingCategorizedHour {
    constructor(props: OptionalNullable<TimeTrackingCategorizedHourWithCategoryData>) {
        super(props);
        this.hourCategoryName = props.hourCategoryName;
        this.hourCategoryDescription = props.hourCategoryDescription ?? null;
    }

    hourCategoryName: string;
    hourCategoryDescription: string | null;
}

export class TimeTrackingCategorizedHourWithUserData extends TimeTrackingCategorizedHourWithCategoryData {
    constructor(props: OptionalNullable<TimeTrackingCategorizedHourWithUserData>) {
        super(props);
        this.profilePicture = props.profilePicture;
        this.employeeInternalId = props.employeeInternalId ?? null;
        this.fullName = props.fullName ?? null;
        this.currentStepId = props.currentStepId ?? null;
        this.isLoggedUserPotentialApprover = props.isLoggedUserPotentialApprover ?? false;
        this.isStatusOverridden = props.isStatusOverridden ?? false;
    }

    profilePicture: string | null | undefined;
    employeeInternalId: string | null;
    fullName: string | null;
    currentStepId: string | null;
    isLoggedUserPotentialApprover: boolean;
    isStatusOverridden: boolean;
}

export interface SavedPendingCategorizedHour {
    id: string;
    userId: number;
}

export interface ActiveCategorizedHourSummary {
    id: string;
    userId: number;
    dateString: string;
    hourCategoryId: number;
    hours: number;
    status: TimeTrackingCategorizedHourStatus;
}

export interface CategorizedHourDataUpdate {
    id: string;
    hours: number;
    entryIds: number[] | null;
}

export class TimeTrackingCategorizedHourWithWorkData extends TimeTrackingCategorizedHourWithUserData {
    constructor(props: OptionalNullable<TimeTrackingCategorizedHourWithWorkData>) {
        super(props);
        this.workTimeSlots = props.workTimeSlots ?? [];
        this.entries = props.entries ?? [];
    }

    workTimeSlots: TimeSlot[];
    entries: TimeTrackingEntryBasicData[];
}
