{
  "openapi": "3.1.0",
  "info": {
    "title": "NooriACS — compatibilidade dos perfis por versão instalada",
    "version": "1.1.1",
    "description": " Perfis ativos ja homologados e sem pacotes vinculados podem editar telemetria preservando identidade, modelo de dados, compatibilidade e escopo de hardware. Esta edicao nao autoriza download nem remocao do ultimo pacote de perfis vinculados."
  },
  "security": [
    {
      "sessionCookie": []
    }
  ],
  "paths": {
    "/api/v1/wifi-profiles": {
      "get": {
        "operationId": "listCpeProfiles",
        "description": "provisioning:read; somente tenant autenticado. Lista existente sem paginação.",
        "responses": {
          "200": {
            "description": "Perfis e política persistida",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "items"
                  ],
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Profile"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Sem permissão ou origem inválida"
          }
        }
      },
      "post": {
        "operationId": "createCpeProfile",
        "description": "provisioning:write; tenant vem da sessão. Firmware IDs exigem firmware:approve.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProfileWrite"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Perfil criado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "400": {
            "description": "Campo inválido; CPE_PROFILE_COMPATIBILITY_INVALID ou CPE_PROFILE_COMPATIBILITY_FIRMWARE_REQUIRED"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Sem permissão ou origem inválida"
          },
          "409": {
            "description": "Nome/identidade/versões duplicados ou vínculo de firmware exige revalidação"
          }
        }
      }
    },
    "/api/v1/wifi-profiles/{profileId}": {
      "parameters": [
        {
          "name": "profileId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "updateCpeProfile",
        "description": "provisioning:write; registra revisão e auditoria; sem mudança direta na ONT. Política vale no próximo despacho e seleção. Sem upgrade automático.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProfileWrite"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Perfil atualizado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "400": {
            "description": "Campo inválido; CPE_PROFILE_COMPATIBILITY_INVALID ou CPE_PROFILE_COMPATIBILITY_FIRMWARE_REQUIRED"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Sem permissão ou origem inválida"
          },
          "404": {
            "description": "Perfil ausente no tenant autenticado"
          },
          "409": {
            "description": "Nome/identidade/versões duplicados ou vínculo de firmware exige revalidação"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "nooriacs_session"
      }
    },
    "schemas": {
      "Compatibility": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "firmwareVersions",
          "excludedAttributePrefixes"
        ],
        "properties": {
          "firmwareVersions": {
            "type": "array",
            "maxItems": 32,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "description": "Versões completas exatas informadas pela ONT. Vazio é perfil genérico; perfil específico tem precedência."
          },
          "excludedAttributePrefixes": {
            "type": "array",
            "maxItems": 32,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "maxLength": 512,
              "pattern": "^(Device|InternetGatewayDevice)\\.(?:[A-Za-z0-9_:-]+\\.)+$"
            },
            "description": "Subárvores sem GetParameterAttributes, incluindo consultas ao ancestral. Não restringe GetParameterValues. Requer firmwareVersions não vazio."
          },
          "wifiInputAliases": {
            "type": "array",
            "maxItems": 16,
            "description": "Aliases explícitos de entrada Basic por banda/campo. Exigem firmware delimitado e slot único no perfil homologado. PUT omitido preserva; [] remove. Escrita usa somente destino canônico do perfil, nunca o caminho recebido.",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "path",
                "band",
                "field"
              ],
              "properties": {
                "path": {
                  "type": "string",
                  "maxLength": 512,
                  "description": "Folha Wi-Fi TR-181 ou TR-098 de SSID ou KeyPassphrase/PreSharedKey, coerente com field; caminho único."
                },
                "band": {
                  "type": "string",
                  "enum": [
                    "2.4GHZ",
                    "5GHZ"
                  ]
                },
                "field": {
                  "type": "string",
                  "enum": [
                    "ssid",
                    "password"
                  ]
                }
              }
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "excludedAttributePrefixes": {
                  "minItems": 1
                }
              }
            },
            "then": {
              "properties": {
                "firmwareVersions": {
                  "minItems": 1
                }
              }
            }
          },
          {
            "if": {
              "required": [
                "wifiInputAliases"
              ],
              "properties": {
                "wifiInputAliases": {
                  "minItems": 1
                }
              }
            },
            "then": {
              "properties": {
                "firmwareVersions": {
                  "minItems": 1
                }
              }
            }
          }
        ]
      },
      "Profile": {
        "type": "object",
        "required": [
          "id",
          "name",
          "revision",
          "compatibility"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "revision": {
            "type": "integer",
            "minimum": 1
          },
          "compatibility": {
            "$ref": "#/components/schemas/Compatibility"
          }
        },
        "additionalProperties": true
      },
      "ProfileWrite": {
        "type": "object",
        "required": [
          "name",
          "manufacturer",
          "model",
          "dataModel",
          "mappings"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "manufacturer": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "model": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "productClass": {
            "type": [
              "string",
              "null"
            ]
          },
          "oui": {
            "type": [
              "string",
              "null"
            ]
          },
          "dataModel": {
            "enum": [
              "TR181",
              "TR098",
              "VENDOR"
            ]
          },
          "priority": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000
          },
          "validationState": {
            "enum": [
              "DRAFT",
              "VALIDATING",
              "HOMOLOGATED"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "mappings": {
            "type": "array",
            "minItems": 1,
            "maxItems": 2,
            "items": {
              "type": "object",
              "required": [
                "band",
                "ssidPath",
                "passwordPath"
              ],
              "properties": {
                "band": {
                  "enum": [
                    "2.4GHZ",
                    "5GHZ"
                  ]
                },
                "ssidPath": {
                  "type": "string"
                },
                "passwordPath": {
                  "type": "string"
                }
              }
            }
          },
          "firmwareIds": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "compatibility": {
            "$ref": "#/components/schemas/Compatibility"
          },
          "referenceDeviceId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "CPE de referencia do tenant autenticado. Confirma modelo, fabricante/OUI, hardware, arvore e versao instalada. Exige versao em compatibility.firmwareVersions. PUT omitido preserva e revalida referencia; null remove. Nao autoriza download nem homologa escrita automaticamente."
          }
        },
        "additionalProperties": true,
        "description": "Mantém campos existentes de mappings PPPoE/diagnóstico/telemetria/alertas. No PUT, compatibility omitido preserva a política. Objeto explícito substitui. Perfil ativo homologado exige hardware pelos vínculos de firmware ou referenceDeviceId validado; alterar elegibilidade de perfil vinculado exige firmware:approve e reenviar firmwareIds."
      }
    }
  }
}
