import { faker } from '@faker-js/faker/locale/en_US';
import { PerformanceReviewExternalReviewer } from '../../../../src/api/modules/performanceReviews/business/models/PerformanceReviewExternalReviewer';
import { PerformanceReviewUser } from '../../../../src/api/modules/performanceReviews/business/models/performanceReviewUser';
import { PerformanceReviewReviewerPaginatedSC } from '../../../../src/api/modules/performanceReviews/presentation/serializationClasses/performanceReviewReviewerPaginatedSC';
import {
    checkPerformanceReviewReviewerSerialized,
    generatePerformanceReviewReviewer,
    generateRandomExternalReviewer,
    generateRandomPerformanceReviewUser,
} from '../common';

describe('PerformanceReviewReviewerPaginatedSC', () => {
    it('should serialize performance review reviewers', () => {
        const reviewerUsersCount = faker.number.int({ max: 20, min: 10 });
        const reviewers = Array(reviewerUsersCount)
            .fill(1)
            .map(() => {
                return generatePerformanceReviewReviewer({});
            });
        const externalReviewersMap: Map<number, PerformanceReviewExternalReviewer> = new Map<number, PerformanceReviewExternalReviewer>();
        const internalReviewersMap: Map<number, PerformanceReviewUser> = new Map<number, PerformanceReviewUser>();
        reviewers.forEach((reviewer) => {
            if (reviewer.isExternal())
                externalReviewersMap.set(reviewer.externalReviewerId!, generateRandomExternalReviewer({ id: reviewer.externalReviewerId! }));
            else internalReviewersMap.set(reviewer.reviewerId!, generateRandomPerformanceReviewUser(reviewer.reviewerId!));
        });
        const reviewedsSerialized = new PerformanceReviewReviewerPaginatedSC().serializePaginatedList({
            count: reviewerUsersCount,
            extraData: { externalReviewersMap, internalReviewersMap },
            limit: 10,
            offset: 0,
            rows: reviewers,
        });

        expect(reviewedsSerialized.items).toHaveLength(reviewers.length);

        reviewedsSerialized.items.forEach((reviewerDTO, index) => {
            checkPerformanceReviewReviewerSerialized(reviewerDTO, externalReviewersMap, internalReviewersMap, reviewers[index]);
        });
    });
});
