"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeBufferFromImagesInfo = exports.extractErrorDetails = exports.copyAndUpdate = void 0;
const lodash_1 = __importDefault(require("lodash"));
const constants_1 = require("../../constants");
const reporter_1 = require("../reporter");
const common_utils_1 = require("../../common-utils");
const copyAndUpdate = (original, updates) => {
    const keys = [
        'attempt',
        'browserId',
        'description',
        'error',
        'errorDetails',
        'file',
        'fullName',
        'history',
        'id',
        'imageDir',
        'imagesInfo',
        'meta',
        'multipleTabs',
        'screenshot',
        'sessionId',
        'skipReason',
        'state',
        'status',
        'testPath',
        'timestamp',
        'url'
    ];
    const keysTypeChecked = keys;
    const updatedTestResult = lodash_1.default.assign({}, lodash_1.default.pick(original, keysTypeChecked), updates);
    return new reporter_1.ReporterTestAdapter(updatedTestResult);
};
exports.copyAndUpdate = copyAndUpdate;
const extractErrorDetails = (testResult) => {
    const details = testResult.error?.details ?? null;
    if (details) {
        return {
            title: details.title || 'error details',
            data: details.data,
            filePath: `${constants_1.ERROR_DETAILS_PATH}/${(0, common_utils_1.getDetailsFileName)(testResult.imageDir, testResult.browserId, testResult.attempt)}`
        };
    }
    return null;
};
exports.extractErrorDetails = extractErrorDetails;
const removeBufferFromImagesInfo = (imagesInfo) => {
    const { diffImg } = imagesInfo;
    const newImagesInfo = lodash_1.default.clone(imagesInfo);
    if ((0, common_utils_1.isImageBufferData)(diffImg)) {
        newImagesInfo.diffImg = { ...diffImg, buffer: Buffer.from('') };
    }
    return newImagesInfo;
};
exports.removeBufferFromImagesInfo = removeBufferFromImagesInfo;
//# sourceMappingURL=index.js.map