import { PaginatedSerializationClass } from '@humand-packages/common';
import { TimeTrackingPolicyApprovalStep } from '../../business/models/policies/approvalSteps/timeTrackingPolicyApprovalStep';
import {
    TimeTrackingGlobalPolicyApprovalStepsDTO,
    TimeTrackingPolicyApprovalStepApproversDTO,
} from '../dtos/timeTracking/timeTrackingPolicyApprovalStepsDTO';

export class TimeTrackingPolicyStepApproversSC extends PaginatedSerializationClass<
    TimeTrackingPolicyApprovalStep,
    TimeTrackingPolicyApprovalStepApproversDTO
> {
    serialize(step: TimeTrackingPolicyApprovalStep): TimeTrackingPolicyApprovalStepApproversDTO {
        return {
            designatedReviewer: step.designatedReviewer ?? false,
            instanceId: step.instanceId,
            itemIds: step?.responsibleSegmentationItems?.map((responsibleItem) => responsibleItem.segmentationItemId) ?? [],
            policyId: step.policyId,
            position: step.position,
            relations: step?.responsibleRelations?.map((responsibleRelation) => responsibleRelation.relation) ?? [],
            stepId: step.id,
            userIds: step?.responsibleUsers?.map((responsibleUser) => responsibleUser.userId) ?? [],
        };
    }
}

export class TimeTrackingGlobalPolicyStepApproversSC extends PaginatedSerializationClass<
    TimeTrackingPolicyApprovalStep[],
    TimeTrackingGlobalPolicyApprovalStepsDTO
> {
    serialize(steps: TimeTrackingPolicyApprovalStep[]): TimeTrackingGlobalPolicyApprovalStepsDTO {
        return {
            steps: new TimeTrackingPolicyStepApproversSC().serializeList(steps),
        };
    }
}
