<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
             xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
             targetNamespace="http://bpmn.io/schema/bpmn"
             id="medium-gateway-definitions">

  <process id="medium-gateway-process" name="Proceso de Aprobación de Crédito" isExecutable="false">

    <startEvent id="start" name="Solicitud recibida">
      <outgoing>flow_start_recv</outgoing>
    </startEvent>

    <task id="task_recv" name="Recepcionar solicitud">
      <incoming>flow_start_recv</incoming>
      <outgoing>flow_recv_valid</outgoing>
    </task>

    <task id="task_valid" name="Validar datos del solicitante">
      <incoming>flow_recv_valid</incoming>
      <outgoing>flow_valid_gw1</outgoing>
    </task>

    <!-- Gateway XOR: ¿datos completos? -->
    <exclusiveGateway id="gw_datos" name="¿Datos completos?" default="flow_gw1_incompleto">
      <incoming>flow_valid_gw1</incoming>
      <outgoing>flow_gw1_completo</outgoing>
      <outgoing>flow_gw1_incompleto</outgoing>
    </exclusiveGateway>

    <task id="task_pedir_docs" name="Solicitar documentación adicional">
      <incoming>flow_gw1_incompleto</incoming>
      <outgoing>flow_docs_join</outgoing>
    </task>

    <task id="task_score" name="Calcular score crediticio">
      <incoming>flow_gw1_completo</incoming>
      <outgoing>flow_score_parallel</outgoing>
    </task>

    <!-- Gateway paralelo: verificación simultánea -->
    <parallelGateway id="gw_parallel_split" name="Verificación paralela">
      <incoming>flow_score_parallel</incoming>
      <outgoing>flow_para_bureau</outgoing>
      <outgoing>flow_para_empleador</outgoing>
    </parallelGateway>

    <task id="task_bureau" name="Consultar buró de crédito">
      <incoming>flow_para_bureau</incoming>
      <outgoing>flow_bureau_join</outgoing>
    </task>

    <task id="task_empleador" name="Verificar empleo y salario">
      <incoming>flow_para_empleador</incoming>
      <outgoing>flow_empleador_join</outgoing>
    </task>

    <!-- Join paralelo -->
    <parallelGateway id="gw_parallel_join" name="Consolidar verificaciones">
      <incoming>flow_bureau_join</incoming>
      <incoming>flow_empleador_join</incoming>
      <outgoing>flow_join_analisis</outgoing>
    </parallelGateway>

    <task id="task_analisis" name="Analizar riesgo crediticio">
      <incoming>flow_join_analisis</incoming>
      <incoming>flow_docs_join</incoming>
      <outgoing>flow_analisis_decision</outgoing>
    </task>

    <!-- Gateway XOR: decisión final -->
    <exclusiveGateway id="gw_decision" name="Decisión del comité">
      <incoming>flow_analisis_decision</incoming>
      <outgoing>flow_dec_aprobado</outgoing>
      <outgoing>flow_dec_rechazado</outgoing>
    </exclusiveGateway>

    <task id="task_aprobar" name="Emitir carta de aprobación">
      <incoming>flow_dec_aprobado</incoming>
      <outgoing>flow_aprobar_desembolso</outgoing>
    </task>

    <task id="task_rechazar" name="Notificar rechazo al solicitante">
      <incoming>flow_dec_rechazado</incoming>
      <outgoing>flow_rechazar_fin</outgoing>
    </task>

    <task id="task_desembolso" name="Procesar desembolso">
      <incoming>flow_aprobar_desembolso</incoming>
      <outgoing>flow_desembolso_archivo</outgoing>
    </task>

    <task id="task_archivo" name="Archivar expediente">
      <incoming>flow_desembolso_archivo</incoming>
      <incoming>flow_rechazar_fin</incoming>
      <outgoing>flow_archivo_end</outgoing>
    </task>

    <endEvent id="end" name="Proceso finalizado">
      <incoming>flow_archivo_end</incoming>
    </endEvent>

    <!-- Sequence Flows -->
    <sequenceFlow id="flow_start_recv" sourceRef="start" targetRef="task_recv"/>
    <sequenceFlow id="flow_recv_valid" sourceRef="task_recv" targetRef="task_valid"/>
    <sequenceFlow id="flow_valid_gw1" sourceRef="task_valid" targetRef="gw_datos"/>
    <sequenceFlow id="flow_gw1_completo" name="Completos" sourceRef="gw_datos" targetRef="task_score"/>
    <sequenceFlow id="flow_gw1_incompleto" name="Incompletos" sourceRef="gw_datos" targetRef="task_pedir_docs"/>
    <sequenceFlow id="flow_docs_join" sourceRef="task_pedir_docs" targetRef="task_analisis"/>
    <sequenceFlow id="flow_score_parallel" sourceRef="task_score" targetRef="gw_parallel_split"/>
    <sequenceFlow id="flow_para_bureau" sourceRef="gw_parallel_split" targetRef="task_bureau"/>
    <sequenceFlow id="flow_para_empleador" sourceRef="gw_parallel_split" targetRef="task_empleador"/>
    <sequenceFlow id="flow_bureau_join" sourceRef="task_bureau" targetRef="gw_parallel_join"/>
    <sequenceFlow id="flow_empleador_join" sourceRef="task_empleador" targetRef="gw_parallel_join"/>
    <sequenceFlow id="flow_join_analisis" sourceRef="gw_parallel_join" targetRef="task_analisis"/>
    <sequenceFlow id="flow_analisis_decision" sourceRef="task_analisis" targetRef="gw_decision"/>
    <sequenceFlow id="flow_dec_aprobado" name="Aprobado" sourceRef="gw_decision" targetRef="task_aprobar"/>
    <sequenceFlow id="flow_dec_rechazado" name="Rechazado" sourceRef="gw_decision" targetRef="task_rechazar"/>
    <sequenceFlow id="flow_aprobar_desembolso" sourceRef="task_aprobar" targetRef="task_desembolso"/>
    <sequenceFlow id="flow_rechazar_fin" sourceRef="task_rechazar" targetRef="task_archivo"/>
    <sequenceFlow id="flow_desembolso_archivo" sourceRef="task_desembolso" targetRef="task_archivo"/>
    <sequenceFlow id="flow_archivo_end" sourceRef="task_archivo" targetRef="end"/>

  </process>

  <bpmndi:BPMNDiagram id="diagram">
    <bpmndi:BPMNPlane id="plane" bpmnElement="medium-gateway-process">
      <bpmndi:BPMNShape id="start_di" bpmnElement="start"><dc:Bounds x="152" y="252" width="36" height="36"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_recv_di" bpmnElement="task_recv"><dc:Bounds x="240" y="230" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_valid_di" bpmnElement="task_valid"><dc:Bounds x="390" y="230" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="gw_datos_di" bpmnElement="gw_datos" isMarkerVisible="true"><dc:Bounds x="545" y="245" width="50" height="50"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_score_di" bpmnElement="task_score"><dc:Bounds x="650" y="230" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_pedir_docs_di" bpmnElement="task_pedir_docs"><dc:Bounds x="650" y="370" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="gw_parallel_split_di" bpmnElement="gw_parallel_split"><dc:Bounds x="805" y="245" width="50" height="50"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_bureau_di" bpmnElement="task_bureau"><dc:Bounds x="910" y="150" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_empleador_di" bpmnElement="task_empleador"><dc:Bounds x="910" y="310" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="gw_parallel_join_di" bpmnElement="gw_parallel_join"><dc:Bounds x="1065" y="245" width="50" height="50"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_analisis_di" bpmnElement="task_analisis"><dc:Bounds x="1170" y="230" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="gw_decision_di" bpmnElement="gw_decision" isMarkerVisible="true"><dc:Bounds x="1325" y="245" width="50" height="50"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_aprobar_di" bpmnElement="task_aprobar"><dc:Bounds x="1430" y="150" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_rechazar_di" bpmnElement="task_rechazar"><dc:Bounds x="1430" y="310" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_desembolso_di" bpmnElement="task_desembolso"><dc:Bounds x="1590" y="150" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="task_archivo_di" bpmnElement="task_archivo"><dc:Bounds x="1750" y="230" width="100" height="80"/></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="end_di" bpmnElement="end"><dc:Bounds x="1912" y="252" width="36" height="36"/></bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="f_start_recv" bpmnElement="flow_start_recv"><di:waypoint x="188" y="270"/><di:waypoint x="240" y="270"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_recv_valid" bpmnElement="flow_recv_valid"><di:waypoint x="340" y="270"/><di:waypoint x="390" y="270"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_valid_gw1" bpmnElement="flow_valid_gw1"><di:waypoint x="490" y="270"/><di:waypoint x="545" y="270"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_gw1_completo" bpmnElement="flow_gw1_completo"><di:waypoint x="595" y="270"/><di:waypoint x="650" y="270"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_gw1_incompleto" bpmnElement="flow_gw1_incompleto"><di:waypoint x="570" y="295"/><di:waypoint x="570" y="410"/><di:waypoint x="650" y="410"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_docs_join" bpmnElement="flow_docs_join"><di:waypoint x="750" y="410"/><di:waypoint x="1220" y="410"/><di:waypoint x="1220" y="310"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_score_parallel" bpmnElement="flow_score_parallel"><di:waypoint x="750" y="270"/><di:waypoint x="805" y="270"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_para_bureau" bpmnElement="flow_para_bureau"><di:waypoint x="830" y="245"/><di:waypoint x="830" y="190"/><di:waypoint x="910" y="190"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_para_empleador" bpmnElement="flow_para_empleador"><di:waypoint x="830" y="295"/><di:waypoint x="830" y="350"/><di:waypoint x="910" y="350"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_bureau_join" bpmnElement="flow_bureau_join"><di:waypoint x="1010" y="190"/><di:waypoint x="1090" y="190"/><di:waypoint x="1090" y="245"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_empleador_join" bpmnElement="flow_empleador_join"><di:waypoint x="1010" y="350"/><di:waypoint x="1090" y="350"/><di:waypoint x="1090" y="295"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_join_analisis" bpmnElement="flow_join_analisis"><di:waypoint x="1115" y="270"/><di:waypoint x="1170" y="270"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_analisis_decision" bpmnElement="flow_analisis_decision"><di:waypoint x="1270" y="270"/><di:waypoint x="1325" y="270"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_dec_aprobado" bpmnElement="flow_dec_aprobado"><di:waypoint x="1350" y="245"/><di:waypoint x="1350" y="190"/><di:waypoint x="1430" y="190"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_dec_rechazado" bpmnElement="flow_dec_rechazado"><di:waypoint x="1350" y="295"/><di:waypoint x="1350" y="350"/><di:waypoint x="1430" y="350"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_aprobar_desembolso" bpmnElement="flow_aprobar_desembolso"><di:waypoint x="1530" y="190"/><di:waypoint x="1590" y="190"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_rechazar_fin" bpmnElement="flow_rechazar_fin"><di:waypoint x="1530" y="350"/><di:waypoint x="1800" y="350"/><di:waypoint x="1800" y="310"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_desembolso_archivo" bpmnElement="flow_desembolso_archivo"><di:waypoint x="1690" y="190"/><di:waypoint x="1800" y="190"/><di:waypoint x="1800" y="230"/></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f_archivo_end" bpmnElement="flow_archivo_end"><di:waypoint x="1850" y="270"/><di:waypoint x="1912" y="270"/></bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>

</definitions>
