import { BUILD_PLAN_SESSION_SIDECAR_REL } from "../../core/planning/build-plan-session-file.js";
import { archiveSidecarFile } from "../../core/state/module-state-sidecar-migration.js";
import { persistAllowlistedModuleStateWithPlanningSync } from "../task-engine/persistence/module-state-planning-events-runtime.js";
const MODULE_ID = "planning-build-session";
export async function persistBuildPlanSessionWithPlanningSync(ctx, snapshot, options) {
    const full = {
        schemaVersion: 1,
        updatedAt: new Date().toISOString(),
        ...snapshot
    };
    const result = await persistAllowlistedModuleStateWithPlanningSync({
        workspacePath: ctx.workspacePath,
        effectiveConfig: ctx.effectiveConfig,
        moduleId: MODULE_ID,
        state: full,
        updatedAt: full.updatedAt,
        documentSchemaVersion: 1,
        commandName: options?.commandName ?? "build-plan",
        clientMutationId: options?.clientMutationId,
        policyApproval: options?.policyApproval
    });
    await archiveSidecarFile(ctx.workspacePath, BUILD_PLAN_SESSION_SIDECAR_REL);
    return result;
}
export async function clearBuildPlanSessionWithPlanningSync(ctx, options) {
    const result = await persistAllowlistedModuleStateWithPlanningSync({
        workspacePath: ctx.workspacePath,
        effectiveConfig: ctx.effectiveConfig,
        moduleId: MODULE_ID,
        state: {},
        removed: true,
        commandName: options?.commandName ?? "build-plan",
        clientMutationId: options?.clientMutationId,
        policyApproval: options?.policyApproval
    });
    await archiveSidecarFile(ctx.workspacePath, BUILD_PLAN_SESSION_SIDECAR_REL);
    return result;
}
