"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.predicateStateMessage = void 0;
const utils_1 = require("@autobe/utils");
const predicateStateMessage = (state, future) => {
    if (future === "analyze")
        return null;
    if (future === "prisma")
        return predicatePrisma(state);
    const futureIndex = STEP_ORDER.indexOf(future);
    for (const key of STEP_ORDER.slice(0, futureIndex))
        if (state[key] === null)
            return buildMissingStepsMessage(future, key);
    const prevStepName = STEP_ORDER[futureIndex - 1];
    if (state.analyze.step !== state[prevStepName].step)
        return buildOutdatedMessage(prevStepName, "analyze", state);
    return null;
};
exports.predicateStateMessage = predicateStateMessage;
const buildMissingStepsMessage = (current, missing) => {
    const currentIndex = STEP_ORDER.indexOf(current);
    const missingIndex = STEP_ORDER.indexOf(missing);
    const remainingSteps = STEP_ORDER.slice(missingIndex, currentIndex + 1)
        .map((step, index) => `${index + 1}. ${STEP_DESCRIPTIONS[step]}`)
        .join("\n    ");
    const currentAction = ACTION_NAMES[current];
    return utils_1.StringUtil.trim `
    ${STEP_DESCRIPTIONS[missing]} not completed yet.

    To ${currentAction}, complete these steps:
    
    ${remainingSteps}

    Start with step ${missingIndex + 1}.
  `;
};
const buildOutdatedMessage = (outdatedStep, currentStep, state) => {
    var _a, _b;
    const outdatedVersion = (_a = state[outdatedStep]) === null || _a === void 0 ? void 0 : _a.step;
    const currentVersion = (_b = state[currentStep]) === null || _b === void 0 ? void 0 : _b.step;
    return utils_1.StringUtil.trim `
    ${STEP_NAMES[outdatedStep]} is outdated (step ${outdatedVersion}).
    
    Requirements are now at step ${currentVersion}.
    
    Please update ${outdatedStep} to match current requirements.
  `;
};
const predicatePrisma = (state) => {
    if (state.analyze !== null)
        return null;
    return utils_1.StringUtil.trim `
    Requirements analysis not started.
    
    Discuss your project with AI to generate requirements analysis.
    Database design will follow after requirements are ready.
  `;
};
const STEP_DESCRIPTIONS = {
    analyze: "Requirements analysis",
    prisma: "Database design",
    interface: "API interface design",
    test: "E2E test creation",
    realize: "Implementation",
};
const STEP_NAMES = {
    analyze: "Requirements analysis",
    prisma: "Database schema",
    interface: "API interface",
    test: "Test functions",
    realize: "Implementation",
};
const ACTION_NAMES = {
    analyze: "analyze requirements",
    prisma: "design database",
    interface: "design API interface",
    test: "create tests",
    realize: "implement the program",
};
const STEP_ORDER = [
    "analyze",
    "prisma",
    "interface",
    "test",
    "realize",
];
//# sourceMappingURL=predicateStateMessage.js.map