jest.mock('../../../../src/api/modules/users/infrastructure/dataAccessObjects/userDAO.ts');
import { faker } from '@faker-js/faker/locale/en_US';
import { FormTemplateCreator } from '../../../../src/api/modules/formTemplates/business/models/formTemplateCreator';
import { PerformanceReviewTemplate } from '../../../../src/api/modules/performanceReviews/business/models/performanceReviewTemplate';
import { PerformanceReviewTemplateGoalsProgressMode } from '../../../../src/api/modules/performanceReviews/business/types/performanceReviewTemplateGoalsProgressMode';
import { PerformanceReviewTemplateSC } from '../../../../src/api/modules/performanceReviews/presentation/serializationClasses/performanceReviewTemplateSC';
import { fakePositiveInteger } from '../../../common/common';
import { generateRandomFormTemplate } from '../../formTemplates/common';
import { generateRandomQuestionTemplate } from '../../questionTemplates/common';
import { checkTemplateSerialized, generateRandomTemplate } from '../common';

describe('PerformanceReviewTemplateSC', () => {
    let template: PerformanceReviewTemplate;

    beforeEach(() => {
        template = generateRandomTemplate();
    });

    it('should serialize performance review template', () => {
        const templateSerialized = new PerformanceReviewTemplateSC().serialize(template);

        expect(templateSerialized).not.toBeNull();

        checkTemplateSerialized(template, templateSerialized);
    });

    it('should serialize performance review template with form template and question template', () => {
        template.formTemplate = generateRandomFormTemplate(template.formTemplateId!);
        template.goalsQuestionTemplate = generateRandomQuestionTemplate();
        template.competenciesQuestionTemplate = generateRandomQuestionTemplate();
        template.goalsProgressMode = PerformanceReviewTemplateGoalsProgressMode.MANUAL;

        const templateSerialized = new PerformanceReviewTemplateSC().serialize(template);

        expect(templateSerialized).not.toBeNull();

        checkTemplateSerialized(template, templateSerialized);
    });

    it('should serialize performance review template with form template, no question template but mode AUTO', () => {
        template.formTemplate = generateRandomFormTemplate(template.formTemplateId!);
        template.goalsProgressMode = PerformanceReviewTemplateGoalsProgressMode.AUTO;

        const templateSerialized = new PerformanceReviewTemplateSC().serialize(template);

        expect(templateSerialized).not.toBeNull();

        checkTemplateSerialized(template, templateSerialized);
    });

    it('should serialize performance review template with question templates within a form template, question template and creator', () => {
        template.formTemplate = generateRandomFormTemplate(template.formTemplateId!);
        template.goalsQuestionTemplate = generateRandomQuestionTemplate();
        template.competenciesQuestionTemplate = generateRandomQuestionTemplate();
        template.goalsProgressMode = PerformanceReviewTemplateGoalsProgressMode.MANUAL;
        template.creator = new FormTemplateCreator(
            faker.person.firstName(),
            faker.person.lastName(),
            faker.datatype.boolean(),
            fakePositiveInteger(),
            faker.date.anytime(),
            faker.date.anytime(),
        );
        template.formTemplate.questionTemplates = [generateRandomQuestionTemplate()];

        const templateSerialized = new PerformanceReviewTemplateSC().serialize(template);

        expect(templateSerialized).not.toBeNull();

        checkTemplateSerialized(template, templateSerialized);
    });
});
