{
  "openapi": "3.1.0",
  "info": {
    "title": "RMAFRA API",
    "version": "1.0.0",
    "summary": "API pública e somente leitura do estúdio RMAFRA",
    "description": "Permite que agentes de IA e integrações consultem os serviços, os trabalhos publicados e os canais de contato da RMAFRA, e preparem um diagnóstico inicial que abre uma conversa no WhatsApp. Não exige autenticação. Todos os erros são JSON no formato { \"error\": { \"code\", \"message\", \"hint\", \"status\" } }.",
    "contact": { "name": "RMAFRA", "email": "contato@rmafra.com.br", "url": "https://rmafra.com.br/contato" },
    "license": { "name": "Uso público somente leitura", "url": "https://rmafra.com.br/privacidade" }
  },
  "servers": [{ "url": "https://rmafra.com.br", "description": "Produção" }],
  "tags": [
    { "name": "catalogo", "description": "Serviços e trabalhos publicados" },
    { "name": "contato", "description": "Canais de contato e diagnóstico inicial" }
  ],
  "paths": {
    "/api/v1/services": {
      "get": {
        "operationId": "listServices",
        "tags": ["catalogo"],
        "summary": "Lista os serviços da RMAFRA",
        "description": "Retorna as quatro frentes de atuação (estratégia, design, tecnologia e crescimento), com resumo e o tipo de negócio para o qual cada uma é indicada.",
        "responses": {
          "200": {
            "description": "Lista de serviços",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ServiceList" } } }
          },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/api/v1/work": {
      "get": {
        "operationId": "listWork",
        "tags": ["catalogo"],
        "summary": "Lista os trabalhos publicados",
        "description": "Retorna os projetos reais que a RMAFRA apresenta publicamente, com cliente, escopo e setor.",
        "responses": {
          "200": {
            "description": "Lista de trabalhos",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WorkList" } } }
          },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/api/v1/contact": {
      "get": {
        "operationId": "getContact",
        "tags": ["contato"],
        "summary": "Retorna os canais de contato",
        "description": "E-mail, telefone, link de WhatsApp, horário de atendimento e localização da RMAFRA.",
        "responses": {
          "200": {
            "description": "Dados de contato",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Contact" } } }
          },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/api/v1/diagnostic": {
      "post": {
        "operationId": "prepareDiagnostic",
        "tags": ["contato"],
        "summary": "Prepara o diagnóstico inicial e o link de WhatsApp",
        "description": "Recebe as cinco respostas do diagnóstico do site e devolve a mensagem formatada e um link wa.me pronto para o usuário abrir. Nenhum dado é armazenado.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DiagnosticInput" } } }
        },
        "responses": {
          "200": {
            "description": "Diagnóstico preparado",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DiagnosticResult" } } }
          },
          "400": {
            "description": "Entrada inválida",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
          },
          "415": {
            "description": "Corpo não é application/json",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
          },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    }
  },
  "components": {
    "responses": {
      "ServerError": {
        "description": "Erro interno",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      }
    },
    "schemas": {
      "Service": {
        "type": "object",
        "required": ["id", "name", "summary", "fitFor"],
        "properties": {
          "id": { "type": "string", "examples": ["design"] },
          "name": { "type": "string", "examples": ["Design e experiência digital"] },
          "summary": { "type": "string", "description": "O que a frente entrega" },
          "fitFor": { "type": "string", "description": "Tipo de negócio ou situação para a qual a frente é indicada" }
        }
      },
      "ServiceList": {
        "type": "object",
        "required": ["services"],
        "properties": { "services": { "type": "array", "items": { "$ref": "#/components/schemas/Service" } } }
      },
      "Work": {
        "type": "object",
        "required": ["id", "client", "summary", "scope", "sector"],
        "properties": {
          "id": { "type": "string" },
          "client": { "type": "string" },
          "summary": { "type": "string" },
          "scope": { "type": "array", "items": { "type": "string" } },
          "sector": { "type": "string" }
        }
      },
      "WorkList": {
        "type": "object",
        "required": ["work"],
        "properties": { "work": { "type": "array", "items": { "$ref": "#/components/schemas/Work" } } }
      },
      "Contact": {
        "type": "object",
        "required": ["name", "email", "phone", "whatsapp", "hours", "location"],
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string", "format": "email" },
          "phone": { "type": "string", "examples": ["+55 81 98234-6298"] },
          "whatsapp": { "type": "string", "format": "uri" },
          "hours": { "type": "string" },
          "preferredChannel": { "type": "string" },
          "location": {
            "type": "object",
            "required": ["city", "region", "country"],
            "properties": {
              "city": { "type": "string" },
              "region": { "type": "string" },
              "country": { "type": "string" }
            }
          }
        }
      },
      "DiagnosticInput": {
        "type": "object",
        "required": ["empresa", "tempo", "nicho", "objetivos"],
        "properties": {
          "empresa": { "type": "string", "minLength": 2, "maxLength": 120, "description": "Nome da empresa" },
          "tempo": {
            "type": "string",
            "description": "Há quanto tempo a empresa existe",
            "enum": ["Estou começando agora", "Menos de 1 ano", "Entre 1 e 3 anos", "Entre 3 e 10 anos", "Mais de 10 anos"]
          },
          "nicho": { "type": "string", "minLength": 2, "maxLength": 160, "description": "Segmento ou tipo de negócio" },
          "concorrentes": { "type": "string", "maxLength": 600, "description": "Concorrentes ou referências, se houver" },
          "objetivos": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "description": "O que precisa mudar primeiro",
            "items": {
              "type": "string",
              "enum": ["Posicionamento mais claro", "Novo site ou landing page", "Produto digital ou automação", "Mais visibilidade e demanda"]
            }
          }
        }
      },
      "DiagnosticResult": {
        "type": "object",
        "required": ["whatsapp_url", "message", "next_step"],
        "properties": {
          "whatsapp_url": { "type": "string", "format": "uri", "description": "Link wa.me com a mensagem pré-preenchida" },
          "message": { "type": "string", "description": "Texto da mensagem, em português" },
          "next_step": { "type": "string", "description": "Instrução para o agente entregar ao usuário" }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message", "status"],
            "properties": {
              "code": { "type": "string", "examples": ["not_found", "validation_error", "method_not_allowed"] },
              "message": { "type": "string" },
              "hint": { "type": "string", "description": "Como resolver" },
              "status": { "type": "integer" },
              "details": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": { "field": { "type": "string" }, "message": { "type": "string" } }
                }
              }
            }
          }
        }
      }
    }
  }
}
