/**
 * Suspend an active session.
 *
 * @task T4782
 * @epic T4654
 */
import { ExitCode } from '@cleocode/contracts';
import { CleoError } from '../errors.js';
import { getAccessor } from '../store/data-accessor.js';
/**
 * Suspend an active session.
 * Sets status to 'suspended' and records the reason.
 * Throws if session not found or not active.
 */
export async function suspendSession(projectRoot, sessionId, reason) {
    const accessor = await getAccessor(projectRoot);
    const sessions = await accessor.loadSessions();
    const session = sessions.find((s) => s.id === sessionId);
    if (!session) {
        throw new CleoError(ExitCode.SESSION_NOT_FOUND, `Session '${sessionId}' not found`);
    }
    if (session.status !== 'active') {
        throw new CleoError(ExitCode.SESSION_NOT_FOUND, `Session '${sessionId}' is ${session.status}, not active`);
    }
    const now = new Date().toISOString();
    session.status = 'suspended';
    Object.assign(session, { suspendedAt: now });
    if (session.stats) {
        session.stats.suspendCount = (session.stats.suspendCount || 0) + 1;
    }
    if (reason) {
        if (!session.notes)
            session.notes = [];
        session.notes.push(reason);
    }
    await accessor.upsertSingleSession(session);
    return session;
}
//# sourceMappingURL=session-suspend.js.map