{
  "openapi": "3.1.0",
  "info": {
    "title": "CastDeck Local API",
    "version": "1.0.0",
    "description": "API local do CastDeck para integrar o estúdio com Stream Deck, Home Assistant, Node-RED, scripts e agentes de IA. Requisições de localhost não precisam de chave; de outro computador use Authorization: Bearer <chave> (veja em GET /api/v1). Ações de palco exigem o estúdio aberto no navegador.",
    "license": {
      "name": "AGPL-3.0-only",
      "url": "https://www.gnu.org/licenses/agpl-3.0.txt"
    }
  },
  "servers": [
    {
      "url": "http://localhost:3000/api/v1",
      "description": "app local (a porta pode variar)"
    }
  ],
  "components": {
    "securitySchemes": {
      "chave": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Acao": {
        "type": "object",
        "required": [
          "tipo"
        ],
        "properties": {
          "tipo": {
            "type": "string",
            "enum": [
              "overlay.show",
              "overlay.hide",
              "chat.send",
              "scene.set",
              "mixer.setVolume",
              "mixer.mute",
              "media.play",
              "media.stop",
              "stage.add",
              "stage.remove"
            ]
          },
          "titulo": {
            "type": "string",
            "description": "overlay.show"
          },
          "texto": {
            "type": "string",
            "description": "overlay.show / chat.send"
          },
          "cor": {
            "type": "string",
            "description": "overlay.show (#hex)"
          },
          "segundos": {
            "type": "number",
            "description": "overlay.show (1..60)"
          },
          "layout": {
            "type": "string",
            "description": "scene.set (grid, solo, leader, sidebar, pip, split)"
          },
          "fonte": {
            "type": "string",
            "description": "mixer.* / media.* / stage.* (id da fonte)"
          },
          "volume": {
            "type": "number",
            "description": "mixer.setVolume (0..1)"
          },
          "on": {
            "type": "boolean",
            "description": "mixer.mute / stage.add/remove"
          }
        }
      }
    }
  },
  "security": [
    {
      "chave": []
    }
  ],
  "paths": {
    "/": {
      "get": {
        "summary": "Informações e descoberta",
        "security": [],
        "responses": {
          "200": {
            "description": "Info",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "summary": "Este documento",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI"
          }
        }
      }
    },
    "/status": {
      "get": {
        "summary": "Versão, estúdios abertos, plugins e sistema",
        "responses": {
          "200": {
            "description": "Estado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/studios": {
      "get": {
        "summary": "Lista de estúdios",
        "responses": {
          "200": {
            "description": "Estúdios"
          }
        }
      }
    },
    "/studios/{id}": {
      "get": {
        "summary": "Detalhe do estúdio",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Estúdio"
          },
          "404": {
            "description": "Não encontrado"
          }
        }
      }
    },
    "/studios/{id}/action": {
      "post": {
        "summary": "Executa uma ação no estúdio aberto",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Acao"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ação enviada"
          },
          "400": {
            "description": "Ação inválida"
          },
          "409": {
            "description": "Estúdio fechado"
          }
        }
      }
    },
    "/events": {
      "get": {
        "summary": "Fluxo de eventos (SSE)",
        "security": [],
        "responses": {
          "200": {
            "description": "text/event-stream"
          }
        }
      }
    }
  }
}
