"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BASIC_WORKFLOW_BOUNDARY_VERSION = void 0;
exports.projectBasicWorkflow = projectBasicWorkflow;
exports.evaluateBasicCreationBoundary = evaluateBasicCreationBoundary;
exports.BASIC_WORKFLOW_BOUNDARY_VERSION = 1;
function projectBasicWorkflow(options) {
    const terminal = options.taskStatus === "completed" || options.taskStatus === "cancelled";
    const implementationComplete = options.implementationStatus === "completed";
    return {
        boundaryVersion: exports.BASIC_WORKFLOW_BOUNDARY_VERSION,
        pairOnly: true,
        transcriptRequired: false,
        indexRequired: false,
        continuation: terminal
            ? "terminal"
            : implementationComplete
                ? "review-closeout"
                : "continue-current-task",
        continuationReasonCode: terminal
            ? "task-terminal"
            : implementationComplete
                ? "implementation-complete"
                : "task-active",
        promotionRecommended: false,
        promotionReasonCode: "single-task-boundary-intact",
        advisory: true,
        readOnly: true
    };
}
function evaluateBasicCreationBoundary(options) {
    const existingTaskIds = [...new Set(options.existingTaskIds)]
        .filter((taskId) => taskId !== options.requestedTaskId)
        .sort((left, right) => left.localeCompare(right));
    if (existingTaskIds.length === 0) {
        return {
            boundaryVersion: exports.BASIC_WORKFLOW_BOUNDARY_VERSION,
            allowed: true,
            existingTaskIds,
            confirmationRequired: false,
            confirmationSatisfied: false,
            reasonCode: "first-basic-task",
            promotion: {
                recommended: false,
                reasonCode: "single-task-boundary-intact",
                advisory: true,
                readOnly: true,
                command: null
            }
        };
    }
    const allowed = options.confirmIndependent;
    return {
        boundaryVersion: exports.BASIC_WORKFLOW_BOUNDARY_VERSION,
        allowed,
        existingTaskIds,
        confirmationRequired: true,
        confirmationSatisfied: allowed,
        reasonCode: allowed ? "independence-explicitly-confirmed" : "independence-unconfirmed",
        promotion: {
            recommended: !allowed,
            reasonCode: allowed ? "independence-explicitly-confirmed" : "independence-unconfirmed",
            advisory: true,
            readOnly: true,
            command: promotionCommand(existingTaskIds[0])
        }
    };
}
function promotionCommand(taskId) {
    return [
        "day-shift task promote",
        `--task-definition .day-shift/planning/basic/tasks/${taskId}/task-definition.md`,
        "--to structured",
        "--work-id <work-id>",
        "--spec <canonical-spec-path>"
    ].join(" ");
}
