import { faker } from '@faker-js/faker/locale/en_US';
import { PerformanceReviewCycle } from '../../../../src/api/modules/performanceReviews/business/models/performanceReviewCycle';
import { PerformanceReviewCycleSC } from '../../../../src/api/modules/performanceReviews/presentation/serializationClasses/performanceReviewCycleSC';
import {
    checkPerformanceReviewCycleSerialized,
    generateRandomPerformanceReviewCycle,
    generateRandomPerformanceReviewFormTemplate,
    generateRandomPerformanceReviewTargetUser,
} from '../common';

describe('PerformanceReviewCycleSC', () => {
    let reviewCycle: PerformanceReviewCycle;

    beforeEach(() => {
        reviewCycle = generateRandomPerformanceReviewCycle();
    });

    it('should serialize review cycle without form templates', () => {
        const reviewCycleSerialized = new PerformanceReviewCycleSC().serialize(reviewCycle);

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerialized(reviewCycle, reviewCycleSerialized);
    });

    it('should serialize review cycle with form templates', () => {
        const formTemplatesCount = faker.number.int({ max: 3, min: 1 });
        reviewCycle.formTemplates = Array(formTemplatesCount)
            .fill(1)
            .map(() => generateRandomPerformanceReviewFormTemplate(reviewCycle.id));

        const reviewCycleSerialized = new PerformanceReviewCycleSC().serialize(reviewCycle);

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerialized(reviewCycle, reviewCycleSerialized);
    });

    it('should serialize review cycle with target users', () => {
        const targetUsersCount = faker.number.int({ max: 3, min: 1 });
        reviewCycle.targetUsers = Array(targetUsersCount)
            .fill(1)
            .map(() => generateRandomPerformanceReviewTargetUser(reviewCycle.id));

        const reviewCycleSerialized = new PerformanceReviewCycleSC().serialize(reviewCycle);

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerialized(reviewCycle, reviewCycleSerialized);
    });

    it('should serialize review cycle with user target user', () => {
        reviewCycle.userTargetUser = generateRandomPerformanceReviewTargetUser(reviewCycle.id);

        const reviewCycleSerialized = new PerformanceReviewCycleSC().serialize(reviewCycle);

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerialized(reviewCycle, reviewCycleSerialized);
    });

    it('should serialize review cycle with user target user and obfuscation', () => {
        reviewCycle.userTargetUser = generateRandomPerformanceReviewTargetUser(reviewCycle.id);

        const reviewCycleSerialized = new PerformanceReviewCycleSC().serialize(reviewCycle, { scoreNeedsObfuscation: true });

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerialized(reviewCycle, reviewCycleSerialized, true);
    });

    it('should serialize review cycle with is responsible flag', () => {
        reviewCycle.isResponsible = faker.datatype.boolean();

        const reviewCycleSerialized = new PerformanceReviewCycleSC().serialize(reviewCycle);

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerialized(reviewCycle, reviewCycleSerialized);
    });
});
