{
  "openapi": "3.1.0",
  "info": {
    "title": "Noori ACS — leituras do painel operacional",
    "version": "1.0.0"
  },
  "security": [
    {
      "session": []
    }
  ],
  "paths": {
    "/api/v1/dashboard": {
      "get": {
        "operationId": "readDashboard",
        "description": "Exige devices:read e tenant da sessão. Sem period mantém contrato legado. Com period acrescenta readings. Não envia RPC à CPE. Hosts atuais limitados a 500 snapshots válidos, com cobertura explícita; null significa ausência de evidência. Histórico mede comunicação CWMP em janelas de 15 minutos, não hosts nem PPPoE.",
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1H",
                "6H",
                "24H",
                "7D",
                "30D"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resumo existente e leituras opcionais",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "online": {
                      "type": "integer"
                    },
                    "offline": {
                      "type": "integer"
                    },
                    "readings": {
                      "type": "object",
                      "required": [
                        "generatedAt",
                        "period",
                        "source",
                        "windowMinutes",
                        "connected",
                        "history",
                        "historyNote"
                      ],
                      "properties": {
                        "generatedAt": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "period": {
                          "type": "string",
                          "enum": [
                            "1H",
                            "6H",
                            "24H",
                            "7D",
                            "30D"
                          ]
                        },
                        "source": {
                          "type": "string",
                          "const": "ACS_CWMP_SESSIONS"
                        },
                        "windowMinutes": {
                          "type": "integer",
                          "const": 15
                        },
                        "historyNote": {
                          "type": "string"
                        },
                        "connected": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": [
                                "integer",
                                "null"
                              ]
                            },
                            "coveredCpes": {
                              "type": "integer"
                            },
                            "totalCpes": {
                              "type": "integer"
                            },
                            "evaluatedCpes": {
                              "type": "integer"
                            },
                            "complete": {
                              "type": "boolean"
                            },
                            "observedAt": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "format": "date-time"
                            },
                            "source": {
                              "type": "string"
                            },
                            "historyAvailable": {
                              "type": "boolean",
                              "const": false
                            }
                          }
                        },
                        "history": {
                          "type": "array",
                          "maxItems": 61,
                          "items": {
                            "type": "object",
                            "properties": {
                              "at": {
                                "type": "string",
                                "format": "date-time"
                              },
                              "online": {
                                "type": [
                                  "integer",
                                  "null"
                                ]
                              },
                              "total": {
                                "type": [
                                  "integer",
                                  "null"
                                ]
                              }
                            }
                          }
                        }
                      }
                    }
                  },
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Período inválido"
          },
          "401": {
            "description": "Sessão ausente"
          },
          "403": {
            "description": "devices:read ausente"
          }
        }
      }
    },
    "/api/v1/global-search": {
      "get": {
        "operationId": "searchOperationalResources",
        "description": "Busca existente, tenant-scoped, exige customers:read. Amplia correspondência por fabricante, modelo e MAC. Endereços IP e endpoints de gerência só participam com device_web:view. Parâmetros de senha nunca são pesquisados ou devolvidos.",
        "parameters": [
          {
            "in": "query",
            "name": "q",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Agrupamentos existentes de clientes, serviços e CPEs"
          },
          "401": {
            "description": "Sem sessão"
          },
          "403": {
            "description": "Sem permissão"
          }
        }
      }
    },
    "/api/v1/devices": {
      "get": {
        "operationId": "listDashboardDevices",
        "description": "Lista existente exige devices:read, limitada e tenant-scoped. Acrescenta management_address nullable apenas com device_web:view, proveniente de endpoint OBSERVED ou CONFIRMED do mesmo tenant/device. Demais campos preservados.",
        "responses": {
          "200": {
            "description": "Lista existente com endereço de gerência opcional"
          },
          "401": {
            "description": "Sem sessão"
          },
          "403": {
            "description": "Sem permissão"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "nooriacs_session"
      }
    }
  }
}
