{
  "openapi": "3.1.0",
  "info": {
    "title": "Check Contatos API",
    "version": "1.0.0",
    "description": "Diagnóstico passivo dos canais de contato de um site (WhatsApp, telefone, e-mail, formulários, botões, celular, HTTPS). Lê só páginas públicas: não envia mensagens nem formulários. Cadastro aberto com chave por agente e limites por chave."
  },
  "servers": [
    {
      "url": "https://iafnrtypzwdugsehyvvd.supabase.co/functions/v1/api"
    }
  ],
  "components": {
    "securitySchemes": {
      "agentKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "cc_live_...",
        "description": "Chave obtida em POST /v1/agents."
      }
    }
  },
  "paths": {
    "/v1/agents": {
      "post": {
        "operationId": "registerAgent",
        "summary": "Cadastrar um agente e receber a chave (mostrada uma vez)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "email",
                  "company",
                  "agent_name",
                  "purpose",
                  "accept_terms"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Nome do responsável"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "company": {
                    "type": "string"
                  },
                  "agent_name": {
                    "type": "string",
                    "description": "Ex.: Claude Desktop, agente interno"
                  },
                  "purpose": {
                    "type": "string",
                    "description": "Uso pretendido (5 a 1000 caracteres)"
                  },
                  "accept_terms": {
                    "type": "boolean",
                    "const": true,
                    "description": "Aceite da política de privacidade em https://www.checkcontatos.com.br/privacidade"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Chave criada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "agent_id": {
                      "type": "string"
                    },
                    "api_key": {
                      "type": "string"
                    },
                    "key_prefix": {
                      "type": "string"
                    },
                    "limits": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inexistente ou revogada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Limite atingido (veja retry_after)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/diagnostics": {
      "post": {
        "operationId": "startDiagnostic",
        "summary": "Iniciar o diagnóstico de um site",
        "security": [
          {
            "agentKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Endereço público do site"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Diagnóstico na fila; consulte em poll_after_seconds"
          },
          "400": {
            "description": "Entrada inválida",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inexistente ou revogada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Limite atingido (veja retry_after)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/diagnostics/{id}": {
      "get": {
        "operationId": "getDiagnostic",
        "summary": "Estado e resultado estruturado",
        "security": [
          {
            "agentKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "items[] com código, tipo de correção, comportamento esperado, critérios de aceite e ocorrências com correção exata; not_verified[] com os limites. Enquanto poll_after_seconds não for nulo, a análise continua."
          },
          "400": {
            "description": "Entrada inválida",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inexistente ou revogada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Limite atingido (veja retry_after)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/diagnostics/{id}/report": {
      "get": {
        "operationId": "getReportLink",
        "summary": "Link assinado (60 s) do relatório em PDF, quando a análise completa termina",
        "security": [
          {
            "agentKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "url, filename, expires_in_seconds"
          },
          "400": {
            "description": "Entrada inválida",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inexistente ou revogada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Ainda não pronto",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Limite atingido (veja retry_after)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/diagnostics/{id}/presentation": {
      "get": {
        "operationId": "getPresentationLink",
        "summary": "Link assinado (60 s) da apresentação em PDF para a diretoria (16:9), quando a análise completa termina",
        "security": [
          {
            "agentKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "url, filename, expires_in_seconds"
          },
          "400": {
            "description": "Entrada inválida",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inexistente ou revogada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Ainda não pronta",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Limite atingido (veja retry_after)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "retry_after": {
                          "type": "integer",
                          "description": "Segundos até tentar de novo."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/checks": {
      "get": {
        "operationId": "listChecks",
        "summary": "Catálogo das verificações: o que é, por que importa, fonte e tipo de correção",
        "responses": {
          "200": {
            "description": "checks[], improvements[], resolutions"
          }
        }
      }
    }
  }
}