/**
 * 架构决策研讨契约。
 *
 * 架构设计不是先写结果再补理由。该模块定义六类决策域的确认状态，
 * 供 sf_expand 在生成正式设计指令前强制校验。
 */
export const ARCHITECTURE_DECISION_DOMAINS = [
    "business_process",
    "data_architecture",
    "security_architecture",
    "backend_architecture",
    "frontend_architecture",
    "infrastructure",
];
const DOMAIN_DEPENDENCIES = {
    business_process: ["data_architecture", "security_architecture", "backend_architecture", "frontend_architecture"],
    data_architecture: ["security_architecture", "backend_architecture", "infrastructure"],
    security_architecture: ["backend_architecture", "frontend_architecture", "infrastructure"],
    backend_architecture: ["frontend_architecture", "infrastructure"],
    frontend_architecture: ["backend_architecture", "infrastructure"],
    infrastructure: ["security_architecture"],
};
export function createArchitectureDecisionWorkshop(taskId, projectContext = "new_system") {
    const domains = {};
    for (const domain of ARCHITECTURE_DECISION_DOMAINS) {
        domains[domain] = {
            decision_id: `${taskId}-${domain}`,
            domain,
            status: "not_started",
            required: true,
            facts_and_constraints: [],
            evidence_refs: [],
            options: [],
            dependent_domains: DOMAIN_DEPENDENCIES[domain],
        };
    }
    return {
        task_id: taskId,
        project_context: projectContext,
        status: "draft",
        prerequisite_evidence_refs: [],
        domains,
        required_diagrams: ["核心业务流程时序图"],
        design_generation_allowed: false,
        blocking_findings: [],
    };
}
/** 架构设计、重大系统方案才进入六域研讨，低风险修改不误拦。 */
export function requiresArchitectureDecisionWorkshop(workflowIntent, intent) {
    if (workflowIntent === "architecture_design")
        return true;
    return /架构设计|总体架构|技术架构|系统设计|技术方案设计|服务拆分|平台建设|architecture\s+design/i.test(intent);
}
export function evaluateArchitectureDecisionWorkshop(contract) {
    if (!contract) {
        return {
            allowed: false,
            status: "blocked",
            missing_domains: [...ARCHITECTURE_DECISION_DOMAINS],
            blocking_findings: ["缺少架构决策研讨记录，必须先完成六类架构决策讨论与用户确认"],
            next_domain: "business_process",
        };
    }
    const missingDomains = [];
    const findings = [];
    if (contract.project_context === "existing_system" && contract.prerequisite_evidence_refs.length === 0) {
        findings.push("现有系统架构设计缺少现状分析和差距分析证据");
    }
    for (const domain of ARCHITECTURE_DECISION_DOMAINS) {
        const decision = contract.domains[domain];
        if (!decision) {
            missingDomains.push(domain);
            findings.push(`缺少决策域记录: ${domain}`);
            continue;
        }
        if (decision.status === "not_started" || decision.status === "exploring" ||
            decision.status === "recommended" || decision.status === "awaiting_confirmation" ||
            decision.status === "rework_required" || decision.status === "rejected") {
            missingDomains.push(domain);
            findings.push(`决策域 ${domain} 尚未确认 (${decision.status})`);
        }
        if (decision.status === "confirmed" && !decision.user_confirmation_ref) {
            missingDomains.push(domain);
            findings.push(`决策域 ${domain} 标记 confirmed 但缺少用户确认引用`);
        }
        if (decision.status === "not_applicable_with_reason" && !decision.not_applicable_reason) {
            missingDomains.push(domain);
            findings.push(`决策域 ${domain} 标记不适用但缺少理由`);
        }
        if (decision.status === "deferred_with_impact" &&
            (!decision.user_confirmation_ref || !decision.deferred_impact?.length)) {
            missingDomains.push(domain);
            findings.push(`决策域 ${domain} 延期但缺少影响说明或用户确认`);
        }
    }
    if (!contract.document_output_confirmation_ref) {
        findings.push("架构设计文档输出目录和范围尚未获得用户确认");
    }
    return {
        allowed: findings.length === 0,
        status: findings.length === 0 ? "confirmed" : "awaiting_confirmation",
        missing_domains: [...new Set(missingDomains)],
        blocking_findings: findings,
        next_domain: missingDomains[0],
    };
}
export function applyArchitectureWorkshopGate(contract) {
    if (!contract)
        return undefined;
    const gate = evaluateArchitectureDecisionWorkshop(contract);
    return {
        ...contract,
        status: gate.status,
        design_generation_allowed: gate.allowed,
        blocking_findings: gate.blocking_findings,
    };
}
//# sourceMappingURL=architecture_decision_workshop.js.map