{
  "openapi": "3.1.0",
  "info": {
    "title": "FIA Copilot API",
    "version": "1.0.0",
    "description": "API programática de FIA Copilot. Acceso para planes pagos vía API key. Cada key accede solo a la data de su dueño."
  },
  "servers": [{ "url": "https://fiacopilot.com/api/v1" }],
  "security": [{ "bearerAuth": [] }, { "apiKeyHeader": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "Authorization: Bearer fia_sk_…" },
      "apiKeyHeader": { "type": "apiKey", "in": "header", "name": "X-API-Key" }
    },
    "responses": {
      "Unauthorized": { "description": "Falta o es inválida la API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Forbidden": { "description": "Scope insuficiente o rol no autorizado", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "NotFound": { "description": "No existe o no es tuyo", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    },
    "schemas": {
      "Error": { "type": "object", "properties": { "error": { "type": "string" } }, "required": ["error"] },
      "Page": { "type": "object", "properties": { "limit": { "type": "integer" }, "offset": { "type": "integer" }, "total": { "type": ["integer", "null"] } } },
      "MemoryItem": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "title": { "type": ["string", "null"] },
          "content": { "type": "string" },
          "content_type": { "type": "string", "enum": ["general", "context_business", "context_personal", "context_ai_memory", "context_process", "context_prompt", "ai_response", "resource"] },
          "tags": { "type": ["array", "null"], "items": { "type": "string" } },
          "is_starred": { "type": "boolean" },
          "capsule_id": { "type": ["string", "null"] },
          "created_at": { "type": "string" },
          "updated_at": { "type": "string" }
        }
      },
      "TeamMember": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": ["string", "null"] },
          "org_role": { "type": ["string", "null"] },
          "capsules_started": { "type": "integer" },
          "capsules_done": { "type": "integer" },
          "last_activity": { "type": ["string", "null"] },
          "vault_outputs": { "type": "integer" },
          "joined_at": { "type": ["string", "null"] },
          "classification": { "type": "string", "enum": ["comprometido", "constante", "en_riesgo", "abandonando", "sin_empezar"] },
          "days_inactive": { "type": ["integer", "null"] }
        }
      }
    }
  },
  "paths": {
    "/me": {
      "get": { "summary": "Identidad del dueño de la key", "operationId": "getMe", "responses": { "200": { "description": "OK" }, "401": { "$ref": "#/components/responses/Unauthorized" } } }
    },
    "/memory": {
      "get": {
        "summary": "Lista la memoria", "operationId": "listMemory",
        "parameters": [
          { "name": "type", "in": "query", "schema": { "type": "string" } },
          { "name": "starred", "in": "query", "schema": { "type": "string", "enum": ["true"] } },
          { "name": "tag", "in": "query", "schema": { "type": "string" } },
          { "name": "capsule_id", "in": "query", "schema": { "type": "string" } },
          { "name": "q", "in": "query", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50, "maximum": 200 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0 } }
        ],
        "responses": { "200": { "description": "Lista de items", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/MemoryItem" } }, "page": { "$ref": "#/components/schemas/Page" } } } } } }, "401": { "$ref": "#/components/responses/Unauthorized" }, "403": { "$ref": "#/components/responses/Forbidden" } }
      },
      "post": {
        "summary": "Crea un item de memoria", "operationId": "createMemory",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["content"], "properties": { "content": { "type": "string" }, "title": { "type": "string" }, "content_type": { "type": "string" }, "tags": { "type": "array", "items": { "type": "string" } }, "is_starred": { "type": "boolean" } } } } } },
        "responses": { "201": { "description": "Creado" }, "400": { "description": "Datos inválidos" }, "401": { "$ref": "#/components/responses/Unauthorized" }, "403": { "$ref": "#/components/responses/Forbidden" } }
      }
    },
    "/memory/{id}": {
      "get": { "summary": "Un item de memoria", "operationId": "getMemory", "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }], "responses": { "200": { "description": "OK" }, "404": { "$ref": "#/components/responses/NotFound" } } }
    },
    "/processes": {
      "get": { "summary": "Procesos (memoria context_process)", "operationId": "listProcesses", "responses": { "200": { "description": "OK" }, "403": { "$ref": "#/components/responses/Forbidden" } } }
    },
    "/capsules": {
      "get": { "summary": "Catálogo de cápsulas + paths", "operationId": "listCapsules", "responses": { "200": { "description": "OK" } } }
    },
    "/capsules/progress": {
      "get": { "summary": "Tu progreso en cápsulas", "operationId": "myProgress", "responses": { "200": { "description": "OK" } } }
    },
    "/briefings": {
      "get": { "summary": "Lista tus briefings", "operationId": "listBriefings", "responses": { "200": { "description": "OK" }, "403": { "$ref": "#/components/responses/Forbidden" } } },
      "post": {
        "summary": "Crea un briefing", "operationId": "createBriefing",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["title"], "properties": { "title": { "type": "string" }, "instructions": { "type": "string" }, "included_outputs": { "type": "array", "items": { "type": "string" } }, "included_business_context": { "type": "array", "items": { "type": "string" } }, "include_profile": { "type": "boolean" }, "include_diagnostico": { "type": "boolean" }, "expires_at": { "type": ["string", "null"] }, "max_views": { "type": ["integer", "null"] }, "password": { "type": ["string", "null"] }, "public_on_profile": { "type": "boolean" } } } } } },
        "responses": { "201": { "description": "Creado (devuelve id, token, url)" }, "400": { "description": "title_required" }, "403": { "$ref": "#/components/responses/Forbidden" } }
      }
    },
    "/briefings/{id}": {
      "get": { "summary": "Un briefing", "operationId": "getBriefing", "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }], "responses": { "200": { "description": "OK" }, "404": { "$ref": "#/components/responses/NotFound" } } },
      "patch": { "summary": "Edita/revoca un briefing", "operationId": "updateBriefing", "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }], "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string", "enum": ["active", "revoked"] }, "instructions": { "type": "string" }, "expires_at": { "type": ["string", "null"] }, "max_views": { "type": ["integer", "null"] }, "public_on_profile": { "type": "boolean" } } } } } }, "responses": { "200": { "description": "OK" }, "404": { "$ref": "#/components/responses/NotFound" } } }
    },
    "/briefings/{id}/executions": {
      "get": { "summary": "Logs de ejecución del briefing", "operationId": "listExecutions", "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }], "responses": { "200": { "description": "OK" }, "404": { "$ref": "#/components/responses/NotFound" } } },
      "post": { "summary": "Deja un log de ejecución", "operationId": "createExecution", "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["summary"], "properties": { "summary": { "type": "string" }, "agent": { "type": "string" }, "output": { "type": "string" } } } } } }, "responses": { "201": { "description": "Creado" }, "404": { "$ref": "#/components/responses/NotFound" } } }
    },
    "/team": {
      "get": { "summary": "Roster del equipo + resumen", "operationId": "teamOverview", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/TeamMember" } }, "page": { "$ref": "#/components/schemas/Page" }, "summary": { "type": "object" } } } } } }, "403": { "$ref": "#/components/responses/Forbidden" } } }
    },
    "/team/{memberId}": {
      "get": { "summary": "Detalle de un miembro", "operationId": "teamMember", "parameters": [{ "name": "memberId", "in": "path", "required": true, "schema": { "type": "string" } }], "responses": { "200": { "description": "OK" }, "403": { "$ref": "#/components/responses/Forbidden" }, "404": { "$ref": "#/components/responses/NotFound" } } }
    }
  }
}
