/**
 * Nexus Prime — Run Projector
 *
 * Projects run state for the dashboard and API consumers.
 * Converts internal execution state into the tri-state model:
 *   executionState × verificationState × acceptanceState
 */
export class RunProjector {
    /**
     * Build a RunProjection from execution results and verification proof.
     */
    project(params) {
        const { runId, workerResults, verificationProof, applied, rolledBack, startedAt, completedAt, proofIds } = params;
        const executionState = completedAt
            ? (workerResults.some(w => w.errors.length > 0) ? 'failed' : 'completed')
            : 'running';
        const verificationState = verificationProof?.verdict ?? 'pending';
        let acceptanceState = 'unapplied';
        if (applied)
            acceptanceState = 'applied';
        else if (rolledBack)
            acceptanceState = 'rolled_back';
        else if (verificationState === 'rejected')
            acceptanceState = 'held';
        return {
            runId,
            executionState,
            verificationState,
            acceptanceState,
            workerResults,
            proofIds,
            startedAt,
            completedAt,
        };
    }
    /** Extract the tri-state from a projection. */
    toTriState(projection) {
        return {
            executionState: projection.executionState,
            verificationState: projection.verificationState,
            acceptanceState: projection.acceptanceState,
        };
    }
}
