import { PerformanceReviewUserWithStats } from '../../../../src/api/modules/performanceReviews/business/models/performanceReviewUser';
import { PerformanceReviewFormShareStatus } from '../../../../src/api/modules/performanceReviews/business/types/performanceReviewFormShareStatus';
import { PerformanceReviewUserStatus } from '../../../../src/api/modules/performanceReviews/business/types/performanceReviewUserStatus';
import { PerformanceReviewUserWithStatsSC } from '../../../../src/api/modules/performanceReviews/presentation/serializationClasses/performanceReviewUserWithStatsSC';
import { fakePositiveInteger } from '../../../common/common';
import { addStatsToPerformanceReviewUser, checkPerformanceReviewUserWithStatsSerialized, generateRandomPerformanceReviewUser } from '../common';

describe('PerformanceReviewUserWithStatsSC', () => {
    it('should serialize review user with stats', () => {
        const reviewUser = addStatsToPerformanceReviewUser(generateRandomPerformanceReviewUser(fakePositiveInteger()));
        const reviewUserSerialized = new PerformanceReviewUserWithStatsSC().serialize(reviewUser);

        expect(reviewUserSerialized).not.toBeNull();

        checkPerformanceReviewUserWithStatsSerialized(reviewUser, reviewUserSerialized);
    });

    it('should serialize shareStatus and teamScoreDiff when set', () => {
        const reviewUser = new PerformanceReviewUserWithStats({
            userId: fakePositiveInteger(),
            firstName: 'John',
            lastName: 'Doe',
            employeeInternalId: 'E001',
            profilePicture: null,
            deleted: false,
            filledReviews: 5,
            totalReviews: 5,
            pendingReviews: 0,
            status: PerformanceReviewUserStatus.FINISHED,
            score: 96.5,
            shareStatus: PerformanceReviewFormShareStatus.SHARED_CONFIRMED,
            teamScoreDiff: 3.0,
        });
        const result = new PerformanceReviewUserWithStatsSC().serialize(reviewUser);

        expect(result.shareStatus).toBe(PerformanceReviewFormShareStatus.SHARED_CONFIRMED);
        expect(result.teamScoreDiff).toBe(3.0);
        expect(result.score).toBe(96.5);
    });

    it('should serialize null shareStatus and teamScoreDiff when not set', () => {
        const reviewUser = new PerformanceReviewUserWithStats({
            userId: fakePositiveInteger(),
            firstName: 'Jane',
            lastName: 'Doe',
            employeeInternalId: 'E002',
            profilePicture: null,
            deleted: false,
            filledReviews: 0,
            totalReviews: 5,
            pendingReviews: 5,
            status: PerformanceReviewUserStatus.PENDING,
            score: null,
        });
        const result = new PerformanceReviewUserWithStatsSC().serialize(reviewUser);

        expect(result.shareStatus).toBeNull();
        expect(result.teamScoreDiff).toBeNull();
        expect(result.score).toBeNull();
    });
});
