// WorldStartupEvidence — the typed bundle the classifier consumes.
//
// Every Failed lifecycle transition carries one of these. Fields are
// strict-optional (undefined, not null) so consumers can use the
// presence/absence as a signal directly (`promptSentAt === undefined`
// is itself the PromptMisdelivery signal).

/**
 * @typedef {'pending' | 'ok' | 'failed'} HandshakeStatus
 */

/**
 * @typedef {object} WorldStartupEvidence
 * @property {string}                   worldId
 * @property {import('./phases.mjs').WorldLifecyclePhase} lastPhase
 * @property {number}                   lastPhaseAt                epoch ms
 * @property {number}                   [promptSentAt]             undefined if no dispatch ever sent
 * @property {number}                   [firstThoughtAt]           undefined if no thoughts ever produced
 * @property {HandshakeStatus}          mcpHandshakeStatus
 * @property {HandshakeStatus}          transportStatus
 * @property {string[]}                 pluginErrors               captured stderr lines from plugin boot
 * @property {number}                   [processExitCode]
 * @property {number}                   elapsedSecondsSinceCreation
 */

/**
 * Construct an empty evidence bundle for a freshly-spawned world.
 * Caller mutates fields as transitions happen, then passes to the
 * classifier on Failed.
 *
 * @param {string} worldId
 * @param {number} [now]
 * @returns {WorldStartupEvidence}
 */
export function emptyEvidence(worldId, now = Date.now()) {
  return {
    worldId,
    lastPhase: 'Spawning',
    lastPhaseAt: now,
    mcpHandshakeStatus: 'pending',
    transportStatus: 'pending',
    pluginErrors: [],
    elapsedSecondsSinceCreation: 0,
  };
}
