"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Observer_1 = require("./Observer");
const OBSERVATION_ARTIFACT_NAME = 'broken_links.json';
class BrokenLinksObserver extends Observer_1.FlowObserver {
    constructor(dispatcher) {
        super(Observer_1.ObservationType.BROKEN_LINKS, dispatcher);
        this.observeFlowFunction = this.observeFlowFunction.bind(this);
    }
    async observeFlowFunction(context) {
        const linkValidationContext = context.executionContext.linkValidationContext;
        const linkResults = linkValidationContext.getPageLinkValidationResults();
        if (!linkResults.size) {
            return {};
        }
        const resultsObject = Object.fromEntries(linkResults);
        const stringifiedData = JSON.stringify(resultsObject);
        const tmpFile = await this.writeTempFile(OBSERVATION_ARTIFACT_NAME, stringifiedData);
        const filesByObservationType = {};
        if (tmpFile) {
            filesByObservationType[this.observationType] = { uri: tmpFile };
        }
        return { filesByObservationType };
    }
}
exports.default = BrokenLinksObserver;
