{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "procurement-flow",
        "responseMode": "=responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "id": "9cface33-59d9-4317-8fab-fba13afdfaa3",
      "name": "Webhook"
    },
    {
      "parameters": {
        "url": "=http://host.docker.internal:5000/api/procurement/{{$json[\"body\"][\"procurement_id\"]}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        208,
        0
      ],
      "id": "e57f2f73-99a1-4491-bd3c-c618874e985d",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "jsCode": "const inventory = $json.items || [];\n\nif (inventory.length === 0) {\n  throw new Error(\"No hay inventario registrado\");\n}\n\ninventory.sort((a, b) => a.unit_price - b.unit_price);\n\nconst best = inventory[0];\n\nreturn [\n  {\n    json: {\n      supplier_id: best.supplier_id,\n      product_name: best.name,\n      unit_price: best.unit_price,\n      quantity: 2,\n      total_amount: best.unit_price * 2\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        832,
        0
      ],
      "id": "1f1c9086-12bc-4887-b516-303a168ad66a",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "url": "=http://host.docker.internal:5000/api/inventory",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        624,
        0
      ],
      "id": "688e928d-afe3-43ed-b28f-fa1e37b2f073",
      "name": "Inventario"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://host.docker.internal:11434/api/generate",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"llama3\",\n  \"prompt\": \"Analiza esta solicitud gaming: Producto {{$json['title']}}, categor\u00eda {{$json['category']}}, cantidad {{$json['quantity']}}, presupuesto {{$json['budget']}}. Recomienda estrategia de compra.\",\n  \"stream\": false\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        416,
        0
      ],
      "id": "ad0c90e1-f35e-4cef-8b72-5e505c8552b7",
      "name": "IA Llama3"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://host.docker.internal:5000/api/orders",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"procurement_request_id\": 1,\n  \"supplier_id\": {{$json[\"supplier_id\"]}},\n  \"total_amount\": {{$json[\"total_amount\"]}}\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1040,
        0
      ],
      "id": "4c4de100-6503-4423-ab41-2270317e2c1e",
      "name": "Create Order"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\n  \"status\": \"success\",\n  \"message\": \"Orden generada autom\u00e1ticamente\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        1248,
        0
      ],
      "id": "1498ce05-2b86-447f-a460-756b9747785a",
      "name": "Respond to Webhook"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "IA Llama3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inventario": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IA Llama3": {
      "main": [
        [
          {
            "node": "Inventario",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Create Order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Order": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "7553c771-99a4-464a-8870-3dd9a68c6331",
  "id": "K9Q85HvTnb5BRyXe",
  "tags": []
}