{
  "openapi": "3.1.0",
  "info": {
    "title": "FlowOS Public Automation API",
    "version": "1.0.0",
    "description": "Especificação OpenAPI oficial para automação, CRM Kanban, disparos e webhooks no FlowOS (flowos.top).",
    "contact": {
      "name": "Suporte Técnico FlowOS",
      "email": "suporte@flowos.top",
      "url": "https://flowos.top"
    }
  },
  "servers": [
    {
      "url": "https://flowos.top",
      "description": "Servidor Oficial de Produção FlowOS"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT / FlowOS Token",
        "description": "Insira seu token de API obtido no menu lateral do FlowOS"
      }
    },
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "example": true
          },
          "app": {
            "type": "string",
            "example": "FlowOS"
          },
          "version": {
            "type": "string",
            "example": "1.0.0"
          }
        }
      },
      "Contact": {
        "type": "object",
        "required": [
          "phone"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "example": "5511999998888"
          },
          "name": {
            "type": "string",
            "example": "Maria Oliveira"
          },
          "funnel_stage": {
            "type": "string",
            "example": "fechamento"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "lead_quente",
              "vip"
            ]
          },
          "notes": {
            "type": "string",
            "example": "Interesse no plano anual PRO"
          }
        }
      },
      "TriggerFlowRequest": {
        "type": "object",
        "required": [
          "phone",
          "message"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "example": "5511999998888"
          },
          "message": {
            "type": "string",
            "example": "Olá Maria! Segue sua chave PIX para ativação imediata."
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "campanha_black_friday"
            ]
          },
          "delay_seconds": {
            "type": "integer",
            "example": 15
          }
        }
      },
      "PixCheckoutRequest": {
        "type": "object",
        "required": [
          "amount",
          "description",
          "payer_email"
        ],
        "properties": {
          "amount": {
            "type": "number",
            "example": 67.0
          },
          "description": {
            "type": "string",
            "example": "FlowOS PRO Anual"
          },
          "payer_email": {
            "type": "string",
            "example": "cliente@email.com"
          },
          "payer_name": {
            "type": "string",
            "example": "Carlos Souza"
          }
        }
      },
      "PixCheckoutResponse": {
        "type": "object",
        "properties": {
          "payment_id": {
            "type": "integer",
            "example": 1234567890
          },
          "qr_code": {
            "type": "string",
            "example": "00020126580014br.gov.bcb.pix..."
          },
          "qr_code_base64": {
            "type": "string",
            "example": "iVBORw0KGgoAAAANSUhEUgAA..."
          },
          "status": {
            "type": "string",
            "example": "pending"
          }
        }
      }
    }
  },
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Status do Servidor e Diagnóstico",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "Serviço ativo e operacional",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/contacts": {
      "get": {
        "summary": "Listar Contatos do CRM Kanban",
        "operationId": "listContacts",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de contatos recuperada com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Contact"
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Criar ou Atualizar Contato no Funil",
        "operationId": "upsertContact",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Contact"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Contato sincronizado com sucesso"
          }
        }
      }
    },
    "/api/flows/trigger": {
      "post": {
        "summary": "Disparar Mensagem ou Fluxo Automatizado",
        "operationId": "triggerFlow",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TriggerFlowRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Mensagem enfileirada no motor WA-JS com sucesso"
          }
        }
      }
    },
    "/api/checkout/pix": {
      "post": {
        "summary": "Gerar Cobrança Instantânea PIX Mercado Pago",
        "operationId": "createPixCheckout",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PixCheckoutRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "PIX Copia e Cola e QR Code gerados com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PixCheckoutResponse"
                }
              }
            }
          }
        }
      }
    }
  }
}