{
  "openapi": "3.0.3",
  "info": {
    "title": "Trunko API",
    "version": "1.0.0",
    "description": "API pública do Trunko — consulte seus conectores, uso e chamadas. Autentique com uma chave (Configurações → API) em Authorization: Bearer trkpk_… ou no header x-api-key."
  },
  "servers": [
    {
      "url": "https://trunko.com.br/api/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {
      "apiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "chave trkpk_…"
      },
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    }
  },
  "paths": {
    "/me": {
      "get": {
        "operationId": "me",
        "summary": "Valida a chave e resume a conta",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "org": {
                      "type": "object"
                    },
                    "connectors": {
                      "type": "integer"
                    },
                    "tools": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/stats": {
      "get": {
        "operationId": "stats",
        "summary": "Números da plataforma (conectores, ferramentas, chamadas hoje e total)",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connectors": {
                      "type": "integer"
                    },
                    "tools": {
                      "type": "integer"
                    },
                    "callsToday": {
                      "type": "integer"
                    },
                    "callsTotal": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/connectors": {
      "get": {
        "operationId": "listConnectors",
        "summary": "Lista seus conectores com saúde, uso e ferramentas",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connectors": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createConnector",
        "summary": "Cria um conector (devolve o token MCP uma vez)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "baseUrl",
                  "tools"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "baseUrl": {
                    "type": "string"
                  },
                  "auth": {
                    "type": "object",
                    "description": "ex.: { \"type\": \"bearer\", \"value\": \"…\" } — type: none|bearer|header|query|body|oauth2"
                  },
                  "tools": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "name",
                        "path"
                      ],
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "method": {
                          "type": "string"
                        },
                        "path": {
                          "type": "string"
                        },
                        "description": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "criado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "endpoint": {
                      "type": "string"
                    },
                    "token": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/connectors/{id}": {
      "delete": {
        "operationId": "deleteConnector",
        "summary": "Apaga um conector e o histórico de chamadas",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "id do conector (conn_…)"
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/connectors/{id}/calls": {
      "get": {
        "operationId": "connectorCalls",
        "summary": "Chamadas recentes de um conector",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "id do conector (conn_…)"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "máx. de chamadas (1–200, padrão 50)"
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connector": {
                      "type": "object"
                    },
                    "calls": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/usage": {
      "get": {
        "operationId": "usage",
        "summary": "Uso agregado de 14 dias (por conector, origem e hora)",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "days": {
                      "type": "integer"
                    },
                    "byConnector": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "byHour": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}