{
  "openapi": "3.1.0",
  "info": {
    "title": "IA Relatórios API",
    "version": "2.0.0",
    "description": "API pública do iarelatorios.com.br. Para consultas de planos, FAQ e tipos de relatório, prefira o servidor MCP em /api/mcp.php.",
    "contact": {
      "name": "IA Relatórios",
      "email": "contato@iarelatorios.com.br",
      "url": "https://www.iarelatorios.com.br"
    }
  },
  "servers": [
    {
      "url": "https://www.iarelatorios.com.br",
      "description": "Produção"
    }
  ],
  "paths": {
    "/health.php": {
      "get": {
        "operationId": "healthCheck",
        "summary": "Status do serviço",
        "responses": {
          "200": {
            "description": "Operacional",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "healthy"
                    },
                    "app": {
                      "type": "string",
                      "example": "iarelatorios.com.br"
                    },
                    "version": {
                      "type": "string"
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/lead.php": {
      "post": {
        "operationId": "requestFreeTrial",
        "summary": "Pedir teste gratuito (2 relatórios, sem cartão)",
        "description": "Registra um pedido de teste. Agentes só devem chamar com consentimento explícito do usuário para usar nome, e-mail e telefone dele.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "email",
                  "phone"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 120,
                    "example": "Roberto Silva"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "roberto@empresa.com.br"
                  },
                  "phone": {
                    "type": "string",
                    "description": "Telefone/WhatsApp com DDD (10 a 13 dígitos)",
                    "example": "(11) 99999-9999"
                  },
                  "report_type": {
                    "type": "string",
                    "enum": [
                      "financeiro",
                      "vendas",
                      "contabil",
                      "marketing",
                      "operacoes",
                      "outro"
                    ],
                    "default": "outro"
                  },
                  "plan": {
                    "type": "string",
                    "enum": [
                      "trial",
                      "free",
                      "pro",
                      "business"
                    ],
                    "default": "trial"
                  },
                  "source": {
                    "type": "string",
                    "maxLength": 80,
                    "example": "agente_ia"
                  },
                  "utm": {
                    "type": "string",
                    "description": "JSON com parâmetros UTM (opcional)",
                    "example": "{\"utm_source\":\"google\"}"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pedido recebido",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string"
                    },
                    "lead_id": {
                      "type": "string",
                      "example": "lead_20261013_101500_a1b2c3d4"
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Método não permitido"
          },
          "422": {
            "description": "Erro de validação",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "message": {
                      "type": "string"
                    },
                    "errors": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Falha temporária ao registrar"
          }
        }
      }
    },
    "/api/mcp.php": {
      "post": {
        "operationId": "mcpJsonRpc",
        "summary": "Servidor MCP (JSON-RPC 2.0, somente leitura)",
        "description": "Métodos: initialize, ping, tools/list, tools/call. Ferramentas: listar_planos, listar_tipos_relatorio, consultar_faq, estimar_economia.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "jsonrpc",
                  "method"
                ],
                "properties": {
                  "jsonrpc": {
                    "const": "2.0"
                  },
                  "id": {
                    "type": [
                      "integer",
                      "string"
                    ]
                  },
                  "method": {
                    "type": "string",
                    "example": "tools/call"
                  },
                  "params": {
                    "type": "object",
                    "example": {
                      "name": "estimar_economia",
                      "arguments": {
                        "relatorios_por_mes": 8,
                        "horas_por_relatorio": 3
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resposta JSON-RPC"
          },
          "202": {
            "description": "Notificação aceita"
          }
        }
      }
    }
  }
}