import { truthy, PaginatedSerializationClass } from '@humand-packages/common';
import { PublicUserPaginatedSC } from '../../../users/presentation/serializationClasses/publicUserPaginatedSC';
import { TimeTrackingCategorizedHourApprovalStep } from '../../business/models/timeTracking/timeTrackingCategorizedHourApprovalStep';
import { TimeTrackingCategorizedHourApprovalStepDTO } from '../dataTransferObjects/timeTrackingCategorizedHourApprovalStepDTO';

export class TimeTrackingCategorizedHourApprovalStepSC extends PaginatedSerializationClass<
    TimeTrackingCategorizedHourApprovalStep,
    TimeTrackingCategorizedHourApprovalStepDTO
> {
    serialize(step: TimeTrackingCategorizedHourApprovalStep): TimeTrackingCategorizedHourApprovalStepDTO {
        const publicUserSC = new PublicUserPaginatedSC();
        return {
            approver: step.approver ? publicUserSC.serialize(step.approver) : null,
            comment: step.comment ?? null,
            id: step.id,
            position: step.position,
            potentialApprovers: step.potentialApprovers
                .map((pa) => pa.user)
                .filter(truthy)
                .map((u) => publicUserSC.serialize(u)),
            state: step.state,
        };
    }
}
