# Horus API — OpenAPI 3.1
# Gerado a partir do código do backend Go (backend/internal/app/app.go + módulos).
# Guia legível: docs/api/README.md (https://horusacs.com.br/docs/api).
openapi: "3.1.0"
info:
  title: "Horus API"
  version: "1.0.0"
  summary: "API REST do Horus (ACS TR-069, OLTs e ERP) para provedores."
  description: |-
    Guia completo: [README](./README.md) (também em https://horusacs.com.br/docs/api).

    - Base: `https://app.horusacs.com.br`, todos os caminhos sob `/api/v1`.
    - Autenticação: `Authorization: Bearer acsd_<48 hex>` (API key) ou JWT de sessão. O tenant sai da credencial.
    - Cada operação traz `x-required-permissions` (escopos) e `x-api-key` (false = só sessão de usuário). Com `x-permissions-mode: any`, basta um dos escopos listados.
    - Envelope de sucesso `{"data": ...}`; listas paginadas `{"data": [...], "meta": {...}}`; exceções `{items, pagination}` em `/devices`, `/devices/{id}/queue` e `/tasks`.
    - Erros `{"error": "..."}`; validação 422 `{"error": "validation_failed", "fields": {...}}`.
    - Limite: 600 requisições/min por API key (429 + `Retry-After`).
servers:
  - url: "https://app.horusacs.com.br"
    description: "Produção"
security:
  - bearer: []
tags:
  - name: "Conta e plano"
    description: "Quem é a credencial, tenant, plano, papéis e identidade visual."
  - name: "CPEs (dispositivos)"
    description: "Roteadores/ONTs gerenciados por TR-069: leitura, Wi-Fi, WAN, diagnósticos e ações."
  - name: "Integrações"
    description: "Busca do CPE do cliente a partir de dados do ERP/app."
  - name: Tarefas
    description: "Fila de operações remotas (RPCs TR-069). Escritas no CPE são assíncronas."
  - name: Alertas
    description: "Alertas de CPE, ONU e PON."
  - name: Incidentes
    description: "Incidentes de rede correlacionados (PON/placa/OLT)."
  - name: "Manutenção"
    description: "Janelas de manutenção programada."
  - name: "OLTs, PONs e ONUs"
    description: "Rede óptica: leitura, triangulação e provisionamento de ONU."
  - name: CTOs
    description: "Caixas de terminação óptica e portas."
  - name: Webhooks
    description: "Assinaturas de eventos de saída (HMAC-SHA256)."
  - name: "ERP (IXC, HubSoft, Thothix)"
    description: "Integração com o sistema de gestão do provedor."
  - name: "Importação e OLT Cloud"
    description: "Migração (GenieACS, OLT Cloud) e sincronização contínua."
  - name: Campanhas
    description: "Configuração em massa com piloto e ondas."
  - name: Firmware
    description: "Catálogo e upload de firmware."
  - name: "Relatórios e dashboard"
    description: "KPIs e relatórios (JSON, sem paginação)."
  - name: Outros
    description: "Auditoria, catálogo de parâmetros, presets, reinício/restauração automáticos, notificações, autorregistro e configurações."
  - name: "Somente sessão de usuário"
    description: "Rotas que nunca aceitam API key (403), qualquer que seja o escopo."
paths:
  /api/v1/auth/me:
    get:
      tags:
        - "Conta e plano"
      summary: "Quem sou eu (whoami)"
      description: |-
        **Permissão:** qualquer credencial autenticada.

        Com API key devolve `auth_type: api_key`, `email: api-key:<nome>` e `permissions` = escopos efetivos da chave.
      x-required-permissions: []
      x-api-key: true
      operationId: get_auth_me
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Me"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/settings/system:
    get:
      tags:
        - "Conta e plano"
      summary: "Tenant, plano e uso"
      description: |-
        **Permissão:** qualquer credencial autenticada.

        Status do tenant, plano, assinantes em uso (`plan_usage`) e modos de operação. O limite do plano só avisa; nada é bloqueado.
      x-required-permissions: []
      x-api-key: true
      operationId: get_settings_system
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/SystemInfo"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/roles:
    get:
      tags:
        - "Conta e plano"
      summary: "Listar papéis"
      description: "**Permissão:** `roles:read`."
      x-required-permissions:
        - "roles:read"
      x-api-key: true
      operationId: get_roles
      parameters:
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Role"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Criar papel"
      description: |-
        **Permissão:** `roles:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "roles:manage"
      x-api-key: false
      operationId: post_roles
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/roles/{id}":
    get:
      tags:
        - "Conta e plano"
      summary: "Detalhe do papel"
      description: "**Permissão:** `roles:read`."
      x-required-permissions:
        - "roles:read"
      x-api-key: true
      operationId: get_roles_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    allOf:
                      - "$ref": "#/components/schemas/Role"
                      - type: object
                        properties:
                          permissions:
                            type: array
                            items:
                              type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    patch:
      tags:
        - "Somente sessão de usuário"
      summary: "Alterar papel"
      description: |-
        **Permissão:** `roles:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "roles:manage"
      x-api-key: false
      operationId: patch_roles_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - "Somente sessão de usuário"
      summary: "Remover papel"
      description: |-
        **Permissão:** `roles:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "roles:manage"
      x-api-key: false
      operationId: delete_roles_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/permissions:
    get:
      tags:
        - "Conta e plano"
      summary: "Catálogo de permissões"
      description: |-
        **Permissão:** `roles:read`.

        Lista sem paginação.
      x-required-permissions:
        - "roles:read"
      x-api-key: true
      operationId: get_permissions
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Permission"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/branding:
    get:
      tags:
        - "Conta e plano"
      summary: "Ler identidade visual"
      description: "**Permissão:** `branding:read`."
      x-required-permissions:
        - "branding:read"
      x-api-key: true
      operationId: get_branding
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Branding"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    patch:
      tags:
        - "Conta e plano"
      summary: "Alterar identidade visual"
      description: |-
        **Permissão:** `branding:manage`.

        Exige o recurso `own_branding` do plano (senão 403 `plan_feature_unavailable: ...`).
      x-required-permissions:
        - "branding:manage"
      x-api-key: true
      operationId: patch_branding
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                app_name:
                  type: string
                  maxLength: 100
                primary_color:
                  type: string
                  description: "#RRGGBB"
                secondary_color:
                  type: string
                custom_domain:
                  type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Branding"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/devices:
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Listar CPEs"
      description: |-
        **Permissão:** `devices:read`.

        Envelope próprio: `{items, pagination}` (não `data`). Ordem: último Inform mais recente primeiro.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices
      parameters:
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PageSize"
        - "$ref": "#/components/parameters/PerPage"
        - name: q
          in: query
          schema:
            type: string
          description: "Busca parcial (sem diferenciar maiúsculas) em serial, OUI, product_class, IP, nome do cliente e login PPPoE. Alias legado `search`."
        - name: status
          in: query
          schema:
            type: string
            enum:
              - unknown
              - online
              - offline
              - provisioning
              - error
        - name: oui
          in: query
          schema:
            type: string
          description: "Lista de OUIs separada por vírgula."
        - name: vendor
          in: query
          schema:
            type: string
          description: "Legado: OUI de 6 hex ou nome (huawei, zte, tp-link, intelbras, ...). Ignorado se `oui` vier."
        - name: tag
          in: query
          schema:
            type: string
          description: "Etiqueta exata (minúsculas)."
        - name: plan
          in: query
          schema:
            type: string
          description: "Nome exato do plano do cliente (ERP)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      "$ref": "#/components/schemas/DeviceListItem"
                  pagination:
                    "$ref": "#/components/schemas/ItemsPagination"
                required:
                  - items
                  - pagination
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Cadastrar CPE"
      description: |-
        **Permissão:** `devices:create`.

        Normalmente o CPE se cadastra sozinho no primeiro Inform; use isto para pré-cadastro. 409 se o serial já existe no tenant.
      x-required-permissions:
        - "devices:create"
      x-api-key: true
      operationId: post_devices
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                serial_number:
                  type: string
                  minLength: 1
                  maxLength: 200
                oui:
                  type: string
                  minLength: 6
                  maxLength: 6
                product_class:
                  type: string
                  maxLength: 200
                model_id:
                  type: string
                  format: uuid
                tags:
                  type: array
                  items:
                    type: string
                    maxLength: 50
                  maxItems: 20
                notes:
                  type: string
                  maxLength: 1000
              required:
                - serial_number
                - oui
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Device"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/devices/tags:
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Etiquetas em uso"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_tags
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        tag:
                          type: string
                        count:
                          type: integer
                          format: int64
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/devices/import-labels:
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Importar etiquetas e notas por serial"
      description: |-
        **Permissão:** `devices:update`.

        Até 5000 linhas; nunca cria CPE. Use `dry_run` para conferir.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_import_labels
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                dry_run:
                  type: boolean
                tags_mode:
                  type: string
                  enum:
                    - replace
                    - add
                  default: replace
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      serial_number:
                        type: string
                      tags:
                        type: array
                        items:
                          type: string
                      notes:
                        type:
                          - string
                          - "null"
                  maxItems: 5000
              required:
                - rows
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      dry_run:
                        type: boolean
                      total:
                        type: integer
                      updated:
                        type: integer
                      unchanged:
                        type: integer
                      not_found:
                        type: integer
                      invalid:
                        type: integer
                      duplicate:
                        type: integer
                      rows:
                        type: array
                        items:
                          type: object
                          properties:
                            line:
                              type: integer
                            serial_number:
                              type: string
                            status:
                              type: string
                              enum:
                                - updated
                                - unchanged
                                - not_found
                                - invalid
                                - duplicate
                            message:
                              type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Detalhe do CPE"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Device"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    patch:
      tags:
        - "CPEs (dispositivos)"
      summary: "Alterar etiquetas/notas do CPE"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: patch_devices_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                model_id:
                  type: string
                  format: uuid
                provisioning_profile_id:
                  type: string
                  format: uuid
                tags:
                  type: array
                  items:
                    type: string
                  description: "Substitui todas."
                notes:
                  type: string
                  maxLength: 1000
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Device"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - "CPEs (dispositivos)"
      summary: "Remover CPE (soft delete)"
      description: "**Permissão:** `devices:delete`."
      x-required-permissions:
        - "devices:delete"
      x-api-key: true
      operationId: delete_devices_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/operational-view":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Visão operacional do CPE"
      description: |-
        **Permissão:** `devices:read`.

        Resumo para tela de atendimento: `device`, `health_summary`, `traffic_summary`, `signal_summary`, `last_session`, `last_tasks` (5), `key_parameters`, `connection_request`.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_operational_view
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      device:
                        type: object
                        properties: {}
                      health_summary:
                        type: object
                        properties:
                          health_score:
                            type: integer
                          download_mbps:
                            type: number
                          upload_mbps:
                            type: number
                          rx_power_dbm:
                            type: number
                          tx_power_dbm:
                            type: number
                          wifi_status:
                            type: string
                            enum:
                              - active
                              - inactive
                              - unknown
                          memory_usage_pct:
                            type:
                              - number
                              - "null"
                          cpu_usage_pct:
                            type:
                              - number
                              - "null"
                      traffic_summary:
                        type: object
                        properties: {}
                      signal_summary:
                        type: object
                        properties:
                          current_rx_power_dbm:
                            type: number
                          current_tx_power_dbm:
                            type: number
                      last_session:
                        oneOf:
                          - "$ref": "#/components/schemas/SessionInfo"
                          - type: "null"
                      last_tasks:
                        type: array
                        items:
                          type: object
                          properties:
                            id:
                              type: string
                              format: uuid
                            type:
                              type: string
                            status:
                              type: string
                            created_at:
                              type: string
                              format: date-time
                            completed_at:
                              type:
                                - string
                                - "null"
                              format: date-time
                            attempts_count:
                              type: integer
                      key_parameters:
                        type: object
                        properties: {}
                        additionalProperties:
                          type:
                            - string
                            - "null"
                      connection_request:
                        type:
                          - object
                          - "null"
                        properties:
                          status:
                            type: string
                          last_status_code:
                            type:
                              - integer
                              - "null"
                          last_error:
                            type:
                              - string
                              - "null"
                          last_attempt_at:
                            type:
                              - string
                              - "null"
                            format: date-time
                          last_auth_method:
                            type:
                              - string
                              - "null"
                          last_duration_ms:
                            type:
                              - integer
                              - "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/parameters":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Parâmetros TR-069 (lista, árvore ou busca)"
      description: |-
        **Permissão:** `devices:read`.

        O modo depende de quais parâmetros vêm na URL:

        - nenhum → lista plana `[Parameter]` (todos os parâmetros, valores crus);
        - `prefix` → `{mode: "tree", prefix, nodes, truncated}`;
        - `q` → `{mode: "search", prefix, q, nodes, truncated}`.

        Nos modos árvore e busca, senhas saem como `********` (`secret: true`).
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_parameters
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - name: prefix
          in: query
          schema:
            type: string
          description: "Modo árvore: `\"\"` (raízes) ou caminho de objeto terminado em `.`. Devolve só os filhos diretos (máx. 5000)."
        - name: q
          in: query
          schema:
            type: string
          description: "Modo busca (2–256 caracteres) em caminho e valor; combina com `prefix`."
        - name: limit
          in: query
          schema:
            type: integer
            default: 200
            maximum: 1000
          description: "Só no modo busca."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    oneOf:
                      - type: array
                        items:
                          "$ref": "#/components/schemas/Parameter"
                      - type: object
                        properties:
                          mode:
                            type: string
                            enum:
                              - tree
                              - search
                          prefix:
                            type: string
                          q:
                            type: string
                          nodes:
                            type: array
                            items:
                              "$ref": "#/components/schemas/ParamNode"
                          truncated:
                            type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/parameters/export":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Exportar parâmetros (JSON ou CSV)"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_parameters_export
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - name: format
          in: query
          schema:
            type: string
            enum:
              - json
              - csv
          description: "Padrão JSON."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Parameter"
                required:
                  - data
            text/csv:
              schema:
                type: string
                description: "Colunas: path,value,writable,type,notification,access_list,fetched_at"
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/parameters/refresh":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Reler parâmetro ou subárvore do CPE"
      description: |-
        **Permissão:** `devices:update`.

        Cria uma tarefa (`get_param_values`, ou `custom` para objeto terminado em `.`) e dispara Connection Request. Se já houver a mesma leitura ativa, reaproveita (`already_pending: true`).
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_parameters_refresh
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                path:
                  type: string
                  description: "Caminho TR-069 sob `InternetGatewayDevice.` ou `Device.`"
              required:
                - path
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type: string
                        format: uuid
                      task_type:
                        type: string
                        enum:
                          - custom
                          - get_param_values
                      path:
                        type: string
                      already_pending:
                        type: boolean
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      pending:
                        type: boolean
                      message:
                        type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/parameters/set":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Gravar um parâmetro"
      description: |-
        **Permissão:** `devices:update` e `tasks:create`.

        Exige os dois escopos. O parâmetro precisa existir e ser gravável no CPE (senão 404/409). WAN só com `ACS_WAN_WRITE_MODE=enabled` (senão 403). `*.ManagementServer.*` exige `confirm_management_server: true` (senão 428).
      x-required-permissions:
        - "devices:update"
        - "tasks:create"
      x-api-key: true
      operationId: post_devices_id_parameters_set
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                value:
                  type: string
                  maxLength: 4096
                type:
                  type: string
                  description: "Opcional; deve bater com o tipo do CPE."
                confirm_management_server:
                  type: boolean
              required:
                - name
                - value
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type: string
                        format: uuid
                      name:
                        type: string
                      type:
                        type: string
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      pending:
                        type: boolean
                      message:
                        type: string
                required:
                  - data
        "428":
          description: "Falta `confirm_management_server`."
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/Error"
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/wifi":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Ler Wi-Fi (rádios e SSIDs)"
      description: |-
        **Permissão:** `devices:read`.

        Não devolve senha; só `password_available`. Para ver a senha use `/wifi-passwords`.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_wifi
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      radios:
                        type: array
                        items:
                          "$ref": "#/components/schemas/WifiRadio"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/wifi-passwords":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Revelar senhas do Wi-Fi"
      description: |-
        **Permissão:** `devices:update`.

        Exige `devices:update` porque devolve segredo. Cada chamada fica na trilha de auditoria (`device.view_wifi_password`). `password` é null quando o CPE mascara a senha.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: get_devices_id_wifi_passwords
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - name: band
          in: query
          schema:
            type: string
            enum:
              - "2.4ghz"
              - "5ghz"
          description: "Opcional: uma banda só."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      passwords:
                        type: array
                        items:
                          type: object
                          properties:
                            wlan_index:
                              type: integer
                            band:
                              type: string
                            ssid:
                              type:
                                - string
                                - "null"
                            password:
                              type:
                                - string
                                - "null"
                            param_key:
                              type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/update-wifi":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Trocar SSID e/ou senha do Wi-Fi"
      description: |-
        **Permissão:** `devices:update`.

        Mande só o que muda (ao menos um campo). SSID: 1–32 bytes; senha: 8–63 ASCII imprimíveis ou 64 hex. Cria uma tarefa `set_param_values` e dispara Connection Request.

        `code`: `applying` (CPE acionado), `queued_next_inform` (aplica na próxima conexão) ou `skipped_pending_task` (já há leitura pendente; nada foi criado, tente de novo em alguns minutos).
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_update_wifi
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ssid_24:
                  type: string
                ssid_5:
                  type: string
                password_24:
                  type: string
                  writeOnly: true
                password_5:
                  type: string
                  writeOnly: true
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type:
                          - string
                          - "null"
                        format: uuid
                      parameter_count:
                        type: integer
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      skipped:
                        type: boolean
                      skip_reason:
                        type: string
                      pending:
                        type: boolean
                      message:
                        type: string
                      code:
                        type: string
                        enum:
                          - applying
                          - queued_next_inform
                          - skipped_pending_task
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/hosts":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Dispositivos conectados"
      description: |-
        **Permissão:** `devices:read`.

        Foto da última leitura; para atualizar chame `POST /refresh-hosts` antes.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_hosts
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      hosts:
                        type: array
                        items:
                          "$ref": "#/components/schemas/ConnectedHost"
                      total:
                        type: integer
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/refresh-hosts":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Atualizar dispositivos conectados"
      description: |-
        **Permissão:** `devices:update`.

        Cria leitura dos hosts + Connection Request. Se houve leitura há menos de 2 min, devolve `skipped: true` (`hosts refreshed recently`) sem criar nada.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_refresh_hosts
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type:
                          - string
                          - "null"
                        format: uuid
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      already_pending:
                        type: boolean
                      skipped:
                        type: boolean
                      skip_reason:
                        type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/network":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Rede (WAN/LAN) resumida"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_network
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      wan:
                        type: object
                        properties:
                          wan_ip:
                            type:
                              - string
                              - "null"
                          gateway:
                            type:
                              - string
                              - "null"
                          dns:
                            type: array
                            items:
                              type: string
                          ipv6:
                            type:
                              - string
                              - "null"
                          connection_type:
                            type: string
                            enum:
                              - dhcp
                              - pppoe
                              - static
                              - unknown
                      lan:
                        type: object
                        properties:
                          lan_ip:
                            type:
                              - string
                              - "null"
                          subnet:
                            type:
                              - string
                              - "null"
                          dhcp_enabled:
                            type:
                              - boolean
                              - "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/refresh-network":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Atualizar dados de rede"
      description: |-
        **Permissão:** `devices:update`.

        Mesma lógica de `refresh-hosts` (pulo de 2 min: `network refreshed recently`).
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_refresh_network
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type:
                          - string
                          - "null"
                        format: uuid
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      already_pending:
                        type: boolean
                      skipped:
                        type: boolean
                      skip_reason:
                        type: string
                      pending:
                        type: boolean
                      message:
                        type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/wan-connections":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Conexões WAN"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_wan_connections
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      connections:
                        type: array
                        items:
                          "$ref": "#/components/schemas/WANConnection"
                      write_mode:
                        type: string
                        enum:
                          - read_only
                          - enabled
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/update-wan":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Alterar conexão WAN"
      description: |-
        **Permissão:** `devices:update`.

        403 se o ambiente estiver com escrita WAN desligada (`write_mode: read_only`). `connection_path` vem de `GET /wan-connections`.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_update_wan
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                connection_path:
                  type: string
                wan_ip:
                  type: string
                gateway:
                  type: string
                dns1:
                  type: string
                dns2:
                  type: string
                service_list:
                  type: string
                vlan:
                  type: string
              required:
                - connection_path
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type:
                          - string
                          - "null"
                        format: uuid
                      connection_path:
                        type: string
                      parameter_count:
                        type: integer
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      skipped:
                        type: boolean
                      skip_reason:
                        type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/delete-wan":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Apagar conexão WAN"
      description: |-
        **Permissão:** `devices:update`.

        Irreversível. Mesmas regras de `update-wan`.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_delete_wan
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                connection_path:
                  type: string
              required:
                - connection_path
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type:
                          - string
                          - "null"
                        format: uuid
                      connection_path:
                        type: string
                      deleted_object:
                        type: string
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      skipped:
                        type: boolean
                      skip_reason:
                        type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/reboot-now":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Reiniciar CPE agora"
      description: |-
        **Permissão:** `devices:update`.

        Cria tarefa `reboot` e dispara Connection Request. Se já houver reboot pendente, devolve `already_pending: true` e `task_id: null`.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_reboot_now
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type:
                          - string
                          - "null"
                        format: uuid
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      already_pending:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/connection-request":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Acordar o CPE (Connection Request)"
      description: |-
        **Permissão:** `devices:update`.

        Sempre 200; veja `success`/`status` no corpo.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_connection_request
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/ConnectionRequestResult"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/run-discovery":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Descoberta completa da árvore"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_run_discovery
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      tasks_created:
                        type: integer
                      task_ids:
                        type: array
                        items:
                          type: string
                          format: uuid
                        description: "Pode vir null."
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                      already_pending:
                        type: boolean
                      skipped:
                        type: boolean
                      skip_reason:
                        type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/active-notification":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Ligar notificação ativa (WAN/óptico)"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_active_notification
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      task_id:
                        type: string
                        format: uuid
                      parameters:
                        type: array
                        items:
                          type: string
                      connection_request:
                        "$ref": "#/components/schemas/ConnectionRequestResult"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/restore":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Restaurar configuração conhecida"
      description: |-
        **Permissão:** `devices:update`.

        Reaplica PPPoE/Wi-Fi/presets guardados (ex.: depois de reset de fábrica). 409 se já houver restauração rodando; 422 se não há nada a restaurar.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_restore
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      restoration_id:
                        type: string
                        format: uuid
                      status:
                        type: string
                        enum:
                          - running
                          - failed
                      reason:
                        type: string
                      task_ids:
                        type: array
                        items:
                          type: string
                          format: uuid
                      params:
                        type: array
                        items:
                          type: string
                      skipped_params:
                        type: array
                        items:
                          type: string
                      connection_request:
                        oneOf:
                          - "$ref": "#/components/schemas/ConnectionRequestResult"
                          - type: "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/diagnostics/ping":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Disparar ping"
      description: |-
        **Permissão:** `devices:update`.

        Assíncrono: cria tarefa SPV `DiagnosticsState=Requested` + Connection Request. Consulte o GET correspondente até `state` sair de `Requested`.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_diagnostics_ping
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                host:
                  type: string
                count:
                  type: integer
                  minimum: 1
                  maximum: 20
                  default: 4
                timeout:
                  type: integer
                  minimum: 1
                  maximum: 30000
                  default: 5000
                  description: ms
              required:
                - host
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/DiagnosticTrigger"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Resultado do ping"
      description: |-
        **Permissão:** `devices:read`.

        Se o estado ainda é `Requested`, a consulta também pede a leitura do resultado ao CPE.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_diagnostics_ping
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      state:
                        type: string
                        description: "None, Requested, Complete ou Error_*"
                      host:
                        type: string
                      success_count:
                        type: integer
                      failure_count:
                        type: integer
                      average_response_time:
                        type: integer
                        description: ms
                      minimum_response_time:
                        type: integer
                      maximum_response_time:
                        type: integer
                      run:
                        "$ref": "#/components/schemas/DiagnosticRun"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/diagnostics/traceroute":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Disparar traceroute"
      description: |-
        **Permissão:** `devices:update`.

        Assíncrono: cria tarefa SPV `DiagnosticsState=Requested` + Connection Request. Consulte o GET correspondente até `state` sair de `Requested`.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_diagnostics_traceroute
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                host:
                  type: string
                  maxLength: 256
                max_hops:
                  type: integer
                  minimum: 1
                  maximum: 64
                  default: 30
                timeout:
                  type: integer
                  minimum: 100
                  maximum: 30000
                  default: 5000
                tries:
                  type: integer
                  minimum: 1
                  maximum: 5
                  default: 3
              required:
                - host
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/DiagnosticTrigger"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Resultado do traceroute"
      description: |-
        **Permissão:** `devices:read`.

        Se o estado ainda é `Requested`, a consulta também pede a leitura do resultado ao CPE.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_diagnostics_traceroute
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      state:
                        type: string
                      host:
                        type: string
                      response_time:
                        type: integer
                      hops:
                        type: array
                        items:
                          type: object
                          properties:
                            index:
                              type: integer
                            host:
                              type:
                                - string
                                - "null"
                            address:
                              type:
                                - string
                                - "null"
                            error_code:
                              type:
                                - integer
                                - "null"
                            rt_times:
                              type: array
                              items:
                                type: integer
                      reached:
                        type: boolean
                      run:
                        "$ref": "#/components/schemas/DiagnosticRun"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/diagnostics/speed-test":
    post:
      tags:
        - "CPEs (dispositivos)"
      summary: "Disparar speed-test"
      description: |-
        **Permissão:** `devices:update`.

        Assíncrono: cria tarefa SPV `DiagnosticsState=Requested` + Connection Request. Consulte o GET correspondente até `state` sair de `Requested`. O servidor de teste vem de `/settings/speed-test` (400 se não configurado).
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_devices_id_diagnostics_speed_test
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                direction:
                  type: string
                  enum:
                    - download
                    - upload
              required:
                - direction
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/DiagnosticTrigger"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Resultado do speed-test"
      description: |-
        **Permissão:** `devices:read`.

        Se o estado ainda é `Requested`, a consulta também pede a leitura do resultado ao CPE.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_diagnostics_speed_test
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - name: direction
          in: query
          schema:
            type: string
            enum:
              - download
              - upload
          description: "Padrão download."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      direction:
                        type: string
                      state:
                        type: string
                      url:
                        type: string
                      rom_time:
                        type: string
                        format: date-time
                      bom_time:
                        type: string
                        format: date-time
                      eom_time:
                        type: string
                        format: date-time
                      bytes:
                        type: integer
                        format: int64
                      duration_ms:
                        type: integer
                        format: int64
                      mbps:
                        type: number
                      configured:
                        type: boolean
                      run:
                        "$ref": "#/components/schemas/DiagnosticRun"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/diagnostics/history":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Histórico de diagnósticos"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_diagnostics_history
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - name: kind
          in: query
          schema:
            type: string
            enum:
              - ping
              - traceroute
              - download
              - upload
              - speed
        - name: limit
          in: query
          schema:
            type: integer
            default: 20
            maximum: 100
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/DiagnosticRun"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/service-chain":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Cadeia do serviço (onde está o problema)"
      description: |-
        **Permissão:** `devices:read`.

        Elos em ordem de exibição: `devices`, `wifi`, `cpe`, `onu`, `wan`, `internet`. `culprit` = primeiro elo em falha (ou alerta) na ordem de dependência.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_service_chain
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      links:
                        type: array
                        items:
                          type: object
                          properties:
                            key:
                              type: string
                              enum:
                                - devices
                                - wifi
                                - cpe
                                - onu
                                - wan
                                - internet
                            state:
                              type: string
                              enum:
                                - ok
                                - warn
                                - fail
                                - unknown
                            reason:
                              type: string
                            detail: {}
                      culprit:
                        type:
                          - string
                          - "null"
                      evaluated_at:
                        type: string
                        format: date-time
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/customer":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Cliente do ERP vinculado ao CPE"
      description: |-
        **Permissão:** `devices:read`.

        `data: null` quando não há vínculo (também para CPE inexistente — não há 404).
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_customer
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    oneOf:
                      - "$ref": "#/components/schemas/DeviceCustomer"
                      - type: "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/optical":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Sinal óptico da ONU do CPE"
      description: |-
        **Permissão:** `devices:read`.

        `data: null` quando o CPE não tem ONU vinculada.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_optical
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    oneOf:
                      - "$ref": "#/components/schemas/DeviceOptical"
                      - type: "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/profile":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Perfil CWMP do CPE"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_profile
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      device_id:
                        type: string
                        format: uuid
                      rpc_methods:
                        type: array
                        items:
                          type: string
                      rpc_methods_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                      writable_objects:
                        type: array
                        items:
                          type: string
                      discovered_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                      discovery_summary:
                        type:
                          - string
                          - "null"
                      cwmp_version:
                        type:
                          - string
                          - "null"
                      max_envelopes:
                        type:
                          - integer
                          - "null"
                      retry_count:
                        type:
                          - integer
                          - "null"
                      cpe_current_time:
                        type:
                          - string
                          - "null"
                      last_inform: {}
                      last_inform_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                      event_codes_seen:
                        type: array
                        items:
                          type: string
                      informs_total:
                        type: integer
                        format: int64
                      parameters:
                        type: object
                        properties:
                          total:
                            type: integer
                          writable:
                            type: integer
                          read_only:
                            type: integer
                          typed:
                            type: integer
                          with_attributes:
                            type: integer
                          notifiable:
                            type: integer
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/status-history":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Histórico de status e disponibilidade"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_status_history
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - name: days
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 90
            default: 30
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      days:
                        type: integer
                      transitions:
                        type: integer
                      outages:
                        type: integer
                      observed_seconds:
                        type: integer
                        format: int64
                      online_seconds:
                        type: integer
                        format: int64
                      availability_pct:
                        type:
                          - number
                          - "null"
                      last_outage_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            from_status:
                              type:
                                - string
                                - "null"
                            to_status:
                              type: string
                            changed_at:
                              type: string
                              format: date-time
                            until:
                              type:
                                - string
                                - "null"
                              format: date-time
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/sessions":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Sessões CWMP"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_sessions
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
        - name: event
          in: query
          schema:
            type: string
          description: "Prefixo do código de evento, ex.: `1 BOOT`."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Session"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/last_session":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Última sessão CWMP"
      description: |-
        **Permissão:** `devices:read`.

        Alias: `/last-session`.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_last_session
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    oneOf:
                      - "$ref": "#/components/schemas/SessionInfo"
                      - type: "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/audit":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Auditoria do CPE"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_audit
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/AuditEntry"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/traffic-history":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Série de tráfego"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_traffic_history
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - name: range
          in: query
          schema:
            type: string
            enum:
              - "24h"
              - "7d"
              - "30d"
            default: "24h"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      range:
                        type: string
                      resolution:
                        type: string
                      series:
                        type: array
                        items:
                          type: object
                          properties:
                            timestamp:
                              type: string
                              format: date-time
                            download_mbps:
                              type: number
                            upload_mbps:
                              type: number
                      last_sample_at:
                        type: string
                        format: date-time
                      last_nonzero_sample_at:
                        type: string
                        format: date-time
                      sample_count:
                        type: integer
                      has_data:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/signal-history":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Série de sinal"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_signal_history
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - name: range
          in: query
          schema:
            type: string
            enum:
              - "24h"
              - "7d"
              - "30d"
            default: "24h"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      range:
                        type: string
                      resolution:
                        type: string
                      series:
                        type: array
                        items:
                          type: object
                          properties:
                            timestamp:
                              type: string
                              format: date-time
                            rx_power_dbm:
                              type: number
                            tx_power_dbm:
                              type: number
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/devices/{id}/queue":
    get:
      tags:
        - "CPEs (dispositivos)"
      summary: "Fila de tarefas do CPE"
      description: |-
        **Permissão:** `devices:read`.

        Envelope `{items, pagination}`.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_devices_id_queue
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: "UUID do CPE (`id` da listagem ou `device_id` do lookup)."
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PageSize"
        - "$ref": "#/components/parameters/PerPage"
        - name: status
          in: query
          schema:
            type: string
            enum:
              - pending
              - dispatched
              - executing
              - completed
              - failed
              - cancelled
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          format: uuid
                        type:
                          type: string
                        status:
                          type: string
                        created_at:
                          type: string
                          format: date-time
                        completed_at:
                          type:
                            - string
                            - "null"
                          format: date-time
                        attempts_count:
                          type: integer
                  pagination:
                    "$ref": "#/components/schemas/ItemsPagination"
                required:
                  - items
                  - pagination
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/integrations/cpe:
    get:
      tags:
        - "Integrações"
      summary: "Achar o CPE do cliente"
      description: |-
        **Permissão:** `devices:read`.

        Informe **exatamente um** dos parâmetros. Busca só no tenant da chave. Com mais de um candidato, vence o único online (ou com Inform nas últimas 24 h); senão 409 com `candidates`.
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_integrations_cpe
      parameters:
        - name: pppoe_login
          in: query
          schema:
            type: string
        - name: wan_ip
          in: query
          schema:
            type: string
        - name: customer_id
          in: query
          schema:
            type: string
          description: "Id do cliente no ERP."
        - name: contract_id
          in: query
          schema:
            type: string
          description: "Id do contrato no ERP."
        - name: serial
          in: query
          schema:
            type: string
          description: "Serial do CPE ou da ONU."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/CPELookup"
                required:
                  - data
        "409":
          description: "Ambíguo."
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    const: ambiguous
                  candidates:
                    type: array
                    items:
                      type: object
                      properties:
                        device_id:
                          type: string
                          format: uuid
                        serial_number:
                          type: string
                        model:
                          type:
                            - string
                            - "null"
                        last_inform_at:
                          type:
                            - string
                            - "null"
                          format: date-time
                    maxItems: 20
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/tasks:
    get:
      tags:
        - Tarefas
      summary: "Listar tarefas"
      description: |-
        **Permissão:** `tasks:read`.

        Envelope `{items, pagination}`. Mais recentes primeiro.
      x-required-permissions:
        - "tasks:read"
      x-api-key: true
      operationId: get_tasks
      parameters:
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PageSize"
        - "$ref": "#/components/parameters/PerPage"
        - name: device_id
          in: query
          schema:
            type: string
            format: uuid
        - name: q
          in: query
          schema:
            type: string
          description: "id da tarefa, serial, IP, OUI, modelo (até 100)."
        - name: status
          in: query
          schema:
            type: string
            enum:
              - pending
              - dispatched
              - executing
              - completed
              - failed
              - cancelled
        - name: type
          in: query
          schema:
            type: string
            enum:
              - get_param_values
              - set_param_values
              - reboot
              - factory_reset
              - firmware_upgrade
              - custom
        - name: created_from
          in: query
          schema:
            type: string
            format: date-time
        - name: created_to
          in: query
          schema:
            type: string
            format: date-time
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Task"
                  pagination:
                    "$ref": "#/components/schemas/ItemsPagination"
                required:
                  - items
                  - pagination
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - Tarefas
      summary: "Criar tarefa"
      description: |-
        **Permissão:** qualquer uma de `tasks:create`, `tasks:execute`.

        A tarefa sai na próxima sessão CWMP do CPE. Para acordá-lo agora use `POST /devices/{id}/connection-request`. Erros de payload vêm como 422 com `fields` (ex.: `payload.parameter_names`).
      x-required-permissions:
        - "tasks:create"
        - "tasks:execute"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_tasks
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CreateTask"
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Task"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/tasks/{id}":
    get:
      tags:
        - Tarefas
      summary: "Detalhe da tarefa"
      description: "**Permissão:** `tasks:read`."
      x-required-permissions:
        - "tasks:read"
      x-api-key: true
      operationId: get_tasks_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/TaskDetail"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/tasks/{id}/cancel":
    post:
      tags:
        - Tarefas
      summary: "Cancelar tarefa"
      description: |-
        **Permissão:** `tasks:cancel`.

        Só `pending` ou `dispatched` (senão 409).
      x-required-permissions:
        - "tasks:cancel"
      x-api-key: true
      operationId: post_tasks_id_cancel
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                reason:
                  type: string
                  maxLength: 500
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      message:
                        type: string
                      id:
                        type: string
                        format: uuid
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/tasks/{id}/executions":
    get:
      tags:
        - Tarefas
      summary: "Tentativas de execução"
      description: "**Permissão:** `tasks:read`."
      x-required-permissions:
        - "tasks:read"
      x-api-key: true
      operationId: get_tasks_id_executions
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/TaskExecution"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/alerts:
    get:
      tags:
        - Alertas
      summary: "Listar alertas"
      description: "**Permissão:** qualquer uma de `alerts:read`, `devices:read`."
      x-required-permissions:
        - "alerts:read"
        - "devices:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_alerts
      parameters:
        - name: scope
          in: query
          schema:
            type: string
            enum:
              - active
              - resolved
              - all
            default: active
        - name: type
          in: query
          schema:
            type: string
            enum:
              - device_offline
              - signal_critical
              - factory_reset
              - onu_down
              - onu_signal_critical
              - pon_mass_outage
              - onu_unstable
              - onu_vip_down
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Alert"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/alerts/summary:
    get:
      tags:
        - Alertas
      summary: "Contagem de alertas abertos"
      description: "**Permissão:** qualquer uma de `alerts:read`, `devices:read`."
      x-required-permissions:
        - "alerts:read"
        - "devices:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_alerts_summary
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      open:
                        type: integer
                      acknowledged:
                        type: integer
                      critical:
                        type: integer
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/alerts/rules:
    get:
      tags:
        - Alertas
      summary: "Regras de alerta"
      description: "**Permissão:** qualquer uma de `alerts:read`, `devices:read`."
      x-required-permissions:
        - "alerts:read"
        - "devices:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_alerts_rules
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/AlertRule"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/alerts/rules/{type}":
    put:
      tags:
        - Alertas
      summary: "Configurar regra de alerta"
      description: |-
        **Permissão:** qualquer uma de `alerts:manage`, `devices:update`.

        Parâmetros por tipo: `device_offline.minutes` 1–1440; `signal_critical.below_dbm` -60–0; `factory_reset.hours` 1–168; `onu_down.minutes`; `onu_signal_critical.below_dbm`; `pon_mass_outage.{min_onus,percent,window_minutes}`; `onu_unstable.{flaps,hours}`.
      x-required-permissions:
        - "alerts:manage"
        - "devices:update"
      x-api-key: true
      x-permissions-mode: any
      operationId: put_alerts_rules_type
      parameters:
        - name: type
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                  default: true
                params:
                  type: object
                  properties: {}
                  additionalProperties:
                    type: number
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/AlertRule"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/alerts/{id}/ack":
    post:
      tags:
        - Alertas
      summary: "Reconhecer alerta"
      description: "**Permissão:** qualquer uma de `alerts:manage`, `devices:update`."
      x-required-permissions:
        - "alerts:manage"
        - "devices:update"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_alerts_id_ack
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/incidents:
    get:
      tags:
        - Incidentes
      summary: "Listar incidentes de rede"
      description: "**Permissão:** qualquer uma de `olts:read`, `alerts:read`."
      x-required-permissions:
        - "olts:read"
        - "alerts:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_incidents
      parameters:
        - name: state
          in: query
          schema:
            type: string
            enum:
              - active
              - all
              - open
              - confirmed
              - dismissed
              - closed
            default: active
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Incident"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/incidents/summary:
    get:
      tags:
        - Incidentes
      summary: "Contagem de incidentes"
      description: "**Permissão:** qualquer uma de `olts:read`, `alerts:read`."
      x-required-permissions:
        - "olts:read"
        - "alerts:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_incidents_summary
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      open:
                        type: integer
                      confirmed:
                        type: integer
                      live:
                        type: integer
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/incidents/settings:
    get:
      tags:
        - Incidentes
      summary: "Limiares de correlação"
      description: "**Permissão:** qualquer uma de `olts:read`, `alerts:read`."
      x-required-permissions:
        - "olts:read"
        - "alerts:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_incidents_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/IncidentThresholds"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - Incidentes
      summary: "Alterar limiares"
      description: "**Permissão:** qualquer uma de `devices:update`, `alerts:manage`."
      x-required-permissions:
        - "devices:update"
        - "alerts:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: put_incidents_settings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/IncidentThresholds"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/IncidentThresholds"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/incidents/bulk:
    post:
      tags:
        - Incidentes
      summary: "Confirmar/descartar em lote"
      description: "**Permissão:** qualquer uma de `devices:update`, `alerts:manage`."
      x-required-permissions:
        - "devices:update"
        - "alerts:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_incidents_bulk
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ids:
                  type: array
                  items:
                    type: string
                    format: uuid
                  minItems: 1
                  maxItems: 200
                action:
                  type: string
                  enum:
                    - confirm
                    - dismiss
                reason:
                  type: string
                  maxLength: 1000
              required:
                - ids
                - action
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      done:
                        type: array
                        items:
                          type: string
                          format: uuid
                      skipped:
                        type: object
                        properties: {}
                        additionalProperties:
                          type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/incidents/{id}":
    get:
      tags:
        - Incidentes
      summary: "Detalhe do incidente (ONUs e linha do tempo)"
      description: "**Permissão:** qualquer uma de `olts:read`, `alerts:read`."
      x-required-permissions:
        - "olts:read"
        - "alerts:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_incidents_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/IncidentDetail"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/incidents/{id}/assign":
    post:
      tags:
        - Incidentes
      summary: "Incidente: assign"
      description: |-
        **Permissão:** qualquer uma de `devices:update`, `alerts:manage`.

        Definir dono (`user_id`; null remove). Envie `version` para controle de concorrência (409 se mudou).
      x-required-permissions:
        - "devices:update"
        - "alerts:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_incidents_id_assign
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: false
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/IncidentAction"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Incident"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/incidents/{id}/confirm":
    post:
      tags:
        - Incidentes
      summary: "Incidente: confirm"
      description: |-
        **Permissão:** qualquer uma de `devices:update`, `alerts:manage`.

        De `open` ou `dismissed`. Envie `version` para controle de concorrência (409 se mudou).
      x-required-permissions:
        - "devices:update"
        - "alerts:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_incidents_id_confirm
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: false
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/IncidentAction"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Incident"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/incidents/{id}/dismiss":
    post:
      tags:
        - Incidentes
      summary: "Incidente: dismiss"
      description: |-
        **Permissão:** qualquer uma de `devices:update`, `alerts:manage`.

        Exige `reason`. Envie `version` para controle de concorrência (409 se mudou).
      x-required-permissions:
        - "devices:update"
        - "alerts:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_incidents_id_dismiss
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: false
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/IncidentAction"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Incident"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/incidents/{id}/outcome":
    post:
      tags:
        - Incidentes
      summary: "Incidente: outcome"
      description: |-
        **Permissão:** qualquer uma de `devices:update`, `alerts:manage`.

        Registra `outcome`. Envie `version` para controle de concorrência (409 se mudou).
      x-required-permissions:
        - "devices:update"
        - "alerts:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_incidents_id_outcome
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: false
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/IncidentAction"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Incident"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/incidents/{id}/close":
    post:
      tags:
        - Incidentes
      summary: "Incidente: close"
      description: |-
        **Permissão:** qualquer uma de `devices:update`, `alerts:manage`.

        Exige `outcome` se ainda não houver. Envie `version` para controle de concorrência (409 se mudou).
      x-required-permissions:
        - "devices:update"
        - "alerts:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_incidents_id_close
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: false
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/IncidentAction"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Incident"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/maintenance:
    get:
      tags:
        - "Manutenção"
      summary: "Listar janelas de manutenção"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_maintenance
      parameters:
        - name: status
          in: query
          schema:
            type: string
            enum:
              - all
              - current
              - scheduled
              - active
              - finished
              - cancelled
            default: all
        - name: olt_id
          in: query
          schema:
            type: string
            format: uuid
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/MaintenanceWindow"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "Manutenção"
      summary: "Agendar janela"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_maintenance
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/MaintenanceInput"
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/MaintenanceWindow"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/maintenance/{id}":
    get:
      tags:
        - "Manutenção"
      summary: "Detalhe da janela"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_maintenance_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/MaintenanceDetail"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - "Manutenção"
      summary: "Alterar janela"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: put_maintenance_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/MaintenanceInput"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/MaintenanceWindow"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - "Manutenção"
      summary: "Apagar janela (agendada/cancelada)"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: delete_maintenance_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/maintenance/{id}/cancel":
    post:
      tags:
        - "Manutenção"
      summary: "Janela: cancel"
      description: |-
        **Permissão:** `devices:update`.

        Só janela agendada.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_maintenance_id_cancel
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/MaintenanceWindow"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/maintenance/{id}/finish":
    post:
      tags:
        - "Manutenção"
      summary: "Janela: finish"
      description: |-
        **Permissão:** `devices:update`.

        Só janela ativa.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_maintenance_id_finish
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/MaintenanceWindow"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/maintenance/{id}/compare":
    post:
      tags:
        - "Manutenção"
      summary: "Janela: compare"
      description: |-
        **Permissão:** `devices:update`.

        Comparação antes/depois; só janela encerrada.
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_maintenance_id_compare
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/MaintenanceDetail"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts:
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Listar OLTs"
      description: |-
        **Permissão:** `olts:read`.

        Sem paginação.
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/OLT"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Cadastrar OLT"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/OLTInput"
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLT"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/summary:
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Resumo da rede óptica"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_summary
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      state:
                        type: string
                        enum:
                          - none
                          - never
                          - failing
                          - partial
                          - ok
                          - imported
                      olts_enabled:
                        type: integer
                      olts_healthy:
                        type: integer
                      olts_failing:
                        type: integer
                      olts_pending:
                        type: integer
                      last_ok_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                      oldest_ok_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                      counts:
                        type:
                          - object
                          - "null"
                        properties:
                          total:
                            type: integer
                          online:
                            type: integer
                          offline:
                            type: integer
                          los:
                            type: integer
                          power_off:
                            type: integer
                          inactive:
                            type: integer
                          unknown:
                            type: integer
                          unauthorized:
                            type: integer
                          signal_critical:
                            type: integer
                          signal_degraded:
                            type: integer
                          without_cto:
                            type: integer
                          customers_without_onu:
                            type: integer
                          unstable:
                            type: integer
                      imported_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/onus:
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Buscar ONUs em todas as OLTs"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_onus
      parameters:
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
        - name: status
          in: query
          schema:
            type: string
            enum:
              - online
              - offline
              - los
              - power_off
              - inactive
              - unknown
              - down
          description: "`down` = offline+los+power_off+inactive."
        - name: signal
          in: query
          schema:
            type: string
            enum:
              - critical
              - degraded
              - good
          description: "critical < -27 dBm; degraded -27 a -24; good ≥ -24."
        - name: sort
          in: query
          schema:
            type: string
            enum:
              - signal
          description: "Padrão: OLT, slot, porta, índice."
        - name: q
          in: query
          schema:
            type: string
          description: "serial, MAC (com ou sem `:`), PPPoE, descrição, serial do CPE, cliente, contrato."
        - name: pon_id
          in: query
          schema:
            type: string
            format: uuid
        - name: unlinked
          in: query
          schema:
            type: string
            enum:
              - "true"
          description: "Só ONUs sem CPE."
        - name: vip
          in: query
          schema:
            type: string
            enum:
              - "true"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/ONU"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/unauthorized:
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "ONUs não autorizadas (todas as OLTs)"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_unauthorized
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/UnauthorizedONU"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/triangulation/summary:
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Resumo da triangulação ONU ↔ CPE ↔ cliente"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_triangulation_summary
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      onus:
                        type: integer
                      customer_by_method:
                        type: object
                        properties: {}
                        additionalProperties:
                          type: integer
                      onus_with_customer:
                        type: integer
                      cpe_by_method:
                        type: object
                        properties: {}
                        additionalProperties:
                          type: integer
                      onus_with_cpe:
                        type: integer
                      devices:
                        type: integer
                      cpe_customer_own:
                        type: integer
                      cpe_customer_via_onu:
                        type: integer
                      by_status:
                        type: object
                        properties: {}
                        additionalProperties:
                          type: integer
                      ambiguous_cpe:
                        type: integer
                      ambiguous_customer:
                        type: integer
                      last_matched_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/triangulation:
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Triangulação por ONU"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_triangulation
      parameters:
        - name: status
          in: query
          schema:
            type: string
            enum:
              - ok
              - partial
              - conflict
              - missing
              - ambiguous
        - name: q
          in: query
          schema:
            type: string
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/TriangulationRow"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/triangulation/recalculate:
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Recalcular triangulação"
      description: |-
        **Permissão:** `provisioning:manage`.

        202 `{mode: erp_sync}` quando dispara a sincronização do ERP; 200 `{mode: relink}` quando só religa localmente.
      x-required-permissions:
        - "provisioning:manage"
      x-api-key: true
      operationId: post_olts_triangulation_recalculate
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      mode:
                        type: string
                        enum:
                          - erp_sync
                          - relink
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/analytics/{kind}":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Análises ópticas"
      description: |-
        **Permissão:** `olts:read`.

        `isolated`: ONUs muito abaixo da mediana da PON. `critical-period`: ONUs com leituras críticas no período. `pons`: saúde por PON.
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_analytics_kind
      parameters:
        - name: kind
          in: path
          required: true
          schema:
            type: string
            enum:
              - isolated
              - critical-period
              - pons
        - name: min_delta
          in: query
          schema:
            type: number
            default: 5
        - name: days
          in: query
          schema:
            type: integer
            default: 7
        - name: below
          in: query
          schema:
            type: number
            default: -27
        - name: min_readings
          in: query
          schema:
            type: integer
            default: 3
        - name: limit
          in: query
          schema:
            type: integer
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties: {}
                      additionalProperties: true
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/provisioning/settings:
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Regras de aprovação de provisionamento"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_provisioning_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      approval_threshold:
                        type: integer
                      allow_self_approval:
                        type: boolean
                      server_writes_enabled:
                        type: boolean
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - "Somente sessão de usuário"
      summary: "Regras de aprovação de provisionamento"
      description: |-
        **Permissão:** `olts:write`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "olts:write"
      x-api-key: false
      operationId: put_olts_provisioning_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/provisioning/profiles:
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Perfis de provisionamento de ONU"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_provisioning_profiles
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          format: uuid
                        vendor:
                          type: string
                        name:
                          type: string
                        auth_method:
                          type: string
                          enum:
                            - mac
                            - loid
                        description_template:
                          type: string
                        onu_id_strategy:
                          type: string
                          enum:
                            - next_free
                            - fixed
                        save_config:
                          type: boolean
                        is_default:
                          type: boolean
                        created_at:
                          type: string
                          format: date-time
                        updated_at:
                          type: string
                          format: date-time
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Criar perfil"
      description: |-
        **Permissão:** `olts:write`.

        Exige o recurso `onu_provisioning` do plano.
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_provisioning_profiles
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                vendor:
                  type: string
                  enum:
                    - vsol
                    - huawei
                    - zte
                    - fiberhome
                name:
                  type: string
                  minLength: 1
                  maxLength: 80
                auth_method:
                  type: string
                  enum:
                    - mac
                    - loid
                description_template:
                  type: string
                onu_id_strategy:
                  type: string
                  enum:
                    - next_free
                    - fixed
                save_config:
                  type: boolean
                  default: true
                is_default:
                  type: boolean
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/provisioning/profiles/{pid}":
    put:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Alterar perfil"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: put_olts_provisioning_profiles_pid
      parameters:
        - name: pid
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                vendor:
                  type: string
                  enum:
                    - vsol
                    - huawei
                    - zte
                    - fiberhome
                name:
                  type: string
                  minLength: 1
                  maxLength: 80
                auth_method:
                  type: string
                  enum:
                    - mac
                    - loid
                description_template:
                  type: string
                onu_id_strategy:
                  type: string
                  enum:
                    - next_free
                    - fixed
                save_config:
                  type: boolean
                  default: true
                is_default:
                  type: boolean
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Apagar perfil"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: delete_olts_provisioning_profiles_pid
      parameters:
        - name: pid
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Detalhe da OLT"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLT"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Alterar OLT"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: put_olts_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/OLTInput"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLT"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Remover OLT"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: delete_olts_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/test":
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Testar acesso à OLT"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_test
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      ok:
                        type: boolean
                      kind:
                        type: string
                        enum:
                          - ok
                          - timeout
                          - no_login
                          - refused
                          - auth
                          - unsupported
                          - host_key_mismatch
                          - error
                      elapsed_ms:
                        type: integer
                      message:
                        type: string
                      serial:
                        type: string
                      hardware:
                        type: string
                      software_version:
                        type: string
                      uptime_seconds:
                        type: integer
                      temperature_c:
                        type: number
                      host_key:
                        type: string
                      presented_host_key:
                        type: string
                      pons:
                        type: array
                        items:
                          type: object
                          properties:
                            index:
                              type: integer
                            name:
                              type: string
                            total_onus:
                              type: integer
                            online_onus:
                              type: integer
                            tx_power_dbm:
                              type:
                                - number
                                - "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/collect":
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Coletar agora"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_collect
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      started:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/pons":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "PONs da OLT"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_pons
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/PON"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/health":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Saúde da OLT (série)"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_health
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: hours
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 720
            default: 24
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        at:
                          type: string
                          format: date-time
                        temperature_c:
                          type:
                            - number
                            - "null"
                        uptime_seconds:
                          type:
                            - integer
                            - "null"
                        cpu_pct:
                          type:
                            - number
                            - "null"
                        memory_pct:
                          type:
                            - number
                            - "null"
                        poll_ms:
                          type:
                            - integer
                            - "null"
                        optical_paused:
                          type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/onus":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "ONUs da OLT"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_onus
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
        - name: status
          in: query
          schema:
            type: string
            enum:
              - online
              - offline
              - los
              - power_off
              - inactive
              - unknown
              - down
          description: "`down` = offline+los+power_off+inactive."
        - name: signal
          in: query
          schema:
            type: string
            enum:
              - critical
              - degraded
              - good
          description: "critical < -27 dBm; degraded -27 a -24; good ≥ -24."
        - name: sort
          in: query
          schema:
            type: string
            enum:
              - signal
          description: "Padrão: OLT, slot, porta, índice."
        - name: q
          in: query
          schema:
            type: string
          description: "serial, MAC (com ou sem `:`), PPPoE, descrição, serial do CPE, cliente, contrato."
        - name: pon_id
          in: query
          schema:
            type: string
            format: uuid
        - name: unlinked
          in: query
          schema:
            type: string
            enum:
              - "true"
          description: "Só ONUs sem CPE."
        - name: vip
          in: query
          schema:
            type: string
            enum:
              - "true"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/ONU"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/onus/{onuId}":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Detalhe da ONU"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_onus_onuId
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: onuId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/ONU"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/onus/{onuId}/history":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Histórico de sinal e status da ONU"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_onus_onuId_history
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: onuId
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: hours
          in: query
          schema:
            type: integer
            default: 168
            maximum: 2160
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      hours:
                        type: integer
                      metrics:
                        type: array
                        items:
                          type: object
                          properties:
                            at:
                              type: string
                              format: date-time
                            rx_dbm:
                              type:
                                - number
                                - "null"
                            tx_dbm:
                              type:
                                - number
                                - "null"
                      status:
                        type: array
                        items:
                          type: object
                          properties:
                            at:
                              type: string
                              format: date-time
                            from:
                              type:
                                - string
                                - "null"
                            to:
                              type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/onus/{onuId}/vip":
    put:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Marcar/desmarcar ONU VIP"
      description: "**Permissão:** `provisioning:manage`."
      x-required-permissions:
        - "provisioning:manage"
      x-api-key: true
      operationId: put_olts_id_onus_onuId_vip
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: onuId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                vip:
                  type: boolean
                label:
                  type:
                    - string
                    - "null"
                  maxLength: 120
              required:
                - vip
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/ONU"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/olts/vip/import-oltcloud:
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Importar VIPs do OLT Cloud"
      description: "**Permissão:** `provisioning:manage`."
      x-required-permissions:
        - "provisioning:manage"
      x-api-key: true
      operationId: post_olts_vip_import_oltcloud
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      available:
                        type: boolean
                      marked:
                        type: integer
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/unauthorized":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "ONUs não autorizadas da OLT"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_unauthorized
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/UnauthorizedONU"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/next-onu-id":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Próximo ONU-ID livre"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_next_onu_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: pon
          in: query
          schema:
            type: integer
            minimum: 1
          required: true
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      onu_id:
                        type: integer
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/commands":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Comandos de provisionamento"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_commands
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: onu_id
          in: query
          schema:
            type: string
            format: uuid
        - name: batch_id
          in: query
          schema:
            type: string
            format: uuid
        - name: state
          in: query
          schema:
            type: string
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/OLTCommand"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Simular comando na ONU"
      description: |-
        **Permissão:** `olts:write`.

        Cria uma **simulação** (`state: previewed`, CLI em `cli_preview`); nada vai à OLT até `POST .../execute` (simulação vale 30 min). Repetir o mesmo `idempotency_key` devolve 200 com o comando existente. Exige o recurso `onu_provisioning` do plano e escrita ligada na OLT.
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_commands
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                action:
                  type: string
                  enum:
                    - authorize
                    - deauthorize
                    - reboot
                    - set_description
                    - factory_reset
                unauthorized_id:
                  type: string
                  format: uuid
                  description: "Obrigatório em authorize."
                onu_id:
                  type: string
                  format: uuid
                  description: "Obrigatório nas demais."
                profile_id:
                  type: string
                  format: uuid
                target_onu_id:
                  type: integer
                  description: "0 = sugerido."
                pppoe:
                  type: string
                customer_ref:
                  type: string
                loid_password:
                  type: string
                  writeOnly: true
                description:
                  type:
                    - string
                    - "null"
                save_config:
                  type: boolean
                reason:
                  type: string
                  minLength: 5
                  maxLength: 500
                idempotency_key:
                  type: string
                  maxLength: 60
              required:
                - action
                - reason
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTCommand"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/commands/batch":
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Simular comando em lote"
      description: |-
        **Permissão:** `olts:write`.

        Acima do limiar de aprovação o lote fica `awaiting_approval` e precisa de aprovação de um usuário no painel.
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_commands_batch
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                action:
                  type: string
                  enum:
                    - reboot
                    - deauthorize
                    - set_description
                onu_ids:
                  type: array
                  items:
                    type: string
                    format: uuid
                  minItems: 1
                  maxItems: 256
                description_template:
                  type: string
                  maxLength: 120
                  description: "Variáveis {pppoe} {serial} {customer_ref} {mac} {pon} {onu_id}"
                save_config:
                  type: boolean
                reason:
                  type: string
                idempotency_key:
                  type: string
              required:
                - action
                - onu_ids
                - reason
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTBatch"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/commands/{cmdId}":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Detalhe do comando"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_commands_cmdId
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: cmdId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTCommand"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/commands/{cmdId}/execute":
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Executar comando simulado"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_commands_cmdId_execute
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: cmdId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTCommand"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/commands/{cmdId}/cancel":
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Cancelar comando"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_commands_cmdId_cancel
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: cmdId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTCommand"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/batches":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Lotes (últimos 50)"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_batches
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/OLTBatch"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/batches/{batchId}":
    get:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Detalhe do lote"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_olts_id_batches_batchId
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: batchId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTBatch"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/batches/{batchId}/execute":
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Lote: execute"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_batches_batchId_execute
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: batchId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTBatch"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/batches/{batchId}/resume":
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Lote: resume"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_batches_batchId_resume
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: batchId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTBatch"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/batches/{batchId}/cancel":
    post:
      tags:
        - "OLTs, PONs e ONUs"
      summary: "Lote: cancel"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_olts_id_batches_batchId_cancel
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: batchId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OLTBatch"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ctos:
    get:
      tags:
        - CTOs
      summary: "Listar CTOs"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_ctos
      parameters:
        - name: q
          in: query
          schema:
            type: string
        - name: status
          in: query
          schema:
            type: string
            enum:
              - active
              - inactive
              - planned
        - name: olt_id
          in: query
          schema:
            type: string
            format: uuid
        - name: pon_id
          in: query
          schema:
            type: string
            format: uuid
        - name: occupancy
          in: query
          schema:
            type: string
            enum:
              - full
              - available
              - empty
        - name: without_pon
          in: query
          schema:
            type: string
            enum:
              - "true"
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/CTO"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - CTOs
      summary: "Criar CTO"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_ctos
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CTOInput"
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/CTODetail"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ctos/summary:
    get:
      tags:
        - CTOs
      summary: "Resumo de CTOs e portas"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_ctos_summary
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      total:
                        type: integer
                      active:
                        type: integer
                      without_pon:
                        type: integer
                      without_location:
                        type: integer
                      ports_total:
                        type: integer
                      ports_occupied:
                        type: integer
                      ports_reserved:
                        type: integer
                      ports_faulty:
                        type: integer
                      ports_free:
                        type: integer
                      onus_without_cto:
                        type: integer
                      oltcloud_boxes:
                        type: integer
                      oltcloud_imported:
                        type: integer
                      occupancy_pct:
                        type: number
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ctos/unlinked-onus:
    get:
      tags:
        - CTOs
      summary: "ONUs sem CTO"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_ctos_unlinked_onus
      parameters:
        - name: q
          in: query
          schema:
            type: string
        - name: olt_id
          in: query
          schema:
            type: string
            format: uuid
        - name: pon_id
          in: query
          schema:
            type: string
            format: uuid
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          format: uuid
                        serial_number:
                          type: string
                        status:
                          type: string
                        rx_dbm:
                          type:
                            - number
                            - "null"
                        olt_id:
                          type: string
                          format: uuid
                        olt_name:
                          type: string
                        pon_id:
                          type:
                            - string
                            - "null"
                          format: uuid
                        pon_slot:
                          type:
                            - integer
                            - "null"
                        pon_port:
                          type:
                            - integer
                            - "null"
                        onu_index:
                          type:
                            - integer
                            - "null"
                        device_id:
                          type:
                            - string
                            - "null"
                          format: uuid
                        description:
                          type:
                            - string
                            - "null"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ctos/import/csv:
    post:
      tags:
        - CTOs
      summary: "Importar CTOs de CSV"
      description: |-
        **Permissão:** `olts:write`.

        Cabeçalho obrigatório; colunas (pt/es/en): code, capacity, latitude, longitude, description, address, city, olt, pon (`slot/porta`). Separador `,` ou `;`. Até 5000 linhas; idempotente por `code`.
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_ctos_import_csv
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                csv:
                  type: string
                  description: "Texto do CSV."
                dry_run:
                  type: boolean
              required:
                - csv
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      dry_run:
                        type: boolean
                      rows:
                        type: integer
                      created:
                        type: integer
                      updated:
                        type: integer
                      unchanged:
                        type: integer
                      invalid:
                        type: integer
                      errors:
                        type: array
                        items:
                          type: object
                          properties:
                            line:
                              type: integer
                            ref:
                              type: string
                            error:
                              type: string
                        description: "Pode vir null."
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ctos/import/oltcloud:
    post:
      tags:
        - CTOs
      summary: "Importar CTOs do OLT Cloud"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: post_ctos_import_oltcloud
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                dry_run:
                  type: boolean
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                    additionalProperties: true
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/ctos/{id}":
    get:
      tags:
        - CTOs
      summary: "Detalhe da CTO com portas"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_ctos_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/CTODetail"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - CTOs
      summary: "Alterar CTO"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: put_ctos_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CTOInput"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/CTODetail"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - CTOs
      summary: "Remover CTO"
      description: "**Permissão:** `olts:write`."
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: delete_ctos_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/ctos/{id}/history":
    get:
      tags:
        - CTOs
      summary: "Histórico das portas (últimos 200)"
      description: "**Permissão:** `olts:read`."
      x-required-permissions:
        - "olts:read"
      x-api-key: true
      operationId: get_ctos_id_history
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: integer
                          format: int64
                        port_number:
                          type: integer
                        state:
                          type: string
                        onu_id:
                          type:
                            - string
                            - "null"
                          format: uuid
                        onu_serial:
                          type:
                            - string
                            - "null"
                        customer_ref:
                          type:
                            - string
                            - "null"
                        source:
                          type: string
                        actor_email:
                          type:
                            - string
                            - "null"
                        created_at:
                          type: string
                          format: date-time
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/ctos/{id}/ports/{number}":
    put:
      tags:
        - CTOs
      summary: "Ocupar/liberar/reservar porta"
      description: |-
        **Permissão:** `olts:write`.

        `occupied` exige `onu_serial`, `onu_id` ou `customer_ref`. ONU já em outra CTO → 409, a menos que `move: true`.
      x-required-permissions:
        - "olts:write"
      x-api-key: true
      operationId: put_ctos_id_ports_number
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: number
          in: path
          required: true
          schema:
            type: integer
            minimum: 1
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                state:
                  type: string
                  enum:
                    - free
                    - occupied
                    - reserved
                    - faulty
                onu_serial:
                  type: string
                onu_id:
                  type: string
                  format: uuid
                customer_ref:
                  type: string
                move:
                  type: boolean
                reserved_until:
                  type: string
                  format: date-time
                reserved_for:
                  type: string
              required:
                - state
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/CTODetail"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/webhooks/catalog:
    get:
      tags:
        - Webhooks
      summary: "Catálogo de eventos com exemplos"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_webhooks_catalog
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                        ordering_key:
                          type: string
                        placeholder:
                          type: boolean
                        example:
                          type: object
                          properties:
                            data: {}
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/webhooks:
    get:
      tags:
        - Webhooks
      summary: "Listar webhooks"
      description: |-
        **Permissão:** qualquer uma de `integrations:read`, `provisioning:read`.

        Sem paginação.
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_webhooks
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Webhook"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - Webhooks
      summary: "Cadastrar webhook"
      description: |-
        **Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`.

        Devolve o segredo **uma única vez**. Limite de 20 webhooks por tenant.
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_webhooks
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/WebhookInput"
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/WebhookWithSecret"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/webhooks/{id}":
    get:
      tags:
        - Webhooks
      summary: "Detalhe do webhook"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_webhooks_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Webhook"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - Webhooks
      summary: "Alterar webhook"
      description: |-
        **Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`.

        `enabled: true` religa e zera o contador de falhas.
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: put_webhooks_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/WebhookInput"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Webhook"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - Webhooks
      summary: "Remover webhook (com fila e log)"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: delete_webhooks_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/webhooks/{id}/rotate-secret":
    post:
      tags:
        - Webhooks
      summary: "Rotacionar segredo"
      description: |-
        **Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`.

        O segredo antigo continua assinando junto por 24 h.
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_webhooks_id_rotate_secret
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/WebhookWithSecret"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/webhooks/{id}/test":
    post:
      tags:
        - Webhooks
      summary: "Enviar evento de teste"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_webhooks_id_test
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      delivery_id:
                        type: string
                      delivered:
                        type: boolean
                      http_status:
                        type:
                          - integer
                          - "null"
                      latency_ms:
                        type: integer
                      error:
                        type: string
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/webhooks/{id}/deliveries":
    get:
      tags:
        - Webhooks
      summary: "Log de entregas"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_webhooks_id_deliveries
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: status
          in: query
          schema:
            type: string
            enum:
              - pending
              - delivered
              - failed
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/WebhookDelivery"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/webhooks/{id}/deliveries/{deliveryID}/redeliver":
    post:
      tags:
        - Webhooks
      summary: "Reenviar entrega"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_webhooks_id_deliveries_deliveryID_redeliver
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: deliveryID
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      queued:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ixc/settings:
    get:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "IXC Soft: configuração e status da sincronização"
      description: |-
        **Permissão:** qualquer uma de `integrations:read`, `provisioning:read`.

        Segredos nunca voltam (só `*_set`). Os campos `sync_*` mostram a última sincronização.
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_ixc_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/IXCSettings"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "IXC Soft: configurar"
      description: |-
        **Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`.

        Um ERP por tenant: ligar este com o outro ligado → 409.
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: put_ixc_settings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                base_url:
                  type: string
                username:
                  type: string
                  maxLength: 200
                password:
                  type: string
                  maxLength: 500
                  writeOnly: true
                  description: "Vazio mantém a atual."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/IXCSettings"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ixc/test:
    post:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "IXC Soft: testar credenciais"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_ixc_test
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      ok:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ixc/sync:
    post:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "IXC Soft: sincronizar agora"
      description: |-
        **Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`.

        Assíncrono. Acompanhe por `GET /settings` (`sync_status`). 409 se já houver uma rodando.
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_ixc_sync
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      started:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ixc/unlinked:
    get:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "IXC Soft: CPEs sem cliente"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_ixc_unlinked
      parameters:
        - name: reason
          in: query
          schema:
            type: string
            enum:
              - not_found
              - ambiguous
              - no_customer
              - no_identifier
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/ERPUnlinked"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/hubsoft/settings:
    get:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "HubSoft: configuração e status da sincronização"
      description: |-
        **Permissão:** qualquer uma de `integrations:read`, `provisioning:read`.

        Segredos nunca voltam (só `*_set`). Os campos `sync_*` mostram a última sincronização.
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_hubsoft_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/HubsoftSettings"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "HubSoft: configurar"
      description: |-
        **Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`.

        Um ERP por tenant: ligar este com o outro ligado → 409.
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: put_hubsoft_settings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                base_url:
                  type: string
                client_id:
                  type: string
                client_secret:
                  type: string
                  writeOnly: true
                username:
                  type: string
                password:
                  type: string
                  writeOnly: true
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/HubsoftSettings"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/hubsoft/test:
    post:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "HubSoft: testar credenciais"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_hubsoft_test
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      ok:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/hubsoft/sync:
    post:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "HubSoft: sincronizar agora"
      description: |-
        **Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`.

        Assíncrono. Acompanhe por `GET /settings` (`sync_status`). 409 se já houver uma rodando.
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_hubsoft_sync
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      started:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/hubsoft/unlinked:
    get:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "HubSoft: CPEs sem cliente"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_hubsoft_unlinked
      parameters:
        - name: reason
          in: query
          schema:
            type: string
            enum:
              - not_found
              - ambiguous
              - no_customer
              - no_identifier
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/ERPUnlinked"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/ixc/plans:
    get:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "IXC Soft: planos em uso"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_ixc_plans
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        plan:
                          type: string
                        count:
                          type: integer
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/thothix/settings:
    get:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "Thothix: configuração"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_thothix_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      webhook_url:
                        type: string
                      secret_set:
                        type: boolean
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "Thothix: configurar"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: put_thothix_settings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                webhook_url:
                  type: string
                secret:
                  type: string
                  minLength: 16
                  writeOnly: true
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      webhook_url:
                        type: string
                      secret_set:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/thothix/deliveries:
    get:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "Thothix: entregas"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_thothix_deliveries
      parameters:
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties: {}
                      additionalProperties: true
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/thothix/deliveries/retry-failed:
    post:
      tags:
        - "ERP (IXC, HubSoft, Thothix)"
      summary: "Thothix: reenviar falhas"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_thothix_deliveries_retry_failed
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      retried:
                        type: integer
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/import/genieacs:
    post:
      tags:
        - "Importação e OLT Cloud"
      summary: "Importar do GenieACS"
      description: |-
        **Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`.

        Só lê a origem. `dry_run` padrão true.
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_import_genieacs
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                base_url:
                  type: string
                username:
                  type: string
                password:
                  type: string
                  writeOnly: true
                dry_run:
                  type:
                    - boolean
                    - "null"
                  default: true
                import_presets:
                  type: boolean
              required:
                - base_url
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/ImportRun"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/import/oltcloud:
    post:
      tags:
        - "Importação e OLT Cloud"
      summary: "Importar do OLT Cloud"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_import_oltcloud
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                base_url:
                  type: string
                username:
                  type: string
                password:
                  type: string
                  writeOnly: true
                dry_run:
                  type:
                    - boolean
                    - "null"
                  default: true
                include_inactive:
                  type: boolean
                timezone:
                  type: string
                  default: America/Sao_Paulo
              required:
                - base_url
                - username
                - password
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/ImportRun"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/import/runs:
    get:
      tags:
        - "Importação e OLT Cloud"
      summary: "Últimas 20 importações"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_import_runs
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/ImportRun"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/import/oltcloud/sync:
    get:
      tags:
        - "Importação e OLT Cloud"
      summary: "Sincronização contínua do OLT Cloud"
      description: "**Permissão:** qualquer uma de `integrations:read`, `provisioning:read`."
      x-required-permissions:
        - "integrations:read"
        - "provisioning:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_import_oltcloud_sync
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OltCloudSync"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - "Importação e OLT Cloud"
      summary: "Configurar sincronização contínua"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: put_import_oltcloud_sync
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                base_url:
                  type: string
                username:
                  type: string
                password:
                  type: string
                  writeOnly: true
                interval_seconds:
                  type: integer
                  minimum: 300
                  maximum: 3600
                  default: 600
                timezone:
                  type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/OltCloudSync"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/import/oltcloud/sync/run:
    post:
      tags:
        - "Importação e OLT Cloud"
      summary: "Sincronizar OLT Cloud agora"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_import_oltcloud_sync_run
      responses:
        "202":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      started:
                        type: boolean
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/import/oltcloud/sync/olts:
    post:
      tags:
        - "Importação e OLT Cloud"
      summary: "Escolher fonte de coleta por OLT"
      description: "**Permissão:** qualquer uma de `integrations:manage`, `provisioning:manage`."
      x-required-permissions:
        - "integrations:manage"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_import_oltcloud_sync_olts
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                collect_source:
                  type: string
                  enum:
                    - oltcloud
                    - direct
                all:
                  type: boolean
                olt_ids:
                  type: array
                  items:
                    type: string
                    format: uuid
                  maxItems: 1000
              required:
                - collect_source
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      updated:
                        type: integer
                      olts:
                        type: array
                        items:
                          type: object
                          properties: {}
                          additionalProperties: true
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/campaigns:
    get:
      tags:
        - Campanhas
      summary: "Listar campanhas"
      description: |-
        **Permissão:** `campaigns:read`.

        Sem paginação.
      x-required-permissions:
        - "campaigns:read"
      x-api-key: true
      operationId: get_campaigns
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Campaign"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - Campanhas
      summary: "Criar campanha (rascunho)"
      description: |-
        **Permissão:** `campaigns:create`.

        Exige o recurso `campaigns` do plano. Cria em `draft`; nada sai até `launch`.
      x-required-permissions:
        - "campaigns:create"
      x-api-key: true
      operationId: post_campaigns
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CampaignInput"
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Campaign"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/campaigns/preview-targets:
    post:
      tags:
        - Campanhas
      summary: "Contar alvos de um filtro"
      description: "**Permissão:** `campaigns:create`."
      x-required-permissions:
        - "campaigns:create"
      x-api-key: true
      operationId: post_campaigns_preview_targets
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/TargetFilter"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      total:
                        type: integer
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/campaigns/dry-run:
    post:
      tags:
        - Campanhas
      summary: "Simular campanha"
      description: |-
        **Permissão:** `campaigns:create`.

        Mostra, por CPE (até 500), o valor atual e o novo.
      x-required-permissions:
        - "campaigns:create"
      x-api-key: true
      operationId: post_campaigns_dry_run
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CampaignInput"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      total:
                        type: integer
                      truncated:
                        type: boolean
                      content_type:
                        type: string
                      pilot_size:
                        type: integer
                      total_waves:
                        type: integer
                      summary:
                        type: object
                        properties:
                          will_change:
                            type: integer
                          unchanged:
                            type: integer
                          unknown:
                            type: integer
                      devices:
                        type: array
                        items:
                          type: object
                          properties:
                            device_id:
                              type: string
                              format: uuid
                            serial_number:
                              type: string
                            product_class:
                              type: string
                            sw_version:
                              type:
                                - string
                                - "null"
                            status:
                              type: string
                            wave:
                              type:
                                - integer
                                - "null"
                            changes:
                              type: array
                              items:
                                type: object
                                properties:
                                  key:
                                    type: string
                                  current:
                                    type:
                                      - string
                                      - "null"
                                  new:
                                    type: string
                                  status:
                                    type: string
                                    enum:
                                      - change
                                      - same
                                      - unknown
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/campaigns/approval-settings:
    get:
      tags:
        - Campanhas
      summary: "Regra de aprovação"
      description: "**Permissão:** `campaigns:read`."
      x-required-permissions:
        - "campaigns:read"
      x-api-key: true
      operationId: get_campaigns_approval_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      threshold:
                        type: integer
                        description: "0 = sem aprovação."
                      allow_self_approval:
                        type: boolean
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - "Somente sessão de usuário"
      summary: "Regra de aprovação de campanhas"
      description: |-
        **Permissão:** `provisioning:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "provisioning:manage"
      x-api-key: false
      operationId: put_campaigns_approval_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}":
    get:
      tags:
        - Campanhas
      summary: "Detalhe da campanha"
      description: "**Permissão:** `campaigns:read`."
      x-required-permissions:
        - "campaigns:read"
      x-api-key: true
      operationId: get_campaigns_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Campaign"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/targets":
    get:
      tags:
        - Campanhas
      summary: "Alvos e estado por CPE"
      description: "**Permissão:** `campaigns:read`."
      x-required-permissions:
        - "campaigns:read"
      x-api-key: true
      operationId: get_campaigns_id_targets
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        device_id:
                          type: string
                          format: uuid
                        serial_number:
                          type: string
                        oui:
                          type: string
                        ip_address:
                          type:
                            - string
                            - "null"
                        task_id:
                          type:
                            - string
                            - "null"
                          format: uuid
                        wave:
                          type:
                            - integer
                            - "null"
                        state:
                          type: string
                          enum:
                            - draft
                            - queued
                            - delivered
                            - confirmed
                            - failed
                            - cancelled
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/diff":
    get:
      tags:
        - Campanhas
      summary: "Valores atuais × novos"
      description: "**Permissão:** `campaigns:read`."
      x-required-permissions:
        - "campaigns:read"
      x-api-key: true
      operationId: get_campaigns_id_diff
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties: {}
                      additionalProperties: true
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/comparison":
    get:
      tags:
        - Campanhas
      summary: "Comparação depois do lançamento"
      description: "**Permissão:** `campaigns:read`."
      x-required-permissions:
        - "campaigns:read"
      x-api-key: true
      operationId: get_campaigns_id_comparison
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                    additionalProperties: true
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/launch":
    post:
      tags:
        - Campanhas
      summary: "Lançar campanha"
      description: |-
        **Permissão:** `campaigns:create`.

        Acima do limiar de aprovação a campanha fica `approval_status: pending` e um usuário precisa aprovar no painel.
      x-required-permissions:
        - "campaigns:create"
      x-api-key: true
      operationId: post_campaigns_id_launch
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Campaign"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/cancel":
    post:
      tags:
        - Campanhas
      summary: "Campanha: cancel"
      description: |-
        **Permissão:** `campaigns:create`.

        Cancela as tarefas ainda não entregues.
      x-required-permissions:
        - "campaigns:create"
      x-api-key: true
      operationId: post_campaigns_id_cancel
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Campaign"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/pause":
    post:
      tags:
        - Campanhas
      summary: "Campanha: pause"
      description: |-
        **Permissão:** `campaigns:create`.

        Só campanha em ondas.
      x-required-permissions:
        - "campaigns:create"
      x-api-key: true
      operationId: post_campaigns_id_pause
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Campaign"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/resume":
    post:
      tags:
        - Campanhas
      summary: "Campanha: resume"
      description: |-
        **Permissão:** `campaigns:create`.

        Retoma campanha pausada.
      x-required-permissions:
        - "campaigns:create"
      x-api-key: true
      operationId: post_campaigns_id_resume
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Campaign"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/revert":
    post:
      tags:
        - Campanhas
      summary: "Criar campanha de reversão"
      description: "**Permissão:** `campaigns:create`."
      x-required-permissions:
        - "campaigns:create"
      x-api-key: true
      operationId: post_campaigns_id_revert
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      campaign:
                        "$ref": "#/components/schemas/Campaign"
                      stats:
                        type: object
                        properties:
                          eligible:
                            type: integer
                          skipped:
                            type: integer
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/firmware:
    get:
      tags:
        - Firmware
      summary: "Catálogo de firmware"
      description: "**Permissão:** qualquer uma de `firmware:read`, `devices:read`."
      x-required-permissions:
        - "firmware:read"
        - "devices:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_firmware
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/FirmwareImage"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - Firmware
      summary: "Cadastrar firmware por URL"
      description: "**Permissão:** qualquer uma de `firmware:upload`, `provisioning:manage`."
      x-required-permissions:
        - "firmware:upload"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_firmware
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                vendor:
                  type: string
                product_class:
                  type: string
                version:
                  type: string
                url:
                  type: string
                  description: "http, https ou ftp"
                file_type:
                  type: string
                  enum:
                    - firmware
                    - config
                file_size:
                  type:
                    - integer
                    - "null"
                  minimum: 0
                checksum:
                  type:
                    - string
                    - "null"
                notes:
                  type:
                    - string
                    - "null"
              required:
                - product_class
                - version
                - url
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                        format: uuid
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/firmware/config:
    get:
      tags:
        - Firmware
      summary: "Limites de upload"
      description: "**Permissão:** qualquer uma de `firmware:read`, `devices:read`."
      x-required-permissions:
        - "firmware:read"
        - "devices:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_firmware_config
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      upload_enabled:
                        type: boolean
                      max_upload_mb:
                        type: integer
                      public_url_set:
                        type: boolean
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/firmware/upload:
    post:
      tags:
        - Firmware
      summary: "Enviar arquivo de firmware"
      description: "**Permissão:** qualquer uma de `firmware:upload`, `provisioning:manage`."
      x-required-permissions:
        - "firmware:upload"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: post_firmware_upload
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                vendor:
                  type: string
                product_class:
                  type: string
                version:
                  type: string
                file_type:
                  type: string
                  enum:
                    - firmware
                    - config
                notes:
                  type: string
              required:
                - file
                - product_class
                - version
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                        format: uuid
                      url:
                        type: string
                required:
                  - data
        "413":
          description: "Arquivo maior que o limite."
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/Error"
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/firmware/{id}":
    delete:
      tags:
        - Firmware
      summary: "Remover firmware"
      description: "**Permissão:** qualquer uma de `firmware:upload`, `provisioning:manage`."
      x-required-permissions:
        - "firmware:upload"
        - "provisioning:manage"
      x-api-key: true
      x-permissions-mode: any
      operationId: delete_firmware_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/dashboard/summary:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "KPIs do painel"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_dashboard_summary
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      kpis:
                        type: object
                        properties:
                          total_devices:
                            type: integer
                          online_devices:
                            type: integer
                          offline_devices:
                            type: integer
                          warning_devices:
                            type: integer
                          pending_tasks:
                            type: integer
                          failed_tasks:
                            type: integer
                          completed_today:
                            type: integer
                      recent_activity:
                        type: array
                        items:
                          type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - info
                                - warning
                                - error
                            title:
                              type: string
                            device_id:
                              type:
                                - string
                                - "null"
                              format: uuid
                            device_serial:
                              type: string
                            created_at:
                              type: string
                              format: date-time
                      vendor_distribution:
                        type: array
                        items:
                          type: object
                          properties:
                            vendor:
                              type: string
                            oui:
                              type: string
                            count:
                              type: integer
                            percentage:
                              type: number
                      active_alerts:
                        type: array
                        items:
                          type: object
                          properties:
                            severity:
                              type: string
                            title:
                              type: string
                            device_id:
                              type: string
                              format: uuid
                            device_serial:
                              type: string
                            created_at:
                              type: string
                              format: date-time
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/dashboard/fleet-stats:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "Totais da frota"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_dashboard_fleet_stats
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      total:
                        type: integer
                      online:
                        type: integer
                      offline:
                        type: integer
                      by_oui:
                        type: array
                        items:
                          type: object
                          properties:
                            oui:
                              type: string
                            count:
                              type: integer
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/dashboard/recent-devices:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "CPEs cadastrados recentemente"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_dashboard_recent_devices
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
            default: 8
            maximum: 50
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      devices:
                        type: array
                        items:
                          type: object
                          properties:
                            id:
                              type: string
                              format: uuid
                            serial_number:
                              type: string
                            oui:
                              type: string
                            vendor:
                              type: string
                            model:
                              type:
                                - string
                                - "null"
                            ip_address:
                              type:
                                - string
                                - "null"
                            status:
                              type: string
                            created_at:
                              type: string
                              format: date-time
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reports/fleet-composition:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "Composição da frota"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_reports_fleet_composition
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      by_model:
                        type: array
                        items:
                          type: object
                          properties:
                            oui:
                              type: string
                            model:
                              type: string
                            count:
                              type: integer
                      by_firmware:
                        type: array
                        items:
                          type: object
                          properties:
                            oui:
                              type: string
                            model:
                              type: string
                            version:
                              type: string
                            count:
                              type: integer
                      growth:
                        type: array
                        items:
                          type: object
                          properties:
                            month:
                              type: string
                            new_devices:
                              type: integer
                            cumulative:
                              type: integer
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reports/critical-signal:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "Sinal óptico crítico"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_reports_critical_signal
      parameters:
        - name: days
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 90
            default: 30
        - name: below
          in: query
          schema:
            type: number
            minimum: -60
            maximum: 0
            default: -27
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      days:
                        type: integer
                      below_dbm:
                        type: number
                      devices_with_readings:
                        type: integer
                      total_critical:
                        type: integer
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            device_id:
                              type: string
                            serial_number:
                              type: string
                            oui:
                              type: string
                            model:
                              type:
                                - string
                                - "null"
                            status:
                              type: string
                            current_rx_dbm:
                              type:
                                - number
                                - "null"
                            min_rx_dbm:
                              type: number
                            critical_days:
                              type: integer
                            critical_samples:
                              type: integer
                            samples:
                              type: integer
                            last_critical_at:
                              type: string
                              format: date-time
                            source:
                              type: string
                              enum:
                                - tr069
                                - olt
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reports/offline:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "CPEs offline"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_reports_offline
      parameters:
        - name: days
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 365
            default: 7
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      days:
                        type: integer
                      total:
                        type: integer
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            device_id:
                              type: string
                            serial_number:
                              type: string
                            oui:
                              type: string
                            model:
                              type:
                                - string
                                - "null"
                            status:
                              type: string
                            ip_address:
                              type:
                                - string
                                - "null"
                            last_inform_at:
                              type:
                                - string
                                - "null"
                              format: date-time
                            days_since_last:
                              type:
                                - integer
                                - "null"
                            customer_name:
                              type:
                                - string
                                - "null"
                            plan_name:
                              type:
                                - string
                                - "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reports/alerts:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "Histórico de alertas"
      description: "**Permissão:** qualquer uma de `alerts:read`, `devices:read`."
      x-required-permissions:
        - "alerts:read"
        - "devices:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_reports_alerts
      parameters:
        - name: days
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 365
            default: 30
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      days:
                        type: integer
                      by_rule:
                        type: array
                        items:
                          type: object
                          properties:
                            rule_type:
                              type: string
                            total:
                              type: integer
                            open:
                              type: integer
                            avg_resolve_seconds:
                              type:
                                - number
                                - "null"
                      offenders:
                        type: array
                        items:
                          type: object
                          properties:
                            device_id:
                              type: string
                            serial_number:
                              type: string
                            oui:
                              type: string
                            model:
                              type:
                                - string
                                - "null"
                            alerts:
                              type: integer
                            last_opened_at:
                              type: string
                              format: date-time
                      total_open:
                        type: integer
                      total_alerts:
                        type: integer
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reports/inventory:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "Inventário completo (até 20000)"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_reports_inventory
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      total:
                        type: integer
                      truncated:
                        type: boolean
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            serial_number:
                              type: string
                            oui:
                              type: string
                            model:
                              type:
                                - string
                                - "null"
                            sw_version:
                              type:
                                - string
                                - "null"
                            hw_version:
                              type:
                                - string
                                - "null"
                            ip_address:
                              type:
                                - string
                                - "null"
                            status:
                              type: string
                            last_inform_at:
                              type:
                                - string
                                - "null"
                              format: date-time
                            created_at:
                              type: string
                              format: date-time
                            customer_name:
                              type:
                                - string
                                - "null"
                            plan_name:
                              type:
                                - string
                                - "null"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reports/wifi-signal:
    get:
      tags:
        - "Relatórios e dashboard"
      summary: "Clientes Wi-Fi com sinal fraco"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_reports_wifi_signal
      parameters:
        - name: below
          in: query
          schema:
            type: number
            minimum: -100
            maximum: -40
            default: -75
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      below_dbm:
                        type: number
                      devices_with_readings:
                        type: integer
                      total_weak:
                        type: integer
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            device_id:
                              type: string
                            serial_number:
                              type: string
                            oui:
                              type: string
                            model:
                              type:
                                - string
                                - "null"
                            status:
                              type: string
                            clients:
                              type: integer
                            weak_clients:
                              type: integer
                            worst_dbm:
                              type: number
                            read_at:
                              type: string
                              format: date-time
                            customer_name:
                              type:
                                - string
                                - "null"
                            plan_name:
                              type:
                                - string
                                - "null"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/audit:
    get:
      tags:
        - Outros
      summary: "Trilha de auditoria"
      description: "**Permissão:** `audit:read`."
      x-required-permissions:
        - "audit:read"
      x-api-key: true
      operationId: get_audit
      parameters:
        - name: q
          in: query
          schema:
            type: string
          description: "e-mail do ator ou ação"
        - name: entity_type
          in: query
          schema:
            type: string
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/AuditEntry"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/parameters/catalog:
    get:
      tags:
        - Outros
      summary: "Catálogo de parâmetros vistos na frota"
      description: "**Permissão:** qualquer uma de `catalog:read`, `devices:read`."
      x-required-permissions:
        - "catalog:read"
        - "devices:read"
      x-api-key: true
      x-permissions-mode: any
      operationId: get_parameters_catalog
      parameters:
        - name: q
          in: query
          schema:
            type: string
        - name: model
          in: query
          schema:
            type: string
            enum:
              - tr098
              - tr181
        - name: writable
          in: query
          schema:
            type: string
            enum:
              - "true"
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        path:
                          type: string
                        type:
                          type:
                            - string
                            - "null"
                        writable:
                          type:
                            - boolean
                            - "null"
                        devices:
                          type: integer
                          format: int64
                        sample_value:
                          type:
                            - string
                            - "null"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/presets:
    get:
      tags:
        - Outros
      summary: "Listar presets"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_presets
      parameters:
        - name: status
          in: query
          schema:
            type: string
            enum:
              - active
              - draft
              - archived
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Preset"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - Outros
      summary: "Criar preset"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_presets
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 80
                description:
                  type: string
                  maxLength: 300
                oui:
                  type:
                    - string
                    - "null"
                model:
                  type:
                    - string
                    - "null"
                tags:
                  type: array
                  items:
                    type: string
                  maxItems: 10
                status:
                  type: string
                  enum:
                    - active
                    - draft
                    - archived
                parameters:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                      value:
                        type: string
                      type:
                        type: string
                  minItems: 1
                  maxItems: 50
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Preset"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/presets/{id}":
    get:
      tags:
        - Outros
      summary: "Detalhe do preset"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_presets_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Preset"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - Outros
      summary: "Alterar preset (nova versão)"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: put_presets_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 80
                description:
                  type: string
                  maxLength: 300
                oui:
                  type:
                    - string
                    - "null"
                model:
                  type:
                    - string
                    - "null"
                tags:
                  type: array
                  items:
                    type: string
                  maxItems: 10
                status:
                  type: string
                  enum:
                    - active
                    - draft
                    - archived
                parameters:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                      value:
                        type: string
                      type:
                        type: string
                  minItems: 1
                  maxItems: 50
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/Preset"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/presets/{id}/versions":
    get:
      tags:
        - Outros
      summary: "Versões do preset"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_presets_id_versions
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        version:
                          type: integer
                        param_count:
                          type: integer
                        created_by:
                          type:
                            - string
                            - "null"
                          format: uuid
                        created_at:
                          type: string
                          format: date-time
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reboots/settings:
    get:
      tags:
        - Outros
      summary: "Política de reinício automático"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_reboots_settings
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      policy:
                        type: object
                        properties:
                          require_approval:
                            type: boolean
                          window_start:
                            type: integer
                          window_end:
                            type: integer
                          max_per_day:
                            type: integer
                          cooldown_days:
                            type: integer
                      rules:
                        type: array
                        items:
                          type: object
                          properties:
                            type:
                              type: string
                            enabled:
                              type: boolean
                            params: {}
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reboots/policy:
    put:
      tags:
        - Outros
      summary: "Alterar política de reinício"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: put_reboots_policy
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                require_approval:
                  type: boolean
                window_start:
                  type: integer
                window_end:
                  type: integer
                max_per_day:
                  type: integer
                cooldown_days:
                  type: integer
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                    additionalProperties: true
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/reboots/rules/{type}":
    put:
      tags:
        - Outros
      summary: "Regra de reinício"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: put_reboots_rules_type
      parameters:
        - name: type
          in: path
          required: true
          schema:
            type: string
            enum:
              - high_uptime
              - high_memory
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                params: {}
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                    additionalProperties: true
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/reboots/proposals:
    get:
      tags:
        - Outros
      summary: "Propostas de reinício"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_reboots_proposals
      parameters:
        - name: scope
          in: query
          schema:
            type: string
            enum:
              - pending
              - queue
              - history
            default: pending
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/RebootProposal"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/reboots/proposals/{id}/approve":
    post:
      tags:
        - Outros
      summary: "Proposta de reinício: approve"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_reboots_proposals_id_approve
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/reboots/proposals/{id}/reject":
    post:
      tags:
        - Outros
      summary: "Proposta de reinício: reject"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_reboots_proposals_id_reject
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "409":
          "$ref": "#/components/responses/Conflict"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/restorations:
    get:
      tags:
        - Outros
      summary: "Restaurações pós-reset"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_restorations
      parameters:
        - name: status
          in: query
          schema:
            type: string
            enum:
              - running
              - success
              - failed
              - skipped
        - name: device_id
          in: query
          schema:
            type: string
            format: uuid
        - "$ref": "#/components/parameters/Page"
        - "$ref": "#/components/parameters/PerPage"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/Restoration"
                  meta:
                    "$ref": "#/components/schemas/Meta"
                required:
                  - data
                  - meta
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/restorations/policy:
    get:
      tags:
        - Outros
      summary: "Política de restauração"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_restorations_policy
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      restore_pppoe:
                        type: boolean
                      restore_wifi:
                        type: boolean
                      extra_prefixes:
                        type: array
                        items:
                          type: string
                      bootstrap_preset_ids:
                        type: array
                        items:
                          type: string
                      excluded_models:
                        type: array
                        items:
                          type: string
                      updated_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - Outros
      summary: "Alterar política de restauração"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: put_restorations_policy
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                restore_pppoe:
                  type: boolean
                restore_wifi:
                  type: boolean
                extra_prefixes:
                  type: array
                  items:
                    type: string
                bootstrap_preset_ids:
                  type: array
                  items:
                    type: string
                excluded_models:
                  type: array
                  items:
                    type: string
                updated_at:
                  type:
                    - string
                    - "null"
                  format: date-time
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      restore_pppoe:
                        type: boolean
                      restore_wifi:
                        type: boolean
                      extra_prefixes:
                        type: array
                        items:
                          type: string
                      bootstrap_preset_ids:
                        type: array
                        items:
                          type: string
                      excluded_models:
                        type: array
                        items:
                          type: string
                      updated_at:
                        type:
                          - string
                          - "null"
                        format: date-time
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/notifications/status:
    get:
      tags:
        - Outros
      summary: "Telegram configurado?"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_notifications_status
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      telegram_configured:
                        type: boolean
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/notifications/channels:
    get:
      tags:
        - Outros
      summary: "Canais de notificação"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_notifications_channels
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/NotificationChannel"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - Outros
      summary: "Criar canal"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_notifications_channels
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 80
                target:
                  type: string
                enabled:
                  type: boolean
                  default: true
                min_severity:
                  type: string
                  enum:
                    - warning
                    - critical
                  default: warning
                rule_types:
                  type: array
                  items:
                    type: string
                notify_resolved:
                  type: boolean
                  default: true
              required:
                - name
                - target
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/NotificationChannel"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/notifications/channels/{id}":
    put:
      tags:
        - Outros
      summary: "Alterar canal"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: put_notifications_channels_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 80
                target:
                  type: string
                enabled:
                  type: boolean
                  default: true
                min_severity:
                  type: string
                  enum:
                    - warning
                    - critical
                  default: warning
                rule_types:
                  type: array
                  items:
                    type: string
                notify_resolved:
                  type: boolean
                  default: true
              required:
                - name
                - target
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/NotificationChannel"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - Outros
      summary: "Remover canal"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: delete_notifications_channels_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/notifications/channels/{id}/test":
    post:
      tags:
        - Outros
      summary: "Testar canal"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: post_notifications_channels_id_test
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "Sem corpo."
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/auto-registration-credentials:
    get:
      tags:
        - Outros
      summary: "Credenciais de autorregistro"
      description: "**Permissão:** `devices:read`."
      x-required-permissions:
        - "devices:read"
      x-api-key: true
      operationId: get_auto_registration_credentials
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      "$ref": "#/components/schemas/AutoRegCredential"
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - Outros
      summary: "Criar credencial de autorregistro"
      description: "**Permissão:** `devices:create`."
      x-required-permissions:
        - "devices:create"
      x-api-key: true
      operationId: post_auto_registration_credentials
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 200
                username:
                  type: string
                  minLength: 1
                  maxLength: 200
                password:
                  type: string
                  minLength: 4
                  maxLength: 200
                  writeOnly: true
                enabled:
                  type:
                    - boolean
                    - "null"
                notes:
                  type: string
                  maxLength: 2000
              required:
                - name
                - username
                - password
      responses:
        "201":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/AutoRegCredential"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/auto-registration-credentials/{id}":
    patch:
      tags:
        - Outros
      summary: "Alterar credencial de autorregistro"
      description: "**Permissão:** `devices:update`."
      x-required-permissions:
        - "devices:update"
      x-api-key: true
      operationId: patch_auto_registration_credentials_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 200
                username:
                  type: string
                  minLength: 1
                  maxLength: 200
                password:
                  type: string
                  minLength: 4
                  maxLength: 200
                  writeOnly: true
                enabled:
                  type:
                    - boolean
                    - "null"
                notes:
                  type: string
                  maxLength: 2000
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    "$ref": "#/components/schemas/AutoRegCredential"
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "422":
          "$ref": "#/components/responses/ValidationFailed"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - Outros
      summary: "Remover credencial de autorregistro"
      description: |-
        **Permissão:** `devices:delete`.

        Responde 200 `{"message": "credential deleted"}` (sem `data`).
      x-required-permissions:
        - "devices:delete"
      x-api-key: true
      operationId: delete_auto_registration_credentials_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/Message"
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/settings/tr069:
    get:
      tags:
        - Outros
      summary: "Credenciais TR-069 (sem senhas)"
      description: "**Permissão:** `provisioning:read`."
      x-required-permissions:
        - "provisioning:read"
      x-api-key: true
      operationId: get_settings_tr069
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      acs_username:
                        type: string
                      cr_username:
                        type: string
                      cr_use_same_as_acs:
                        type: boolean
                      has_acs_password:
                        type: boolean
                      has_cr_password:
                        type: boolean
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    patch:
      tags:
        - "Somente sessão de usuário"
      summary: "Trocar credenciais TR-069 da frota"
      description: |-
        **Permissão:** `provisioning:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "provisioning:manage"
      x-api-key: false
      operationId: patch_settings_tr069
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/settings/speed-test:
    get:
      tags:
        - Outros
      summary: "Servidores do teste de velocidade"
      description: "**Permissão:** `provisioning:read`."
      x-required-permissions:
        - "provisioning:read"
      x-api-key: true
      operationId: get_settings_speed_test
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      download_url:
                        type: string
                        maxLength: 256
                      upload_url:
                        type: string
                        maxLength: 256
                      upload_size_bytes:
                        type: integer
                        minimum: 0
                        maximum: 524288000
                        description: "0 = 10 MiB; senão 100 KiB a 500 MiB."
                required:
                  - data
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    put:
      tags:
        - Outros
      summary: "Configurar teste de velocidade"
      description: "**Permissão:** `provisioning:manage`."
      x-required-permissions:
        - "provisioning:manage"
      x-api-key: true
      operationId: put_settings_speed_test
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                download_url:
                  type: string
                  maxLength: 256
                upload_url:
                  type: string
                  maxLength: 256
                upload_size_bytes:
                  type: integer
                  minimum: 0
                  maximum: 524288000
                  description: "0 = 10 MiB; senão 100 KiB a 500 MiB."
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      download_url:
                        type: string
                        maxLength: 256
                      upload_url:
                        type: string
                        maxLength: 256
                      upload_size_bytes:
                        type: integer
                        minimum: 0
                        maximum: 524288000
                        description: "0 = 10 MiB; senão 100 KiB a 500 MiB."
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/auth/logout:
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Sair (revoga o refresh token)"
      description: |-
        **Permissão:** qualquer credencial autenticada.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions: []
      x-api-key: false
      operationId: post_auth_logout
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/auth/logout-all:
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Sair de todas as sessões"
      description: |-
        **Permissão:** qualquer credencial autenticada.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions: []
      x-api-key: false
      operationId: post_auth_logout_all
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/users:
    get:
      tags:
        - "Somente sessão de usuário"
      summary: "Listar usuários"
      description: |-
        **Permissão:** `users:read`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "users:read"
      x-api-key: false
      operationId: get_users
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Criar usuário"
      description: |-
        **Permissão:** `users:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "users:manage"
      x-api-key: false
      operationId: post_users
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/users/me:
    get:
      tags:
        - "Somente sessão de usuário"
      summary: "Meu usuário"
      description: |-
        **Permissão:** qualquer credencial autenticada.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions: []
      x-api-key: false
      operationId: get_users_me
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/users/me/password:
    patch:
      tags:
        - "Somente sessão de usuário"
      summary: "Trocar minha senha"
      description: |-
        **Permissão:** qualquer credencial autenticada.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions: []
      x-api-key: false
      operationId: patch_users_me_password
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/users/invite:
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Convidar usuário"
      description: |-
        **Permissão:** `users:invite`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "users:invite"
      x-api-key: false
      operationId: post_users_invite
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/users/{id}":
    get:
      tags:
        - "Somente sessão de usuário"
      summary: "Detalhe do usuário"
      description: |-
        **Permissão:** `users:read`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "users:read"
      x-api-key: false
      operationId: get_users_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    patch:
      tags:
        - "Somente sessão de usuário"
      summary: "Alterar usuário"
      description: |-
        **Permissão:** `users:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "users:manage"
      x-api-key: false
      operationId: patch_users_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    delete:
      tags:
        - "Somente sessão de usuário"
      summary: "Remover usuário"
      description: |-
        **Permissão:** `users:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "users:manage"
      x-api-key: false
      operationId: delete_users_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/users/{id}/status":
    patch:
      tags:
        - "Somente sessão de usuário"
      summary: "Ativar/suspender usuário"
      description: |-
        **Permissão:** `users:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "users:manage"
      x-api-key: false
      operationId: patch_users_id_status
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/users/{id}/reset-password":
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Redefinir senha do usuário"
      description: |-
        **Permissão:** `users:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "users:manage"
      x-api-key: false
      operationId: post_users_id_reset_password
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/roles/{id}/permissions":
    put:
      tags:
        - "Somente sessão de usuário"
      summary: "Definir permissões do papel"
      description: |-
        **Permissão:** `roles:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "roles:manage"
      x-api-key: false
      operationId: put_roles_id_permissions
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/api-keys:
    get:
      tags:
        - "Somente sessão de usuário"
      summary: "Listar API keys"
      description: |-
        **Permissão:** `api_keys:read`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "api_keys:read"
      x-api-key: false
      operationId: get_api_keys
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Criar API key"
      description: |-
        **Permissão:** `api_keys:create`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "api_keys:create"
      x-api-key: false
      operationId: post_api_keys
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/api-keys/{id}":
    delete:
      tags:
        - "Somente sessão de usuário"
      summary: "Revogar API key"
      description: |-
        **Permissão:** `api_keys:revoke`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "api_keys:revoke"
      x-api-key: false
      operationId: delete_api_keys_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/settings/billing/portal-session:
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Abrir portal de cobrança (Stripe)"
      description: |-
        **Permissão:** `billing:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "billing:manage"
      x-api-key: false
      operationId: post_settings_billing_portal_session
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/settings/billing/acs-credential:
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Revelar senha ACS do cadastro (uma vez)"
      description: |-
        **Permissão:** `provisioning:manage`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "provisioning:manage"
      x-api-key: false
      operationId: post_settings_billing_acs_credential
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/approve":
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Aprovar campanha"
      description: |-
        **Permissão:** `campaigns:create`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "campaigns:create"
      x-api-key: false
      operationId: post_campaigns_id_approve
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/campaigns/{id}/reject":
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Recusar campanha"
      description: |-
        **Permissão:** `campaigns:create`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "campaigns:create"
      x-api-key: false
      operationId: post_campaigns_id_reject
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/writes":
    put:
      tags:
        - "Somente sessão de usuário"
      summary: "Ligar/desligar escrita na OLT"
      description: |-
        **Permissão:** `olts:write`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "olts:write"
      x-api-key: false
      operationId: put_olts_id_writes
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/ssh-host-key/accept":
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Aceitar chave SSH da OLT"
      description: |-
        **Permissão:** `olts:write`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "olts:write"
      x-api-key: false
      operationId: post_olts_id_ssh_host_key_accept
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/batches/{batchId}/approve":
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Aprovar lote de comandos"
      description: |-
        **Permissão:** `olts:write`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "olts:write"
      x-api-key: false
      operationId: post_olts_id_batches_batchId_approve
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: batchId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/olts/{id}/batches/{batchId}/reject":
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Recusar lote de comandos"
      description: |-
        **Permissão:** `olts:write`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "olts:write"
      x-api-key: false
      operationId: post_olts_id_batches_batchId_reject
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: batchId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/allowlist:
    get:
      tags:
        - "Somente sessão de usuário"
      summary: "Allowlist do /acs (superadmin)"
      description: |-
        **Permissão:** `allowlist:manage:global`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "allowlist:manage:global"
      x-api-key: false
      operationId: get_allowlist
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
    post:
      tags:
        - "Somente sessão de usuário"
      summary: "Adicionar à allowlist (superadmin)"
      description: |-
        **Permissão:** `allowlist:manage:global`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "allowlist:manage:global"
      x-api-key: false
      operationId: post_allowlist
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  "/api/v1/allowlist/{id}":
    delete:
      tags:
        - "Somente sessão de usuário"
      summary: "Remover da allowlist (superadmin)"
      description: |-
        **Permissão:** `allowlist:manage:global`.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.
      x-required-permissions:
        - "allowlist:manage:global"
      x-api-key: false
      operationId: delete_allowlist_id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
  /api/v1/admin/tenants:
    get:
      tags:
        - "Somente sessão de usuário"
      summary: "Painel do superadmin (/api/v1/admin/*)"
      description: |-
        **Permissão:** qualquer credencial autenticada.

        **Somente sessão de usuário** — API key recebe 403 `this endpoint is not available to API keys; use a user session`.

        Todas as rotas `/api/v1/admin/*` (tenants, planos, dashboard global, auditoria global, informs não registrados, impersonação) exigem usuário superadmin.
      x-required-permissions: []
      x-api-key: false
      operationId: get_admin_tenants
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties: {}
                required:
                  - data
        "400":
          "$ref": "#/components/responses/BadRequest"
        "401":
          "$ref": "#/components/responses/Unauthorized"
        "403":
          "$ref": "#/components/responses/Forbidden"
        "404":
          "$ref": "#/components/responses/NotFound"
        "429":
          "$ref": "#/components/responses/TooManyRequests"
        "500":
          "$ref": "#/components/responses/ServerError"
      security:
        - bearer: []
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      bearerFormat: "acsd_<48 hex> | JWT"
      description: "API key (`acsd_` + 48 hex, criada em Configurações → Integrações → API keys) ou access token JWT de uma sessão de usuário."
  parameters:
    Page:
      name: page
      in: query
      description: "Página, a partir de 1."
      schema:
        type: integer
        minimum: 1
        default: 1
    PerPage:
      name: per_page
      in: query
      description: "Itens por página (padrão 20, máximo 100; acima disso vira 100)."
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 20
    PageSize:
      name: page_size
      in: query
      description: "Nome preferido nesta rota; `per_page` é aceito como alias."
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 20
  responses:
    BadRequest:
      description: "Requisição inválida."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
          example:
            error: "invalid request body"
    Unauthorized:
      description: "Credencial ausente, inválida, expirada ou revogada — ou tenant suspenso/cancelado."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
          examples:
            apiKey:
              value:
                error: "invalid or revoked api key"
            missing:
              value:
                error: "missing or malformed authorization header"
            jwt:
              value:
                error: "invalid or expired token"
    Forbidden:
      description: "Falta escopo, rota só para usuário ou recurso fora do plano."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
          examples:
            permission:
              value:
                error: "permission required: devices:update"
            anyOf:
              value:
                error: "one of the following permissions is required: [alerts:read devices:read]"
            humanOnly:
              value:
                error: "this endpoint is not available to API keys; use a user session"
            plan:
              value:
                error: "plan_feature_unavailable: o plano atual não inclui campaigns; faça upgrade para o Profissional"
    NotFound:
      description: "Não existe ou é de outro tenant."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
          example:
            error: "device not found"
    Conflict:
      description: "Conflito de estado."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
    ValidationFailed:
      description: "Validação por campo."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/ValidationError"
    TooManyRequests:
      description: "Mais de 600 requisições no minuto para esta API key."
      headers:
        Retry-After:
          description: "Segundos até a próxima janela."
          schema:
            type: integer
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
          example:
            error: "too many requests, try again later"
    ServerError:
      description: "Erro interno."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
          example:
            error: "failed to list devices"
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string
          description: "Mensagem do erro (em inglês, estável para log)."
      required:
        - error
    ValidationError:
      type: object
      properties:
        error:
          type: string
          const: validation_failed
        fields:
          type: object
          properties: {}
          additionalProperties:
            type: string
          description: "Campo → mensagem (ex.: `this field is required`)."
      required:
        - error
        - fields
      example:
        error: validation_failed
        fields:
          name: "must be at least 3 characters"
    Meta:
      type: object
      properties:
        page:
          type: integer
        per_page:
          type: integer
        total_items:
          type: integer
          format: int64
        total_pages:
          type: integer
      required:
        - page
        - per_page
        - total_items
        - total_pages
    ItemsPagination:
      type: object
      properties:
        page:
          type: integer
        page_size:
          type: integer
        total:
          type: integer
          format: int64
        total_pages:
          type: integer
      required:
        - page
        - page_size
        - total
        - total_pages
      description: "Paginação do envelope `{items, pagination}` (lista de CPEs, fila do CPE, lista de tarefas)."
    Message:
      type: object
      properties:
        message:
          type: string
    ConnectionRequestResult:
      type: object
      properties:
        device_id:
          type: string
        url:
          type: string
        status_code:
          type: integer
          description: "Omitido quando o CPE não respondeu."
        success:
          type: boolean
        error:
          type: string
        auth_method:
          type: string
        duration_ms:
          type: integer
          format: int64
        status:
          type: string
          enum:
            - CR_OK
            - CR_AUTH_FAILED
            - CR_UNREACHABLE
            - CR_NOT_CONFIGURED
            - CR_NO_URL
            - CR_FAILED
            - CR_UNKNOWN
      required:
        - device_id
        - url
        - success
      description: "Resultado do Connection Request (acordar o CPE agora). `success: false` não cancela a tarefa: ela sai no próximo Inform periódico."
    DeviceStatus:
      type: string
      enum:
        - unknown
        - online
        - offline
        - provisioning
        - error
    Device:
      type: object
      properties:
        id:
          type: string
          format: uuid
        tenant_id:
          type: string
          format: uuid
        serial_number:
          type: string
        oui:
          type: string
        product_class:
          type:
            - string
            - "null"
        model_id:
          type:
            - string
            - "null"
          format: uuid
        sw_version:
          type:
            - string
            - "null"
        hw_version:
          type:
            - string
            - "null"
        ip_address:
          type:
            - string
            - "null"
        connection_request_url:
          type:
            - string
            - "null"
        provisioning_profile_id:
          type:
            - string
            - "null"
          format: uuid
        data_model:
          type:
            - string
            - "null"
          description: "TR-098 ou TR-181."
        status:
          "$ref": "#/components/schemas/DeviceStatus"
        last_inform_at:
          type:
            - string
            - "null"
          format: date-time
        inform_interval:
          type: integer
        tags:
          type: array
          items:
            type: string
          description: "Pode vir null."
        notes:
          type:
            - string
            - "null"
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    DeviceListItem:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: "UUID interno: é o `{id}` dos demais endpoints."
        serial_number:
          type: string
        model:
          type:
            - string
            - "null"
          description: "= product_class"
        vendor:
          type: string
        product_class:
          type:
            - string
            - "null"
        oui:
          type: string
        ip_address:
          type:
            - string
            - "null"
        status:
          "$ref": "#/components/schemas/DeviceStatus"
        last_seen_at:
          type:
            - string
            - "null"
          format: date-time
        firmware_version:
          type:
            - string
            - "null"
        health_label:
          type:
            - string
            - "null"
          enum:
            - normal
            - warning
            - critical
            - null
        created_at:
          type: string
          format: date-time
        tags:
          type: array
          items:
            type: string
        rx_power_dbm:
          type: number
          description: "Omitido sem leitura."
        tx_power_dbm:
          type: number
        uptime_seconds:
          type: integer
          format: int64
        customer_name:
          type:
            - string
            - "null"
        plan_name:
          type:
            - string
            - "null"
    Parameter:
      type: object
      properties:
        device_id:
          type: string
          format: uuid
        param_key:
          type: string
        param_value:
          type:
            - string
            - "null"
        fetched_at:
          type: string
          format: date-time
        writable:
          type:
            - boolean
            - "null"
        type:
          type:
            - string
            - "null"
        notification:
          type:
            - integer
            - "null"
        access_list:
          type:
            - string
            - "null"
      description: "Linha crua de `device_parameters`. Valores sensíveis de Wi-Fi ficam cifrados no banco e saem assim."
    ParamNode:
      type: object
      properties:
        name:
          type: string
          description: "Objetos terminam em `.`"
        label:
          type: string
        object:
          type: boolean
        child_count:
          type: integer
        param_count:
          type: integer
        value:
          type:
            - string
            - "null"
          description: "`********` quando `secret`."
        secret:
          type: boolean
        type:
          type:
            - string
            - "null"
        writable:
          type:
            - boolean
            - "null"
        notification:
          type:
            - integer
            - "null"
        access_list:
          type:
            - string
            - "null"
        fetched_at:
          type:
            - string
            - "null"
          format: date-time
        oldest_fetched_at:
          type: string
          format: date-time
    WifiRadio:
      type: object
      properties:
        wlan_index:
          type: integer
        band:
          type: string
          enum:
            - "2.4ghz"
            - "5ghz"
            - unknown
        role:
          type: string
          enum:
            - main
            - guest
            - mesh
            - auxiliary
            - disabled
        enabled:
          type:
            - boolean
            - "null"
        ssid:
          type:
            - string
            - "null"
        security_mode:
          type:
            - string
            - "null"
        channel:
          type:
            - string
            - "null"
        channel_width:
          type:
            - string
            - "null"
        password_available:
          type: boolean
        guest_network_enabled:
          type:
            - boolean
            - "null"
    ConnectedHost:
      type: object
      properties:
        index:
          type: integer
        ip_address:
          type:
            - string
            - "null"
        mac_address:
          type:
            - string
            - "null"
        hostname:
          type:
            - string
            - "null"
        active:
          type:
            - boolean
            - "null"
        interface_type:
          type:
            - string
            - "null"
          description: "`Ethernet`, `Wi-Fi`, `Wi-Fi 5G` ou o valor cru do CPE."
        address_source:
          type:
            - string
            - "null"
        signal_dbm:
          type:
            - number
            - "null"
        signal_quality:
          type:
            - string
            - "null"
          enum:
            - good
            - fair
            - weak
            - null
    WANConnection:
      type: object
      properties:
        connection_path:
          type: string
        kind:
          type: string
          enum:
            - ip
            - ppp
        label:
          type: string
        wan_ip:
          type:
            - string
            - "null"
        gateway:
          type:
            - string
            - "null"
        dns:
          type: array
          items:
            type: string
        connection_type:
          type: string
          enum:
            - dhcp
            - pppoe
            - static
            - unknown
        name:
          type:
            - string
            - "null"
        enabled:
          type:
            - boolean
            - "null"
        status:
          type:
            - string
            - "null"
        vlan:
          type:
            - string
            - "null"
        service_list:
          type:
            - string
            - "null"
        purpose:
          type: string
          enum:
            - service
            - management
            - voip
            - other
            - unknown
        purpose_source:
          type: string
          enum:
            - servicelist
            - name
            - none
        stale:
          type: boolean
        last_param_at:
          type:
            - string
            - "null"
          format: date-time
    DiagnosticRun:
      type: object
      properties:
        id:
          type: string
          format: uuid
        device_id:
          type: string
          format: uuid
        kind:
          type: string
          enum:
            - ping
            - traceroute
            - download
            - upload
        status:
          type: string
          enum:
            - requested
            - complete
            - error
            - expired
        target:
          type: string
        task_id:
          type:
            - string
            - "null"
          format: uuid
        diagnostics_state:
          type:
            - string
            - "null"
        mbps:
          type:
            - number
            - "null"
        result:
          description: "Objeto de status gravado, ou null."
        created_at:
          type: string
          format: date-time
        completed_at:
          type:
            - string
            - "null"
          format: date-time
      description: "Execução de diagnóstico; expira em 15 min sem resposta."
    DiagnosticTrigger:
      type: object
      properties:
        task_id:
          type:
            - string
            - "null"
          format: uuid
        connection_request:
          oneOf:
            - "$ref": "#/components/schemas/ConnectionRequestResult"
            - type: "null"
        skipped:
          type: boolean
        skip_reason:
          type: string
        run_id:
          type: string
          format: uuid
      description: "`skipped: true` (`device has pending SPV task`) quando já há um SetParameterValues pendente."
    CPELookup:
      type: object
      properties:
        device_id:
          type: string
          format: uuid
        serial_number:
          type: string
        model:
          type:
            - string
            - "null"
        vendor:
          type:
            - string
            - "null"
        status:
          type: string
        last_inform_at:
          type:
            - string
            - "null"
          format: date-time
        pppoe_login:
          type:
            - string
            - "null"
        wan_ip:
          type:
            - string
            - "null"
        customer:
          type:
            - object
            - "null"
          properties:
            id:
              type: string
            contract_id:
              type:
                - string
                - "null"
            name:
              type:
                - string
                - "null"
            source:
              type: string
              enum:
                - own
                - onu
        onu:
          type:
            - object
            - "null"
          properties:
            serial:
              type: string
            status:
              type: string
            rx_power_dbm:
              type:
                - number
                - "null"
            olt:
              type: string
            pon:
              type:
                - string
                - "null"
              description: "`slot/porta`"
    DeviceCustomer:
      type: object
      properties:
        customer_id:
          type: string
        customer_name:
          type: string
        contract_id:
          type: string
        contract_status:
          type: string
        plan_name:
          type: string
        pppoe_login:
          type: string
        match_method:
          type: string
        synced_at:
          type: string
          format: date-time
        via:
          type: string
          enum:
            - own
            - onu
        onu_serial:
          type: string
          description: "Só com `via: onu`."
    DeviceOptical:
      type: object
      properties:
        olt_id:
          type: string
          format: uuid
        olt_name:
          type: string
        olt_vendor:
          type: string
        olt_last_ok_at:
          type:
            - string
            - "null"
          format: date-time
        olt_last_error:
          type:
            - string
            - "null"
        pon_slot:
          type:
            - integer
            - "null"
        pon_port:
          type:
            - integer
            - "null"
        pon_technology:
          type:
            - string
            - "null"
        pon_tx_dbm:
          type:
            - number
            - "null"
        onu_id:
          type: string
          format: uuid
        onu_index:
          type:
            - integer
            - "null"
        serial_number:
          type: string
        mac:
          type:
            - string
            - "null"
        status:
          type: string
        rx_dbm:
          type:
            - number
            - "null"
        tx_dbm:
          type:
            - number
            - "null"
        distance_m:
          type:
            - integer
            - "null"
        last_status_at:
          type:
            - string
            - "null"
          format: date-time
        last_disconnect_at:
          type:
            - string
            - "null"
          format: date-time
        last_polled_at:
          type:
            - string
            - "null"
          format: date-time
        link_method:
          type: string
        device_status:
          type: string
        device_last_inform_at:
          type:
            - string
            - "null"
          format: date-time
        diagnosis:
          type: string
          enum:
            - fiber_los
            - power_off
            - onu_offline
            - cpe_no_inform
            - ok
            - stale
            - unknown
        stale:
          type: boolean
    Session:
      type: object
      properties:
        id:
          type: string
          format: uuid
        device_id:
          type: string
          format: uuid
        tenant_id:
          type: string
          format: uuid
        started_at:
          type: string
          format: date-time
        ended_at:
          type:
            - string
            - "null"
          format: date-time
        inform_event_codes:
          type: array
          items:
            type: string
        remote_addr:
          type:
            - string
            - "null"
        error:
          type:
            - string
            - "null"
        cwmp_version:
          type:
            - string
            - "null"
        inform_bytes:
          type:
            - integer
            - "null"
    SessionInfo:
      type: object
      properties:
        id:
          type: string
          format: uuid
        started_at:
          type: string
          format: date-time
        ended_at:
          type:
            - string
            - "null"
          format: date-time
        remote_addr:
          type:
            - string
            - "null"
        inform_event_codes:
          type: array
          items:
            type: string
        error:
          type:
            - string
            - "null"
        rpc_count:
          type: integer
        fault_count:
          type: integer
        has_response_xml:
          type: boolean
    AuditEntry:
      type: object
      properties:
        id:
          type: string
          format: uuid
        created_at:
          type: string
          format: date-time
        actor_type:
          type: string
          description: "`user` ou `api_key`."
        actor_email:
          type:
            - string
            - "null"
          description: "Para API key: `api-key:<nome>`."
        action:
          type: string
        entity_type:
          type:
            - string
            - "null"
        entity_id:
          type:
            - string
            - "null"
          format: uuid
        result:
          type: string
        source_module:
          type:
            - string
            - "null"
        before_state: {}
        after_state: {}
        impersonator_email:
          type:
            - string
            - "null"
    TaskType:
      type: string
      enum:
        - get_param_values
        - set_param_values
        - reboot
        - factory_reset
        - firmware_upgrade
        - custom
    TaskStatus:
      type: string
      enum:
        - pending
        - dispatched
        - executing
        - completed
        - failed
        - cancelled
    Task:
      type: object
      properties:
        id:
          type: string
          format: uuid
        tenant_id:
          type: string
          format: uuid
        device_id:
          type: string
          format: uuid
        type:
          "$ref": "#/components/schemas/TaskType"
        status:
          "$ref": "#/components/schemas/TaskStatus"
        priority:
          type: integer
          minimum: 1
          maximum: 10
        payload:
          description: "Parâmetros da tarefa; segredos saem como `********`."
        created_by:
          type:
            - string
            - "null"
          format: uuid
          description: "null quando criada por API key."
        scheduled_at:
          type:
            - string
            - "null"
          format: date-time
        expires_at:
          type:
            - string
            - "null"
          format: date-time
        dispatched_at:
          type:
            - string
            - "null"
          format: date-time
        completed_at:
          type:
            - string
            - "null"
          format: date-time
        cancelled_at:
          type:
            - string
            - "null"
          format: date-time
        cancelled_by:
          type:
            - string
            - "null"
          format: uuid
        cancel_reason:
          type:
            - string
            - "null"
        error:
          type:
            - string
            - "null"
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        serial_number:
          type: string
          description: "Só na listagem/detalhe (omitido se null)."
        ip_address:
          type: string
        oui:
          type: string
        model:
          type: string
        manufacturer:
          type: string
    TaskDetail:
      allOf:
        - "$ref": "#/components/schemas/Task"
        - type: object
          properties:
            attempts_count:
              type: integer
            last_execution:
              type:
                - object
                - "null"
              properties:
                id:
                  type: string
                  format: uuid
                attempt_num:
                  type: integer
                status:
                  "$ref": "#/components/schemas/TaskStatus"
                rpc_method:
                  type:
                    - string
                    - "null"
                started_at:
                  type: string
                  format: date-time
                ended_at:
                  type:
                    - string
                    - "null"
                  format: date-time
                error:
                  type:
                    - string
                    - "null"
    TaskExecution:
      type: object
      properties:
        id:
          type: string
          format: uuid
        task_id:
          type: string
          format: uuid
        tenant_id:
          type: string
          format: uuid
        attempt_num:
          type: integer
        started_at:
          type: string
          format: date-time
        ended_at:
          type:
            - string
            - "null"
          format: date-time
        status:
          "$ref": "#/components/schemas/TaskStatus"
        session_id:
          type:
            - string
            - "null"
          format: uuid
        rpc_method:
          type:
            - string
            - "null"
        response_xml:
          type:
            - string
            - "null"
          description: "Segredos mascarados."
        error:
          type:
            - string
            - "null"
    CreateTask:
      type: object
      properties:
        device_id:
          type: string
          format: uuid
        type:
          "$ref": "#/components/schemas/TaskType"
        priority:
          type: integer
          minimum: 1
          maximum: 10
          default: 5
          description: "0/ausente = 5."
        payload:
          type: object
          properties: {}
          description: |-
            Depende de `type`:

            - `reboot`, `factory_reset`: vazio.
            - `get_param_values`: `{"parameter_names": ["Device.DeviceInfo."]}`.
            - `set_param_values`: `{"parameters": [{"name","value","type"}]}` ou mapa `{"Caminho": "valor"}`; `param_key` opcional.
            - `firmware_upgrade`: `url` (http/https/ftp), `file_type` (`firmware`|`config`), opcionais `username`, `password`, `file_size`, `target_filename`, `delay_seconds`.
            - `custom`: repassado como está.
          additionalProperties: true
        scheduled_at:
          type:
            - string
            - "null"
          format: date-time
        expires_at:
          type:
            - string
            - "null"
          format: date-time
      required:
        - device_id
        - type
    Alert:
      type: object
      properties:
        id:
          type: string
          format: uuid
        device_id:
          type:
            - string
            - "null"
          format: uuid
        subject_type:
          type: string
          enum:
            - device
            - onu
            - pon
        serial_number:
          type: string
        oui:
          type: string
        model:
          type:
            - string
            - "null"
        olt_id:
          type:
            - string
            - "null"
          format: uuid
        olt_name:
          type:
            - string
            - "null"
        rule_type:
          type: string
        severity:
          type: string
          enum:
            - warning
            - critical
        status:
          type: string
          enum:
            - open
            - acknowledged
            - resolved
        details: {}
        opened_at:
          type: string
          format: date-time
        acknowledged_at:
          type:
            - string
            - "null"
          format: date-time
        resolved_at:
          type:
            - string
            - "null"
          format: date-time
    AlertRule:
      type: object
      properties:
        type:
          type: string
        enabled:
          type: boolean
        severity:
          type: string
          enum:
            - warning
            - critical
        params:
          type: object
          properties: {}
          additionalProperties:
            type: number
    Incident:
      type: object
      properties:
        id:
          type: string
          format: uuid
        number:
          type: integer
          format: int64
        kind:
          type: string
          enum:
            - outage
            - olt_unreachable
        scope:
          type: string
          enum:
            - pon
            - slot
            - olt
        olt_id:
          type: string
          format: uuid
        olt_name:
          type: string
        pon_id:
          type:
            - string
            - "null"
          format: uuid
        pon_label:
          type:
            - string
            - "null"
        slot:
          type:
            - integer
            - "null"
        class:
          type: string
          enum:
            - power_probable
            - optical_probable
            - undefined
        state:
          type: string
          enum:
            - open
            - confirmed
            - dismissed
            - closed
        started_at:
          type: string
          format: date-time
        detected_at:
          type: string
          format: date-time
        ended_at:
          type:
            - string
            - "null"
          format: date-time
        affected_onus:
          type: integer
        active_onus_in_scope:
          type: integer
        pct_affected:
          type:
            - number
            - "null"
        dying_gasp_count:
          type: integer
        los_count:
          type: integer
        owner_user_id:
          type:
            - string
            - "null"
          format: uuid
        owner_email:
          type:
            - string
            - "null"
        confirmed_at:
          type:
            - string
            - "null"
          format: date-time
        dismissed_at:
          type:
            - string
            - "null"
          format: date-time
        dismiss_reason:
          type:
            - string
            - "null"
        outcome:
          type:
            - string
            - "null"
        closed_at:
          type:
            - string
            - "null"
          format: date-time
        closed_by:
          type:
            - string
            - "null"
          format: uuid
          description: "null quando fechado por API key."
        reopen_count:
          type: integer
        alert_id:
          type:
            - string
            - "null"
          format: uuid
        customers_linked:
          type: integer
        vip_affected:
          type: integer
        version:
          type: integer
          description: "Controle otimista: envie nas ações."
    IncidentDetail:
      allOf:
        - "$ref": "#/components/schemas/Incident"
        - type: object
          properties:
            onus:
              type: array
              items:
                type: object
                properties:
                  onu_id:
                    type: string
                    format: uuid
                  serial_number:
                    type: string
                  mac:
                    type:
                      - string
                      - "null"
                  pon_label:
                    type:
                      - string
                      - "null"
                  onu_index:
                    type:
                      - integer
                      - "null"
                  status:
                    type: string
                  down_status:
                    type: string
                  went_down_at:
                    type: string
                    format: date-time
                  came_back_at:
                    type:
                      - string
                      - "null"
                    format: date-time
                  vip:
                    type: boolean
                  vip_label:
                    type:
                      - string
                      - "null"
                  device_id:
                    type:
                      - string
                      - "null"
                    format: uuid
                  customer_name:
                    type:
                      - string
                      - "null"
                  contract_id:
                    type:
                      - string
                      - "null"
                  customer_id:
                    type:
                      - string
                      - "null"
                  contract_status:
                    type:
                      - string
                      - "null"
            timeline:
              type: array
              items:
                type: object
                properties:
                  id:
                    type: integer
                    format: int64
                  kind:
                    type: string
                  actor_user_id:
                    type:
                      - string
                      - "null"
                    format: uuid
                  actor_email:
                    type:
                      - string
                      - "null"
                  details: {}
                  created_at:
                    type: string
                    format: date-time
    IncidentAction:
      type: object
      properties:
        version:
          type: integer
          description: "Versão lida; divergente → 409."
        user_id:
          type:
            - string
            - "null"
          format: uuid
          description: "assign: dono (null remove)."
        reason:
          type: string
          maxLength: 1000
          description: "Obrigatório em dismiss."
        outcome:
          type: string
          maxLength: 1000
          description: "Obrigatório em outcome; em close se ainda não houver."
    IncidentThresholds:
      type: object
      properties:
        enabled:
          type: boolean
        min_onus:
          type: integer
          minimum: 2
          maximum: 1000
        min_percent:
          type: integer
          minimum: 1
          maximum: 100
        window_seconds:
          type: integer
          minimum: 30
          maximum: 3600
        slot_min_pons:
          type: integer
          minimum: 2
          maximum: 64
        power_percent:
          type: integer
          minimum: 1
          maximum: 100
        los_percent:
          type: integer
          minimum: 1
          maximum: 100
        close_percent:
          type: integer
          minimum: 1
          maximum: 100
        close_minutes:
          type: integer
          minimum: 0
          maximum: 1440
        reopen_minutes:
          type: integer
          minimum: 0
          maximum: 1440
        unreachable_failures:
          type: integer
          minimum: 1
          maximum: 100
    MaintenanceWindow:
      type: object
      properties:
        id:
          type: string
          format: uuid
        number:
          type: integer
          format: int64
        olt_id:
          type: string
          format: uuid
        olt_name:
          type: string
        scope:
          type: string
          enum:
            - olt
            - pon
        pons:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              label:
                type: string
        title:
          type: string
        reason:
          type:
            - string
            - "null"
        starts_at:
          type: string
          format: date-time
        ends_at:
          type: string
          format: date-time
        status:
          type: string
          enum:
            - scheduled
            - active
            - finished
            - cancelled
        notify_start:
          type: boolean
        notify_end:
          type: boolean
        degrade_threshold_db:
          type: number
        created_by:
          type:
            - string
            - "null"
          format: uuid
        created_by_email:
          type:
            - string
            - "null"
        cancelled_at:
          type:
            - string
            - "null"
          format: date-time
        compared_at:
          type:
            - string
            - "null"
          format: date-time
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        onus_in_scope:
          type: integer
        suppressed_drops:
          type: integer
    MaintenanceInput:
      type: object
      properties:
        olt_id:
          type: string
          format: uuid
        pon_ids:
          type: array
          items:
            type: string
            format: uuid
          maxItems: 256
          description: "Vazio = OLT inteira."
        title:
          type: string
          minLength: 1
          maxLength: 200
        reason:
          type: string
          maxLength: 2000
        starts_at:
          type: string
          format: date-time
        ends_at:
          type: string
          format: date-time
        notify_start:
          type: boolean
        notify_end:
          type: boolean
        degrade_threshold_db:
          type:
            - number
            - "null"
          minimum: 0.5
          maximum: 20
          default: 2.0
      required:
        - olt_id
        - title
        - starts_at
        - ends_at
      description: "Janela de até 72 h, início no máximo 5 min no passado e até 180 dias à frente. PUT substitui tudo."
    MaintenanceDetail:
      allOf:
        - "$ref": "#/components/schemas/MaintenanceWindow"
        - type: object
          properties:
            drops:
              type: array
              items:
                type: object
                properties:
                  onu_id:
                    type: string
                    format: uuid
                  serial_number:
                    type: string
                  mac:
                    type:
                      - string
                      - "null"
                  pon_label:
                    type:
                      - string
                      - "null"
                  onu_index:
                    type:
                      - integer
                      - "null"
                  vip:
                    type: boolean
                  vip_label:
                    type:
                      - string
                      - "null"
                  status:
                    type: string
                  down_status:
                    type: string
                  first_down_at:
                    type: string
                    format: date-time
                  last_down_at:
                    type: string
                    format: date-time
                  drops:
                    type: integer
                  came_back_at:
                    type:
                      - string
                      - "null"
                    format: date-time
            comparison:
              type: object
              properties:
                evaluated:
                  type: boolean
                compared_at:
                  type:
                    - string
                    - "null"
                  format: date-time
                threshold_db:
                  type: number
                summary:
                  type: object
                  properties:
                    total:
                      type: integer
                    lost:
                      type: integer
                    degraded:
                      type: integer
                    improved:
                      type: integer
                    ok:
                      type: integer
                    recovered:
                      type: integer
                    still_down:
                      type: integer
                    unknown:
                      type: integer
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      onu_id:
                        type: string
                        format: uuid
                      serial_number:
                        type: string
                      status_before:
                        type: string
                      rx_before:
                        type:
                          - number
                          - "null"
                      status_after:
                        type: string
                      rx_after:
                        type:
                          - number
                          - "null"
                      delta_db:
                        type:
                          - number
                          - "null"
                      cto_code:
                        type:
                          - string
                          - "null"
                      cto_port:
                        type:
                          - integer
                          - "null"
                      verdict:
                        type: string
                        enum:
                          - lost
                          - degraded
                          - improved
                          - ok
                          - recovered
                          - still_down
                          - unknown
            vip_alerts:
              type: array
              items:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                  onu_id:
                    type: string
                    format: uuid
                  serial:
                    type: string
                  vip_label:
                    type:
                      - string
                      - "null"
                  status:
                    type: string
                  opened_at:
                    type: string
                    format: date-time
            timeline:
              type: array
              items:
                type: object
                properties:
                  id:
                    type: integer
                    format: int64
                  kind:
                    type: string
                  actor_user_id:
                    type:
                      - string
                      - "null"
                    format: uuid
                  actor_email:
                    type:
                      - string
                      - "null"
                  details: {}
                  created_at:
                    type: string
                    format: date-time
    OLT:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        vendor:
          type: string
          enum:
            - vsol
            - huawei
            - zte
            - fiberhome
        model:
          type:
            - string
            - "null"
        host:
          type: string
        mgmt_protocol:
          type: string
          enum:
            - ssh
            - telnet
            - https
            - snmp
        mgmt_port:
          type: integer
        username:
          type: string
        password_set:
          type: boolean
          description: "A senha nunca é devolvida."
        snmp_version:
          type:
            - string
            - "null"
        snmp_port:
          type:
            - integer
            - "null"
        snmp_community_set:
          type: boolean
        enabled:
          type: boolean
        poll_interval_seconds:
          type: integer
        last_polled_at:
          type:
            - string
            - "null"
          format: date-time
        last_ok_at:
          type:
            - string
            - "null"
          format: date-time
        last_error:
          type:
            - string
            - "null"
        firmware_version:
          type:
            - string
            - "null"
        poll_failures:
          type: integer
        last_poll_duration_ms:
          type:
            - integer
            - "null"
        external_source:
          type:
            - string
            - "null"
        collect_source:
          type: string
          enum:
            - direct
            - oltcloud
        temperature_c:
          type:
            - number
            - "null"
        uptime_seconds:
          type:
            - integer
            - "null"
          format: int64
        last_reboot_at:
          type:
            - string
            - "null"
          format: date-time
        optical_paused_until:
          type:
            - string
            - "null"
          format: date-time
        writes_enabled:
          type: boolean
        writes_enabled_at:
          type:
            - string
            - "null"
          format: date-time
        writes_enabled_by:
          type:
            - string
            - "null"
        ssh_host_key:
          type:
            - string
            - "null"
        ssh_host_key_at:
          type:
            - string
            - "null"
          format: date-time
        writes_supported:
          type: boolean
        security:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              severity:
                type: string
                enum:
                  - critical
                  - high
                  - medium
                  - info
              certainty:
                type: string
                enum:
                  - affected
                  - possible
                  - config
              key:
                type: string
              source:
                type: string
        pon_count:
          type: integer
        onu_count:
          type: integer
        onu_online_count:
          type: integer
        onu_down_count:
          type: integer
        onu_critical_count:
          type: integer
        onu_offline_count:
          type: integer
        onu_los_count:
          type: integer
        onu_power_off_count:
          type: integer
        onu_inactive_count:
          type: integer
        unauthorized_count:
          type: integer
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    OLTInput:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 120
        vendor:
          type: string
          enum:
            - vsol
            - huawei
            - zte
            - fiberhome
          description: "Não muda depois."
        model:
          type:
            - string
            - "null"
        host:
          type: string
        mgmt_protocol:
          type: string
          enum:
            - ssh
            - telnet
            - https
            - snmp
        mgmt_port:
          type: integer
          minimum: 0
          maximum: 65535
          description: "0 = padrão do protocolo."
        username:
          type: string
          maxLength: 120
        password:
          type: string
          maxLength: 500
          writeOnly: true
          description: "Só escrita; vazio/null no PUT mantém."
        snmp_version:
          type:
            - string
            - "null"
          description: "`2c` ou vazio."
        snmp_port:
          type:
            - integer
            - "null"
        snmp_community:
          type:
            - string
            - "null"
          writeOnly: true
        enabled:
          type: boolean
          default: true
        poll_interval_seconds:
          type: integer
          minimum: 60
          maximum: 86400
          default: 300
      description: "POST exige `name`, `vendor` e `host`. No PUT todos os campos são opcionais."
    PON:
      type: object
      properties:
        id:
          type: string
          format: uuid
        olt_id:
          type: string
          format: uuid
        slot:
          type: integer
        port:
          type: integer
        technology:
          type: string
        max_onus:
          type: integer
        onu_count:
          type: integer
        online_count:
          type: integer
        down_count:
          type: integer
        los_count:
          type: integer
        tx_power_dbm:
          type:
            - number
            - "null"
        temperature_c:
          type:
            - number
            - "null"
        last_polled_at:
          type:
            - string
            - "null"
          format: date-time
    ONU:
      type: object
      properties:
        id:
          type: string
          format: uuid
        olt_id:
          type: string
          format: uuid
        pon_id:
          type:
            - string
            - "null"
          format: uuid
        serial_number:
          type: string
        mac:
          type:
            - string
            - "null"
        onu_index:
          type:
            - integer
            - "null"
        model:
          type:
            - string
            - "null"
        description:
          type:
            - string
            - "null"
        pppoe_login:
          type:
            - string
            - "null"
        status:
          type: string
          enum:
            - online
            - offline
            - los
            - power_off
            - inactive
            - unknown
        rx_dbm:
          type:
            - number
            - "null"
        tx_dbm:
          type:
            - number
            - "null"
        olt_rx_dbm:
          type:
            - number
            - "null"
        distance_m:
          type:
            - integer
            - "null"
        last_status_at:
          type:
            - string
            - "null"
          format: date-time
        last_disconnect_at:
          type:
            - string
            - "null"
          format: date-time
        last_polled_at:
          type:
            - string
            - "null"
          format: date-time
        device_id:
          type:
            - string
            - "null"
          format: uuid
          description: "CPE (roteador) vinculado."
        link_method:
          type:
            - string
            - "null"
        device_serial:
          type:
            - string
            - "null"
        customer_name:
          type:
            - string
            - "null"
        customer_contract_id:
          type:
            - string
            - "null"
        customer_method:
          type:
            - string
            - "null"
          enum:
            - ixc_pppoe
            - ixc_onu_serial
            - oltcloud_contract
            - via_cpe
            - null
        customer_source:
          type:
            - string
            - "null"
          enum:
            - onu
            - cpe
            - null
        behind_macs:
          type: array
          items:
            type: string
          description: "Pode vir null."
        vip:
          type: boolean
        vip_label:
          type:
            - string
            - "null"
        cto_id:
          type:
            - string
            - "null"
          format: uuid
        cto_code:
          type:
            - string
            - "null"
        cto_port:
          type:
            - integer
            - "null"
        temperature_c:
          type:
            - number
            - "null"
        voltage_v:
          type:
            - number
            - "null"
        bias_ma:
          type:
            - number
            - "null"
        alive_seconds:
          type:
            - integer
            - "null"
          format: int64
        online_since:
          type:
            - string
            - "null"
          format: date-time
        last_reg_at_raw:
          type:
            - string
            - "null"
        last_dereg_at_raw:
          type:
            - string
            - "null"
        last_dereg_reason:
          type:
            - string
            - "null"
        olt_name:
          type: string
        pon_slot:
          type:
            - integer
            - "null"
        pon_port:
          type:
            - integer
            - "null"
        pon_technology:
          type:
            - string
            - "null"
    UnauthorizedONU:
      type: object
      properties:
        id:
          type: string
          format: uuid
        olt_id:
          type: string
          format: uuid
        olt_name:
          type: string
        pon_id:
          type:
            - string
            - "null"
          format: uuid
        pon_index:
          type: integer
        pon_slot:
          type:
            - integer
            - "null"
        pon_port:
          type:
            - integer
            - "null"
        pon_technology:
          type:
            - string
            - "null"
        mac:
          type: string
        loid:
          type:
            - string
            - "null"
        found_at_raw:
          type:
            - string
            - "null"
        first_seen_at:
          type: string
          format: date-time
        last_seen_at:
          type: string
          format: date-time
    TriangulationRow:
      type: object
      properties:
        onu_id:
          type: string
          format: uuid
        olt_id:
          type: string
          format: uuid
        olt_name:
          type: string
        pon_slot:
          type:
            - integer
            - "null"
        pon_port:
          type:
            - integer
            - "null"
        pon_technology:
          type:
            - string
            - "null"
        onu_index:
          type:
            - integer
            - "null"
        serial_number:
          type: string
        mac:
          type:
            - string
            - "null"
        pppoe_login:
          type:
            - string
            - "null"
        behind_macs:
          type: array
          items:
            type: string
        onu_status:
          type: string
        rx_dbm:
          type:
            - number
            - "null"
        customer_id:
          type:
            - string
            - "null"
        customer_name:
          type:
            - string
            - "null"
        contract_id:
          type:
            - string
            - "null"
        contract_status:
          type:
            - string
            - "null"
        customer_method:
          type:
            - string
            - "null"
        customer_confidence:
          type:
            - string
            - "null"
        device_id:
          type:
            - string
            - "null"
          format: uuid
        link_method:
          type:
            - string
            - "null"
        device_serial:
          type:
            - string
            - "null"
        device_model:
          type:
            - string
            - "null"
        cpe_customer_id:
          type:
            - string
            - "null"
        cpe_customer_name:
          type:
            - string
            - "null"
        cpe_contract_id:
          type:
            - string
            - "null"
        cpe_customer_method:
          type:
            - string
            - "null"
        ambiguous_cpe_method:
          type:
            - string
            - "null"
        ambiguous_customer_method:
          type:
            - string
            - "null"
        status:
          type: string
          enum:
            - ok
            - partial
            - conflict
            - missing
            - ambiguous
    OLTCommand:
      type: object
      properties:
        id:
          type: string
          format: uuid
        olt_id:
          type: string
          format: uuid
        onu_id:
          type:
            - string
            - "null"
          format: uuid
        batch_id:
          type:
            - string
            - "null"
          format: uuid
        batch_seq:
          type: integer
        action:
          type: string
          enum:
            - authorize
            - deauthorize
            - reboot
            - set_description
            - factory_reset
        params:
          type: object
          properties:
            pon:
              type: integer
            onu_id:
              type: integer
            mac:
              type: string
            loid:
              type: string
            auth_method:
              type: string
            description:
              type: string
            save_config:
              type: boolean
            profile_id:
              type: string
            profile_name:
              type: string
        dry_run:
          type: boolean
        state:
          type: string
          enum:
            - previewed
            - pending
            - running
            - succeeded
            - failed
            - unverified
            - cancelled
        reason:
          type: string
        requested_by:
          type:
            - string
            - "null"
        executed_by:
          type:
            - string
            - "null"
        approved_by:
          type:
            - string
            - "null"
        cli_preview:
          type: string
        output:
          type:
            - string
            - "null"
        readback:
          description: "Leitura de conferência após a escrita (`verdict`, `detail`, `before`, `after`)."
        error:
          type:
            - string
            - "null"
        attempts:
          type: integer
        created_at:
          type: string
          format: date-time
        confirmed_at:
          type:
            - string
            - "null"
          format: date-time
        started_at:
          type:
            - string
            - "null"
          format: date-time
        finished_at:
          type:
            - string
            - "null"
          format: date-time
        onu_description:
          type:
            - string
            - "null"
    OLTBatch:
      type: object
      properties:
        id:
          type: string
          format: uuid
        olt_id:
          type: string
          format: uuid
        action:
          type: string
        state:
          type: string
          enum:
            - previewed
            - awaiting_approval
            - running
            - paused
            - completed
            - cancelled
            - rejected
        total:
          type: integer
        reason:
          type: string
        requested_by:
          type:
            - string
            - "null"
        approved_by:
          type:
            - string
            - "null"
        approved_at:
          type:
            - string
            - "null"
          format: date-time
        paused_reason:
          type:
            - string
            - "null"
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        counts:
          type: object
          properties: {}
          additionalProperties:
            type: integer
        needs_approval:
          type: boolean
        commands:
          type: array
          items:
            "$ref": "#/components/schemas/OLTCommand"
          description: "Só no GET por id e nas ações."
    CTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        code:
          type: string
        description:
          type:
            - string
            - "null"
        kind:
          type: string
          enum:
            - cto
            - ceo
            - other
        capacity:
          type: integer
        splitter:
          type:
            - string
            - "null"
        pon_id:
          type:
            - string
            - "null"
          format: uuid
        pon_slot:
          type:
            - integer
            - "null"
        pon_port:
          type:
            - integer
            - "null"
        pon_technology:
          type:
            - string
            - "null"
        olt_id:
          type:
            - string
            - "null"
          format: uuid
        olt_name:
          type:
            - string
            - "null"
        projected_attenuation_db:
          type:
            - number
            - "null"
        latitude:
          type:
            - number
            - "null"
        longitude:
          type:
            - number
            - "null"
        address:
          type:
            - string
            - "null"
        city:
          type:
            - string
            - "null"
        status:
          type: string
          enum:
            - active
            - inactive
            - planned
        validated_at:
          type:
            - string
            - "null"
          format: date-time
        validated_by:
          type:
            - string
            - "null"
          format: uuid
        validated_by_email:
          type:
            - string
            - "null"
        external_source:
          type:
            - string
            - "null"
        ports_free:
          type: integer
        ports_occupied:
          type: integer
        ports_reserved:
          type: integer
        ports_faulty:
          type: integer
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    CTODetail:
      allOf:
        - "$ref": "#/components/schemas/CTO"
        - type: object
          properties:
            ports:
              type: array
              items:
                type: object
                properties:
                  number:
                    type: integer
                  state:
                    type: string
                    enum:
                      - free
                      - occupied
                      - reserved
                      - faulty
                  onu_id:
                    type:
                      - string
                      - "null"
                    format: uuid
                  onu_serial:
                    type:
                      - string
                      - "null"
                  onu_status:
                    type:
                      - string
                      - "null"
                  onu_rx_dbm:
                    type:
                      - number
                      - "null"
                  onu_olt_id:
                    type:
                      - string
                      - "null"
                    format: uuid
                  onu_olt_name:
                    type:
                      - string
                      - "null"
                  device_id:
                    type:
                      - string
                      - "null"
                    format: uuid
                  customer_ref:
                    type:
                      - string
                      - "null"
                  reserved_until:
                    type:
                      - string
                      - "null"
                    format: date-time
                  reserved_for:
                    type:
                      - string
                      - "null"
                  updated_at:
                    type: string
                    format: date-time
    CTOInput:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          maxLength: 80
        description:
          type: string
        kind:
          type: string
          enum:
            - cto
            - ceo
            - other
          default: cto
        capacity:
          type: integer
          minimum: 1
          maximum: 256
        splitter:
          type: string
        pon_id:
          type: string
          description: "UUID; `\"\"` desvincula."
        projected_attenuation_db:
          type: number
          minimum: 0
          maximum: 60
        clear_attenuation:
          type: boolean
        latitude:
          type: number
        longitude:
          type: number
        clear_location:
          type: boolean
        address:
          type: string
        city:
          type: string
        status:
          type: string
          enum:
            - active
            - inactive
            - planned
        validated:
          type: boolean
      description: "Todos opcionais; `capacity` obrigatório na criação."
    Webhook:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        url:
          type: string
        event_types:
          type: array
          items:
            type: string
        enabled:
          type: boolean
        disabled_reason:
          type:
            - string
            - "null"
        disabled_at:
          type:
            - string
            - "null"
          format: date-time
        consecutive_failures:
          type: integer
        secret_rotating:
          type: boolean
        created_by:
          type:
            - string
            - "null"
          format: uuid
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        pending_count:
          type: integer
        failed_count_24h:
          type: integer
        last_delivery_at:
          type:
            - string
            - "null"
          format: date-time
        last_delivery_status:
          type:
            - string
            - "null"
      description: "O segredo nunca aparece aqui."
    WebhookInput:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 120
        url:
          type: string
          format: uri
          description: "`https://` obrigatório; destinos internos recusados."
        event_types:
          type: array
          items:
            type: string
            enum:
              - incident.opened
              - incident.updated
              - incident.closed
              - onu.down
              - onu.up
              - onu.vip.status_changed
              - onu.signal_degraded
              - onu.authorized
              - device.factory_reset
              - device.restored
          minItems: 1
        enabled:
          type: boolean
          default: true
      description: "POST exige `name`, `url` e `event_types`; no PUT todos são opcionais."
    WebhookWithSecret:
      type: object
      properties:
        webhook:
          "$ref": "#/components/schemas/Webhook"
        secret:
          type: string
          description: "`whsec_` + 64 hex. Mostrado só aqui."
    WebhookDelivery:
      type: object
      properties:
        id:
          type: string
          format: uuid
        event_id:
          type: string
          format: uuid
        event_type:
          type: string
        ordering_key:
          type: string
        sequence:
          type: integer
          format: int64
        status:
          type: string
          enum:
            - pending
            - delivered
            - failed
        attempts:
          type: integer
        next_attempt_at:
          type: string
          format: date-time
        last_attempt_at:
          type:
            - string
            - "null"
          format: date-time
        last_http_status:
          type:
            - integer
            - "null"
        last_latency_ms:
          type:
            - integer
            - "null"
        last_error:
          type:
            - string
            - "null"
        delivered_at:
          type:
            - string
            - "null"
          format: date-time
        created_at:
          type: string
          format: date-time
        occurred_at:
          type: string
          format: date-time
        data: {}
    WebhookEvent:
      type: object
      properties:
        version:
          type: string
          const: "1"
        event_id:
          type: string
          format: uuid
        type:
          type: string
        occurred_at:
          type: string
          format: date-time
        ordering_key:
          type: string
        sequence:
          type: integer
          format: int64
        tenant_id:
          type: string
          format: uuid
        data:
          description: "Muda por tipo; ver `GET /api/v1/webhooks/catalog`."
      description: "Corpo que o Horus envia (POST) ao seu endpoint, assinado em `X-Horus-Signature`."
    IXCSettings:
      type: object
      properties:
        enabled:
          type: boolean
        base_url:
          type: string
        username:
          type: string
        password_set:
          type: boolean
        sync_status:
          type: string
          enum:
            - idle
            - running
            - ok
            - error
        sync_started_at:
          type:
            - string
            - "null"
          format: date-time
        sync_finished_at:
          type:
            - string
            - "null"
          format: date-time
        sync_error:
          type:
            - string
            - "null"
        sync_total:
          type: integer
        sync_linked:
          type: integer
        sync_ambiguous:
          type: integer
        sync_unlinked:
          type: integer
    HubsoftSettings:
      type: object
      properties:
        enabled:
          type: boolean
        base_url:
          type: string
        client_id:
          type: string
        client_secret_set:
          type: boolean
        username:
          type: string
        password_set:
          type: boolean
        sync_status:
          type: string
          enum:
            - idle
            - running
            - ok
            - error
        sync_started_at:
          type:
            - string
            - "null"
          format: date-time
        sync_finished_at:
          type:
            - string
            - "null"
          format: date-time
        sync_error:
          type:
            - string
            - "null"
        sync_total:
          type: integer
        sync_linked:
          type: integer
        sync_ambiguous:
          type: integer
        sync_unlinked:
          type: integer
    ERPUnlinked:
      type: object
      properties:
        items:
          type: array
          items:
            type: object
            properties:
              device_id:
                type: string
                format: uuid
              serial_number:
                type: string
              pppoe_login:
                type: string
              reason:
                type: string
                enum:
                  - not_found
                  - ambiguous
                  - no_customer
                  - no_identifier
              model:
                type:
                  - string
                  - "null"
              status:
                type: string
              synced_at:
                type: string
                format: date-time
        counts:
          type: object
          properties: {}
          additionalProperties:
            type: integer
        meta:
          "$ref": "#/components/schemas/Meta"
      description: "Atenção: aqui `meta` fica dentro de `data`."
    ImportRun:
      type: object
      properties:
        id:
          type: string
          format: uuid
        source:
          type: string
          enum:
            - genieacs
            - oltcloud
        dry_run:
          type: boolean
        status:
          type: string
          enum:
            - running
            - done
            - error
        source_url:
          type: string
        report:
          description: "Relatório (muda por origem)."
        error:
          type:
            - string
            - "null"
        started_at:
          type: string
          format: date-time
        finished_at:
          type:
            - string
            - "null"
          format: date-time
    OltCloudSync:
      type: object
      properties:
        enabled:
          type: boolean
        base_url:
          type: string
        username:
          type: string
        password_set:
          type: boolean
        interval_seconds:
          type: integer
        timezone:
          type: string
        running:
          type: boolean
        last_run_at:
          type:
            - string
            - "null"
          format: date-time
        last_ok_at:
          type:
            - string
            - "null"
          format: date-time
        last_error:
          type:
            - string
            - "null"
        last_duration_ms:
          type:
            - integer
            - "null"
        last_report:
          description: "Relatório da última rodada (`olts_ok`, `onus`, `updated`, `created`, `missing`...)."
        updated_at:
          type:
            - string
            - "null"
          format: date-time
        olts:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              name:
                type: string
              vendor:
                type: string
              host:
                type: string
              enabled:
                type: boolean
              collect_source:
                type: string
                enum:
                  - oltcloud
                  - direct
              password_set:
                type: boolean
              last_ok_at:
                type:
                  - string
                  - "null"
                format: date-time
              last_error:
                type:
                  - string
                  - "null"
              onu_count:
                type: integer
              private_host:
                type: boolean
    TargetFilter:
      type: object
      properties:
        scope:
          type: string
          enum:
            - all
            - vendor
            - status
            - signal
            - plan
            - list
        ouis:
          type: array
          items:
            type: string
        status:
          "$ref": "#/components/schemas/DeviceStatus"
        signal:
          type: string
          enum:
            - attention
            - no_data
        plans:
          type: array
          items:
            type: string
        product_classes:
          type: array
          items:
            type: string
        sw_versions:
          type: array
          items:
            type: string
        tags:
          type: array
          items:
            type: string
        olt_ids:
          type: array
          items:
            type: string
            format: uuid
        pon_ids:
          type: array
          items:
            type: string
            format: uuid
        statuses:
          type: array
          items:
            type: string
        include_serials:
          type: array
          items:
            type: string
          maxItems: 10000
        exclude_serials:
          type: array
          items:
            type: string
          maxItems: 10000
      required:
        - scope
    CampaignParam:
      type: object
      properties:
        key:
          type: string
        value:
          type: string
        type:
          type: string
          enum:
            - "xsd:string"
            - "xsd:int"
            - "xsd:unsignedInt"
            - "xsd:boolean"
            - "xsd:dateTime"
      required:
        - key
        - value
    Rollout:
      type: object
      properties:
        pilot_size:
          type: integer
          minimum: 0
          maximum: 100
        verify_minutes:
          type: integer
          minimum: 5
          maximum: 1440
        wave_size:
          type: integer
          minimum: 0
          maximum: 100000
          description: "0 = todo o resto de uma vez."
        max_failure_percent:
          type: integer
          minimum: 0
          maximum: 100
        start_at:
          type:
            - string
            - "null"
          format: date-time
        window:
          type:
            - object
            - "null"
          properties:
            start_hour:
              type: integer
              minimum: 0
              maximum: 23
            end_hour:
              type: integer
              minimum: 0
              maximum: 23
          description: "Horário de Brasília."
    CampaignInput:
      type: object
      properties:
        name:
          type: string
          minLength: 2
          maxLength: 120
        target_filter:
          "$ref": "#/components/schemas/TargetFilter"
        content_type:
          type: string
          enum:
            - params
            - preset
            - firmware
            - reboot
          description: "Vazio = params."
        params:
          type: array
          items:
            "$ref": "#/components/schemas/CampaignParam"
          minItems: 1
          maxItems: 20
        preset_id:
          type: string
          format: uuid
        preset_version:
          type: integer
        firmware_id:
          type: string
          format: uuid
        rollout:
          oneOf:
            - "$ref": "#/components/schemas/Rollout"
            - type: "null"
        param_key:
          type: string
          description: "Legado (um parâmetro só)."
        param_value:
          type: string
        param_type:
          type: string
      required:
        - name
        - target_filter
    Campaign:
      type: object
      properties:
        id:
          type: string
          format: uuid
        tenant_id:
          type: string
          format: uuid
        name:
          type: string
        status:
          type: string
          enum:
            - draft
            - running
            - completed
            - cancelled
            - failed
        effective_status:
          type: string
          description: "Inclui `paused`."
        target_filter:
          "$ref": "#/components/schemas/TargetFilter"
        params:
          type: array
          items:
            "$ref": "#/components/schemas/CampaignParam"
        total_targets:
          type: integer
        approval_status:
          type: string
          enum:
            - none
            - pending
            - approved
            - rejected
        decided_by:
          type:
            - string
            - "null"
          format: uuid
        decided_at:
          type:
            - string
            - "null"
          format: date-time
        decision_note:
          type:
            - string
            - "null"
        revert_of:
          type:
            - string
            - "null"
          format: uuid
        content_type:
          type: string
        content:
          description: "preset/firmware resolvido."
        rollout:
          oneOf:
            - "$ref": "#/components/schemas/Rollout"
            - type: "null"
        current_wave:
          type: integer
          description: "-1 = não começou."
        total_waves:
          type: integer
        wave_started_at:
          type:
            - string
            - "null"
          format: date-time
        accepted_wave:
          type: integer
        rollout_done_at:
          type:
            - string
            - "null"
          format: date-time
        paused_at:
          type:
            - string
            - "null"
          format: date-time
        paused_reason:
          type:
            - string
            - "null"
          enum:
            - manual
            - pilot_failed
            - pilot_timeout
            - wave_failed
            - null
        paused_detail:
          type:
            - string
            - "null"
        created_by:
          type:
            - string
            - "null"
          format: uuid
          description: "null quando criada por API key."
        launched_at:
          type:
            - string
            - "null"
          format: date-time
        completed_at:
          type:
            - string
            - "null"
          format: date-time
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        progress:
          type: object
          properties:
            total:
              type: integer
            draft:
              type: integer
            queued:
              type: integer
            delivered:
              type: integer
            confirmed:
              type: integer
            failed:
              type: integer
            cancelled:
              type: integer
        waves:
          type: array
          items:
            type: object
            properties:
              wave:
                type: integer
              total:
                type: integer
              pending:
                type: integer
              in_flight:
                type: integer
              completed:
                type: integer
              recovered:
                type: integer
              failed:
                type: integer
              cancelled:
                type: integer
              mismatch:
                type: integer
        phase:
          type: string
          enum:
            - scheduled
            - pilot
            - waves
            - done
    FirmwareImage:
      type: object
      properties:
        id:
          type: string
          format: uuid
        vendor:
          type: string
        product_class:
          type: string
        version:
          type: string
        url:
          type: string
        file_name:
          type:
            - string
            - "null"
        stored:
          type: boolean
        file_type:
          type: string
          enum:
            - "1 Firmware Upgrade Image"
            - "3 Vendor Configuration File"
        file_size:
          type:
            - integer
            - "null"
        checksum:
          type:
            - string
            - "null"
        notes:
          type:
            - string
            - "null"
        created_at:
          type: string
          format: date-time
        devices:
          type: integer
          description: "CPEs do mesmo product_class."
        on_version:
          type: integer
    SystemInfo:
      type: object
      properties:
        tenant:
          type: object
          properties:
            id:
              type: string
              format: uuid
            name:
              type: string
            slug:
              type: string
            status:
              type: string
              enum:
                - active
                - suspended
                - cancelled
            plan_name:
              type:
                - string
                - "null"
            devices:
              type: integer
            max_devices:
              type:
                - integer
                - "null"
        sessions:
          type: object
          properties:
            access_ttl_minutes:
              type: integer
            refresh_ttl_days:
              type: integer
        retention:
          type: object
          properties:
            inform_history_days:
              type: integer
            olt_history_days:
              type: integer
        operations:
          type: object
          properties:
            task_reaper_mode:
              type: string
            wan_write_mode:
              type: string
            olt_collector_enabled:
              type: boolean
            audit_logging:
              type: boolean
        plan_usage:
          type:
            - object
            - "null"
          properties:
            plan_code:
              type: string
            plan_name:
              type: string
            active_cpes:
              type: integer
            onus:
              type: integer
            subscribers:
              type: integer
              description: "maior entre CPEs e ONUs"
            max_subscribers:
              type:
                - integer
                - "null"
              description: "null = sem limite"
            usage_percent:
              type:
                - number
                - "null"
            near_limit:
              type: boolean
            over_limit:
              type: boolean
            features:
              type: object
              properties: {}
              additionalProperties:
                type: boolean
    Me:
      type: object
      properties:
        auth_type:
          type: string
          enum:
            - user
            - api_key
        user_id:
          type: string
          format: uuid
          description: "Para API key: o id da chave."
        tenant_id:
          type: string
          format: uuid
        email:
          type: string
          description: "Para API key: `api-key:<nome>`."
        role_id:
          type: string
          format: uuid
          description: "Para API key: UUID zero."
        permissions:
          type: array
          items:
            type: string
          description: "Para API key: os escopos efetivos."
        is_superadmin:
          type: boolean
      example:
        auth_type: api_key
        user_id: "6f1c2d3e-0000-4000-8000-000000000001"
        tenant_id: "0b9e8f7a-0000-4000-8000-000000000002"
        email: "api-key:app-wifi"
        role_id: "00000000-0000-0000-0000-000000000000"
        permissions:
          - "devices:read"
          - "devices:update"
          - "tasks:read"
        is_superadmin: false
    Preset:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        description:
          type: string
        oui:
          type:
            - string
            - "null"
        model:
          type:
            - string
            - "null"
        tags:
          type: array
          items:
            type: string
        status:
          type: string
          enum:
            - active
            - draft
            - archived
        version:
          type: integer
        parameters:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              value:
                type: string
              type:
                type: string
        created_by:
          type:
            - string
            - "null"
          format: uuid
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    Restoration:
      type: object
      properties:
        id:
          type: string
          format: uuid
        device_id:
          type: string
          format: uuid
        serial_number:
          type: string
        model:
          type:
            - string
            - "null"
        trigger:
          type: string
          enum:
            - bootstrap
            - manual
        status:
          type: string
          enum:
            - running
            - success
            - failed
            - skipped
        reason:
          type:
            - string
            - "null"
        skipped_params:
          type: array
          items:
            type: string
        snapshot_at:
          type:
            - string
            - "null"
          format: date-time
        created_by:
          type:
            - string
            - "null"
          format: uuid
        created_at:
          type: string
          format: date-time
        finished_at:
          type:
            - string
            - "null"
          format: date-time
        steps:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              group:
                type: string
              label:
                type: string
              status:
                type: string
              spv_task_id:
                type:
                  - string
                  - "null"
                format: uuid
              verify_task_id:
                type:
                  - string
                  - "null"
                format: uuid
              params:
                type: array
                items:
                  type: string
              unverified_params:
                type: array
                items:
                  type: string
              mismatched_params:
                type: array
                items:
                  type: string
              error:
                type:
                  - string
                  - "null"
    NotificationChannel:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        target:
          type: string
          description: "chat id do Telegram ou @usuario"
        enabled:
          type: boolean
        min_severity:
          type: string
          enum:
            - warning
            - critical
        rule_types:
          type: array
          items:
            type: string
        notify_resolved:
          type: boolean
        created_at:
          type: string
          format: date-time
    RebootProposal:
      type: object
      properties:
        id:
          type: string
          format: uuid
        device_id:
          type: string
          format: uuid
        serial_number:
          type: string
        oui:
          type: string
        model:
          type:
            - string
            - "null"
        rule_type:
          type: string
        reason: {}
        status:
          type: string
        created_at:
          type: string
          format: date-time
        decided_at:
          type:
            - string
            - "null"
          format: date-time
        executed_at:
          type:
            - string
            - "null"
          format: date-time
        error:
          type:
            - string
            - "null"
    Role:
      type: object
      properties:
        id:
          type: string
          format: uuid
        tenant_id:
          type:
            - string
            - "null"
          format: uuid
        name:
          type: string
        description:
          type: string
        is_system_role:
          type: boolean
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    Permission:
      type: object
      properties:
        id:
          type: string
          format: uuid
        module:
          type: string
        action:
          type: string
        scope:
          type: string
          enum:
            - own_tenant
            - global
            - assigned_devices
        description:
          type: string
    Branding:
      type: object
      properties:
        id:
          type: string
          format: uuid
        tenant_id:
          type: string
          format: uuid
        app_name:
          type:
            - string
            - "null"
        logo_url:
          type:
            - string
            - "null"
        favicon_url:
          type:
            - string
            - "null"
        primary_color:
          type: string
        secondary_color:
          type: string
        custom_domain:
          type:
            - string
            - "null"
        updated_at:
          type: string
          format: date-time
    AutoRegCredential:
      type: object
      properties:
        id:
          type: string
          format: uuid
        tenant_id:
          type: string
          format: uuid
        name:
          type: string
        username:
          type: string
        enabled:
          type: boolean
        notes:
          type:
            - string
            - "null"
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
webhooks:
  horusEvent:
    post:
      summary: "Evento enviado pelo Horus ao seu endpoint"
      description: "Headers: `X-Horus-Event`, `X-Horus-Event-Id`, `X-Horus-Delivery`, `X-Horus-Sequence`, `X-Horus-Ordering-Key`, `X-Horus-Timestamp`, `X-Horus-Signature` (`sha256=` + hex(HMAC-SHA256(segredo, timestamp + \".\" + corpo))). Responda 2xx em até 10 s."
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/WebhookEvent"
      responses:
        "200":
          description: Recebido.
