"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Observer_1 = require("./Observer");
const OBSERVATION_ARTIFACT_NAME = 'accessibility_check.json';
const A11Y_CHECK_EXECUTOR_NAME = 'accessibility_check';
class AccessibilityCheckResultsObserver extends Observer_1.AfterObserver {
    constructor(dispatcher) {
        super(Observer_1.ObservationType.ACCESSIBILITY_CHECK, dispatcher);
        this.observeAfterFunction = async (context) => {
            const accessibilityCheckExecutor = context.executionContext.executorStore.getStepExecutorByType(A11Y_CHECK_EXECUTOR_NAME);
            const maybeAccessibilityCheckResults = accessibilityCheckExecutor.getCheckResults();
            accessibilityCheckExecutor.clearCheckResults();
            if (!maybeAccessibilityCheckResults) {
                return {};
            }
            const a11yResults = JSON.stringify(maybeAccessibilityCheckResults);
            const tmpFile = await this.writeTempFile(OBSERVATION_ARTIFACT_NAME, a11yResults);
            const filesByObservationType = {};
            if (tmpFile) {
                filesByObservationType[this.observationType] = { uri: tmpFile };
            }
            return { filesByObservationType };
        };
        this.observeAfter = async (options) => {
            if (!options.properties?.isIntermediateAction) {
                await super.observeAfter(options);
            }
        };
    }
}
exports.default = AccessibilityCheckResultsObserver;
