import { CLI_REMEDIATION_DOCS } from "../../core/cli-remediation.js";
import { enforcePlanningGenerationPolicy, getPlanningGenerationPolicy } from "./planning-config.js";
/** Shared optimistic-concurrency gate for `wk run` mutations that touch planning generation. */
export function planningGenPolicyGate(ctx, args, instructionPath, planningGenSnapshot) {
    const policy = getPlanningGenerationPolicy({
        effectiveConfig: ctx.effectiveConfig
    });
    const gate = enforcePlanningGenerationPolicy(policy, args);
    if (!gate.ok) {
        const block = {
            ok: false,
            code: gate.code,
            message: gate.message,
            remediation: {
                instructionPath,
                docPath: CLI_REMEDIATION_DOCS.planningGeneration
            }
        };
        if (planningGenSnapshot !== undefined && gate.code === "planning-generation-required") {
            block.data = {
                currentPlanningGeneration: planningGenSnapshot,
                retryAfterRead: true,
                readCommandSuggestion: {
                    command: "list-tasks",
                    args: {}
                }
            };
        }
        return { block };
    }
    return { block: null, warnings: gate.warnings };
}
