{
  "name": "FASE 1 - Motor Logica PROD",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 6
            }
          ]
        }
      },
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -800,
        0
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": "REEMPLAZAR_SHEET_ID",
        "sheetName": "Calendario"
      },
      "name": "Get Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -600,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.estado }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "pendiente"
            }
          ]
        }
      },
      "name": "IF Estado",
      "type": "n8n-nodes-base.if",
      "position": [
        -400,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ new Date($json.fecha_hora) }}",
              "rightValue": "={{ new Date() }}",
              "operator": {
                "type": "dateTime",
                "operation": "beforeOrEquals"
              }
            }
          ]
        }
      },
      "name": "IF Fecha",
      "type": "n8n-nodes-base.if",
      "position": [
        -200,
        0
      ]
    },
    {
      "parameters": {
        "batchSize": 1
      },
      "name": "Split In Batches",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.media_url }}",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              }
            },
            {
              "leftValue": "={{ $json.caption }}",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              }
            }
          ]
        }
      },
      "name": "IF Contenido OK",
      "type": "n8n-nodes-base.if",
      "position": [
        200,
        0
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "modo",
              "value": "prod"
            },
            {
              "name": "tipo",
              "value": "={{ $json.tipo }}"
            },
            {
              "name": "caption",
              "value": "={{ $json.caption }}"
            },
            {
              "name": "media_url",
              "value": "={{ $json.media_url }}"
            },
            {
              "name": "hashtags",
              "value": "={{ $json.hashtags }}"
            },
            {
              "name": "plataforma",
              "value": "={{ $json.plataforma }}"
            },
            {
              "name": "row_number",
              "value": "={{ $json.row_number }}"
            }
          ]
        }
      },
      "name": "Build Payload",
      "type": "n8n-nodes-base.set",
      "position": [
        400,
        0
      ]
    },
    {
      "parameters": {
        "workflowId": "REEMPLAZAR_ID_PUBLICADOR"
      },
      "name": "Execute Publicador",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        600,
        0
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": "REEMPLAZAR_SHEET_ID",
        "sheetName": "Calendario",
        "columns": {
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "row_number"
          ]
        }
      },
      "name": "Actualizar Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        800,
        0
      ]
    }
  ],
  "connections": {
    "Schedule": {
      "main": [
        [
          {
            "node": "Get Sheet"
          }
        ]
      ]
    },
    "Get Sheet": {
      "main": [
        [
          {
            "node": "IF Estado"
          }
        ]
      ]
    },
    "IF Estado": {
      "main": [
        [
          {
            "node": "IF Fecha"
          }
        ]
      ]
    },
    "IF Fecha": {
      "main": [
        [
          {
            "node": "Split In Batches"
          }
        ]
      ]
    },
    "Split In Batches": {
      "main": [
        [
          {
            "node": "IF Contenido OK"
          }
        ]
      ]
    },
    "IF Contenido OK": {
      "main": [
        [
          {
            "node": "Build Payload"
          }
        ]
      ]
    },
    "Build Payload": {
      "main": [
        [
          {
            "node": "Execute Publicador"
          }
        ]
      ]
    },
    "Execute Publicador": {
      "main": [
        [
          {
            "node": "Actualizar Sheet"
          }
        ]
      ]
    }
  }
}