import { SerializationClass } from '@humand-packages/common';
import { PublicUserPaginatedSC } from '../../../users/presentation/serializationClasses/publicUserPaginatedSC';
import { TimeTrackingCategorizedHourWithWorkData } from '../../business/models/timeTracking/timeTrackingCategorizedHour';
import { TimeTrackingCategorizedHourApprovalStep } from '../../business/models/timeTracking/timeTrackingCategorizedHourApprovalStep';
import { TimeTrackingCategorizedHourDetailDTO } from '../dataTransferObjects/timeTrackingCategorizedHourDetailDTO';
import { TimeTrackingCategorizedHourApprovalStepSC } from './TimeTrackingCategorizedHourApprovalStepSC';
import { TimeTrackingCategorizedHoursSC } from './TimeTrackingCategorizedHoursSC';

export interface TimeTrackingCategorizedHourDetailInput {
    hour: TimeTrackingCategorizedHourWithWorkData;
    approvalSteps: TimeTrackingCategorizedHourApprovalStep[];
}

export class TimeTrackingCategorizedHourDetailSC extends SerializationClass<
    TimeTrackingCategorizedHourDetailInput,
    TimeTrackingCategorizedHourDetailDTO
> {
    serialize({ hour, approvalSteps }: TimeTrackingCategorizedHourDetailInput): TimeTrackingCategorizedHourDetailDTO {
        const publicUserSC = new PublicUserPaginatedSC();
        return {
            ...new TimeTrackingCategorizedHoursSC().serialize(hour),
            approvalSteps: new TimeTrackingCategorizedHourApprovalStepSC().serializeList(approvalSteps),
            entries: hour.entries,
            entryIds: hour.entryIds,
            hourCategoryDescription: hour.hourCategoryDescription,
            statusOverride:
                hour.statusOverriddenByAdminId != null
                    ? {
                          admin: hour.statusOverriddenByAdmin ? publicUserSC.serialize(hour.statusOverriddenByAdmin) : null,
                          comment: hour.statusOverrideComment,
                      }
                    : null,
            workTimeSlots: hour.workTimeSlots,
        };
    }
}
