"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.publishRunWorkflowWithEventHooks = publishRunWorkflowWithEventHooks;
exports.runEventHooksForRunPublication = runEventHooksForRunPublication;
const runner_1 = require("../../event-hooks/runner");
const publisher_factory_1 = require("./publisher-factory");
const workflow_template_root_1 = require("./workflow-template-root");
async function publishRunWorkflowWithEventHooks(input) {
    const result = await (0, publisher_factory_1.createRunWorkflowPublisher)(input.context).publishWorkflow(input.request);
    await runEventHooksForRunPublication({
        ...input,
        result,
    });
    return result;
}
async function runEventHooksForRunPublication(input) {
    await (0, runner_1.runEventHooksForPublications)({
        repoRoot: input.repoRoot ?? (0, workflow_template_root_1.getWorkflowTemplateRepoRoot)(input.context),
        config: input.context.config,
        publications: [
            {
                request: input.request,
                result: input.result,
                origin: input.origin ?? "worker_publish",
                run: input.run ?? null,
            },
        ],
        ...(input.logger !== undefined ? { logger: input.logger } : {}),
        worker: input.context.worker,
        ...(input.context.logHomeDirectory !== undefined
            ? { homeDirectory: input.context.logHomeDirectory }
            : {}),
    });
}
