"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSubActivityLogs = exports.HealthieOmitType = void 0;
var HealthieOmitType;
(function (HealthieOmitType) {
    HealthieOmitType["QUESTION_NOT_FOUND_IN_FORM_DEFINITION"] = "QUESTION_NOT_FOUND_IN_FORM_DEFINITION";
    HealthieOmitType["MISSING_MAPPING"] = "MISSING_MAPPING";
    HealthieOmitType["OTHER"] = "OTHER";
})(HealthieOmitType || (exports.HealthieOmitType = HealthieOmitType = {}));
const getMappingLogs = (data) => {
    const errors = data.filter((item) => item.omitType === HealthieOmitType.MISSING_MAPPING);
    if (errors.length === 0)
        return undefined;
    const getMessage = () => {
        const errorText = errors
            .map((err) => {
            return `${err.questionId}`;
        })
            .join(', ');
        return `Missing mapping for the below questions: ${errorText}`;
    };
    const category = 'MISSING_SETTINGS';
    const message = getMessage();
    return {
        date: new Date().toISOString(),
        text: {
            en: message,
        },
        error: {
            category,
            message,
        },
    };
};
const getFormDefinitionLogs = (data) => {
    const errors = data.filter((item) => item.omitType === HealthieOmitType.QUESTION_NOT_FOUND_IN_FORM_DEFINITION);
    if (errors.length === 0)
        return undefined;
    const getMessage = () => {
        const errorText = errors
            .map((err) => {
            return `${err.questionId}`;
        })
            .join(', ');
        return `The following questions in the response could not be linked to a question definition in the form definition: ${errorText}`;
    };
    const category = 'SERVER_ERROR';
    const message = getMessage();
    return {
        date: new Date().toISOString(),
        text: {
            en: message,
        },
        error: {
            category,
            message,
        },
    };
};
const getOtherErrors = (data) => {
    const errors = data.filter((item) => item.omitType === HealthieOmitType.OTHER);
    if (errors.length === 0)
        return undefined;
    const getMessage = () => {
        const errorText = errors
            .map((err) => {
            return `${err.questionId}: ${err.reason}`;
        })
            .join(', ');
        return `There was an unexpected error transforming the following Awell form answers to Healthie form answers: ${errorText}`;
    };
    const category = 'SERVER_ERROR';
    const message = getMessage();
    return {
        date: new Date().toISOString(),
        text: {
            en: message,
        },
        error: {
            category,
            message,
        },
    };
};
const getSubActivityLogs = (data) => {
    const activityEvents = [
        getMappingLogs(data),
        getFormDefinitionLogs(data),
        getOtherErrors(data),
    ].filter((_) => _ !== undefined);
    return activityEvents;
};
exports.getSubActivityLogs = getSubActivityLogs;
//# sourceMappingURL=getSubActivityLogs.js.map