{
  "name": "Lanterna: criar vídeo e esperar o MP4",
  "nodes": [
    {
      "parameters": {},
      "id": "a1f6e0a2-0000-4000-8000-000000000001",
      "name": "Começar",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [0, 0]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            { "id": "1", "name": "title", "value": "O farol que acendeu sozinho", "type": "string" },
            { "id": "2", "name": "theme", "value": "Mistério sobre um farol abandonado na Escócia, tom de documentário.", "type": "string" },
            { "id": "3", "name": "format", "value": "shorts", "type": "string" }
          ]
        },
        "options": {}
      },
      "id": "a1f6e0a2-0000-4000-8000-000000000002",
      "name": "Definir tema",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [220, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://SEU-DOMINIO/api/v1/videos",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Idempotency-Key", "value": "={{ $execution.id }}" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ title: $json.title, theme: $json.theme, format: $json.format, approval: 'auto', webhook_url: $execution.resumeUrl, webhook_events: ['video.completed', 'video.failed'] }) }}",
        "options": {}
      },
      "id": "a1f6e0a2-0000-4000-8000-000000000003",
      "name": "Criar vídeo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [440, 0],
      "notes": "Crie a credencial 'Header Auth' com nome Authorization e valor: Bearer lan_live_... (sua chave de Conta > API). Troque SEU-DOMINIO pelo endereço da Lanterna."
    },
    {
      "parameters": {
        "resume": "webhook",
        "httpMethod": "POST",
        "options": {}
      },
      "id": "a1f6e0a2-0000-4000-8000-000000000004",
      "name": "Esperar o vídeo",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [660, 0],
      "webhookId": "lanterna-video-pronto"
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.body.event }}",
              "rightValue": "video.completed",
              "operator": { "type": "string", "operation": "equals" }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a1f6e0a2-0000-4000-8000-000000000005",
      "name": "Ficou pronto?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [880, 0]
    },
    {
      "parameters": {
        "url": "={{ $json.body.data.result.mp4_url }}",
        "options": { "response": { "response": { "responseFormat": "file" } } }
      },
      "id": "a1f6e0a2-0000-4000-8000-000000000006",
      "name": "Baixar o MP4",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1100, -100],
      "notes": "O link é assinado e vale por 24 h: não precisa de chave. Ligue aqui o próximo passo (salvar no Drive, enviar a um agendador, etc.)."
    },
    {
      "parameters": {
        "errorMessage": "={{ 'A Lanterna não conseguiu gerar o vídeo: ' + ($json.body.data.error ? $json.body.data.error.message : 'erro desconhecido') }}"
      },
      "id": "a1f6e0a2-0000-4000-8000-000000000007",
      "name": "Falhou",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [1100, 100]
    }
  ],
  "connections": {
    "Começar": { "main": [[{ "node": "Definir tema", "type": "main", "index": 0 }]] },
    "Definir tema": { "main": [[{ "node": "Criar vídeo", "type": "main", "index": 0 }]] },
    "Criar vídeo": { "main": [[{ "node": "Esperar o vídeo", "type": "main", "index": 0 }]] },
    "Esperar o vídeo": { "main": [[{ "node": "Ficou pronto?", "type": "main", "index": 0 }]] },
    "Ficou pronto?": {
      "main": [
        [{ "node": "Baixar o MP4", "type": "main", "index": 0 }],
        [{ "node": "Falhou", "type": "main", "index": 0 }]
      ]
    }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "meta": { "templateCredsSetupCompleted": false }
}
