"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReleaseGate = void 0;
const SystemDoctor_1 = require("./SystemDoctor");
const TestHarness_1 = require("./TestHarness");
const ReleaseWorkflow_1 = require("./ReleaseWorkflow");
const OperatingSystem_1 = require("./OperatingSystem");
class ReleaseGate {
    doctor;
    harness;
    workflow;
    operatingSystem;
    constructor() {
        this.doctor = new SystemDoctor_1.SystemDoctor();
        this.harness = new TestHarness_1.TestHarness();
        this.workflow = new ReleaseWorkflow_1.ReleaseWorkflow();
        this.operatingSystem = new OperatingSystem_1.OperatingSystem();
    }
    async run(releaseId, missionId) {
        const staticChecks = this.doctor.run();
        const runtimeChecks = await this.doctor.runRuntimeChecks();
        const harnessChecks = await this.harness.runPhase1Checks();
        const checks = [
            ...staticChecks.map((check) => ({ name: `doctor:${check.name}`, ok: check.ok })),
            ...runtimeChecks.map((check) => ({ name: `runtime:${check.name}`, ok: check.ok })),
            ...harnessChecks.map((check) => ({ name: `harness:${check.name}`, ok: check.ok }))
        ];
        if (missionId) {
            const decision = this.operatingSystem.decide(missionId);
            checks.push({ name: `ops:shouldRelease`, ok: decision.shouldRelease });
            checks.push({ name: `ops:noBlockers`, ok: decision.blockers.length === 0 });
        }
        return this.workflow.create(releaseId, checks);
    }
}
exports.ReleaseGate = ReleaseGate;
