<?xml version="1.0" encoding="UTF-8"?>
<workflow id="project_state_workflow" name="项目状态工作流">
    <!-- 状态定义 -->
    <states>
        <state id="initial" name="方案准备中" type="initial">
            <description>项目启动，正在准备方案</description>
        </state>
        <state id="quotation_submitted" name="方案报价已递交">
            <description>方案和报价已提交给客户</description>
        </state>
        <state id="waiting_reply" name="等客户回复中">
            <description>等待客户对方案和报价的回复</description>
        </state>
        <state id="preparing_contract" name="准备合同">
            <description>客户确认后，准备合同文档</description>
        </state>
        <state id="negotiation" name="商务谈判中">
            <description>与客户就方案或价格进行进一步谈判</description>
        </state>
        <state id="contract_signed" name="合同已签署" type="final">
            <description>合同已正式签署，项目进入执行阶段</description>
        </state>
        <state id="contract_rejected" name="合同被拒绝" type="final">
            <description>合同未通过客户审核，项目终止</description>
        </state>
    </states>

    <!-- 流转规则 -->
    <transitions>
        <!-- 串行流转 -->
        <transition from="initial" to="quotation_submitted" name="提交方案报价">
            <condition>方案准备完成且报价已确定</condition>
        </transition>
        <transition from="quotation_submitted" to="waiting_reply" name="等待客户回复">
            <condition>方案和报价已发送给客户</condition>
        </transition>

        <!-- 选择分支 -->
        <choice from="waiting_reply">
            <transition to="preparing_contract" name="客户接受">
                <condition>客户接受方案和报价</condition>
            </transition>
            <transition to="negotiation" name="客户要求谈判">
                <condition>客户需要进一步谈判</condition>
            </transition>
            <transition to="contract_rejected" name="客户拒绝">
                <condition>客户拒绝方案</condition>
            </transition>
        </choice>

        <!-- 谈判后流转 -->
        <transition from="negotiation" to="quotation_submitted" name="更新方案报价">
            <condition>谈判达成一致，更新方案和报价</condition>
        </transition>
        <transition from="negotiation" to="contract_rejected" name="谈判失败">
            <condition>谈判无法达成一致</condition>
        </transition>

        <!-- 最终流转 -->
        <transition from="preparing_contract" to="contract_signed" name="合同签署">
            <condition>合同已签署</condition>
        </transition>
        <transition from="preparing_contract" to="negotiation" name="合同需要修改">
            <condition>客户要求修改合同条款</condition>
        </transition>
    </transitions>

    <!-- 并行节点示例 -->
    <parallel id="contract_finalization" name="合同最终确认">
        <description>合同签署前的并行准备工作</description>
        <tasks>
            <task state="preparing_contract" name="合同文档准备"/>
            <task state="waiting_reply" name="客户确认"/>
        </tasks>
        <join to="contract_signed"/>
    </parallel>
</workflow>
