{
  "openapi": "3.1.0",
  "info": {
    "title": "NooriACS — Configuração ACS",
    "version": "1.1.0",
    "description": "Configuração por empresa, revisão otimista e senhas somente entrada. Aplicação automática opt-in usa o perfil homologado e a capacidade atual para configurar somente ConnectionRequestUsername/Password nas ONTs sem credencial utilizável ou com rejeição autenticada. Credenciais válidas são preservadas. Escrita aguarda Inform autenticado e sucesso exige Connection Request autenticado. Timeout, rota e ACL não autorizam rotação. Status 1 aguarda BOOT do operador. Caminho e porta são referências, não são gravados na ONT. Desativar bloqueia novos envios; candidatos enviados continuam em confirmação por até 24 horas."
  },
  "security": [
    {
      "tenantSession": []
    }
  ],
  "paths": {
    "/api/v1/acs-settings": {
      "get": {
        "operationId": "getAcsSettings",
        "summary": "Consultar configuração da empresa",
        "x-permission": "acs:read",
        "responses": {
          "200": {
            "description": "Configuração sem senhas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AcsSettings"
                }
              }
            }
          },
          "401": {
            "description": "Erro público sem segredo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "message"
                  ],
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Erro público sem segredo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "message"
                  ],
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "saveAcsSettings",
        "summary": "Salvar configuração ACS e autenticação reversa",
        "x-permission": "acs:manage",
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Origem do painel configurada no servidor."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AcsSettingsInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Configuração sem senhas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AcsSettings"
                }
              }
            }
          },
          "401": {
            "description": "Erro público sem segredo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "message"
                  ],
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Erro público sem segredo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "message"
                  ],
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Erro público sem segredo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "message"
                  ],
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "Erro público sem segredo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "message"
                  ],
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Erro público sem segredo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "message"
                  ],
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Erro público sem segredo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "message"
                  ],
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "x-permissions-when-enabled": [
          "acs:manage",
          "tasks:execute"
        ]
      }
    },
    "/api/v1/acs-settings/provisioning": {
      "get": {
        "operationId": "getConnectionProvisioningStatus",
        "summary": "Acompanhar autenticação reversa por ONT",
        "x-permissions": [
          "acs:read",
          "devices:read"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100000,
              "default": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Estado por ONT sem segredo; READY pode indicar endpoint sem desafio, explicitado em message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionProvisioningStatus"
                }
              }
            }
          },
          "401": {
            "description": "Sessão ausente"
          },
          "403": {
            "description": "Permissão insuficiente"
          },
          "422": {
            "description": "Página inválida"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "tenantSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "nooriacs_session"
      }
    },
    "schemas": {
      "AcsSettings": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "revision",
          "acsUrl",
          "acsUsername",
          "acsPasswordPresent",
          "connectionRequestPath",
          "connectionRequestPort",
          "connectionRequestUsername",
          "connectionRequestPasswordPresent",
          "fallbackEnabled",
          "credentialReadable",
          "updatedAt",
          "endpoints",
          "fallbackModes",
          "autoProvisionEnabled",
          "autoProvisionModes"
        ],
        "properties": {
          "revision": {
            "type": "integer",
            "minimum": 0
          },
          "acsUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Endpoint da origem configurada e alias ativo da empresa; selecionar somente valores de endpoints."
          },
          "acsUsername": {
            "type": "string",
            "minLength": 0,
            "maxLength": 128
          },
          "acsPasswordPresent": {
            "type": "boolean"
          },
          "connectionRequestPath": {
            "type": "string",
            "maxLength": 256,
            "pattern": "^/[A-Za-z0-9._~/-]*$",
            "description": "Referência para configurar a ONT; segmentos . e .. e barras duplas são recusados. Não substitui URL anunciada."
          },
          "connectionRequestPort": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
          },
          "connectionRequestUsername": {
            "type": "string",
            "maxLength": 128
          },
          "connectionRequestPasswordPresent": {
            "type": "boolean"
          },
          "fallbackEnabled": {
            "type": "boolean"
          },
          "credentialReadable": {
            "type": "boolean"
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "endpoints": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "value",
                "label"
              ],
              "properties": {
                "value": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                }
              }
            }
          },
          "fallbackModes": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "value",
                "label"
              ],
              "properties": {
                "value": {
                  "type": "boolean"
                },
                "label": {
                  "type": "string"
                }
              }
            }
          },
          "autoProvisionEnabled": {
            "type": "boolean"
          },
          "autoProvisionModes": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "value",
                "label"
              ],
              "properties": {
                "value": {
                  "type": "boolean"
                },
                "label": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "AcsSettingsInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "revision",
          "acsUrl",
          "acsUsername",
          "connectionRequestPath",
          "connectionRequestPort",
          "connectionRequestUsername",
          "fallbackEnabled"
        ],
        "properties": {
          "revision": {
            "type": "integer",
            "minimum": 0
          },
          "acsUrl": {
            "type": "string",
            "format": "uri",
            "description": "Endpoint da origem configurada e alias ativo da empresa; selecionar somente valores de endpoints."
          },
          "acsUsername": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "connectionRequestPath": {
            "type": "string",
            "maxLength": 256,
            "pattern": "^/[A-Za-z0-9._~/-]*$",
            "description": "Referência para configurar a ONT; segmentos . e .. e barras duplas são recusados. Não substitui URL anunciada."
          },
          "connectionRequestPort": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
          },
          "connectionRequestUsername": {
            "type": "string",
            "maxLength": 128
          },
          "fallbackEnabled": {
            "type": "boolean"
          },
          "acsPassword": {
            "type": "string",
            "format": "password",
            "writeOnly": true,
            "minLength": 1,
            "maxLength": 256,
            "description": "Omitir mantém senha cadastrada. Vazio, marcadores mascarados e controles são recusados. Troca de usuário exige senha correspondente."
          },
          "connectionRequestPassword": {
            "type": "string",
            "format": "password",
            "writeOnly": true,
            "minLength": 1,
            "maxLength": 256,
            "description": "Omitir mantém senha cadastrada. Vazio, marcadores mascarados e controles são recusados. Troca de usuário exige senha correspondente."
          },
          "autoProvisionEnabled": {
            "type": "boolean",
            "description": "Omitido preserva a política existente. Ativação exige acs:manage e tasks:execute; usa par reverso padrão cifrado da empresa."
          }
        }
      },
      "ConnectionProvisioningStatus": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "items",
          "counts",
          "page",
          "limit",
          "total"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "deviceId",
                "serial",
                "firmware",
                "state",
                "label",
                "message",
                "taskId",
                "checkedAt",
                "lastInformAt"
              ],
              "properties": {
                "deviceId": {
                  "type": "string",
                  "format": "uuid"
                },
                "serial": {
                  "type": "string"
                },
                "firmware": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "PENDING",
                    "QUEUED",
                    "VERIFYING",
                    "READY",
                    "FAILED",
                    "UNSUPPORTED"
                  ]
                },
                "label": {
                  "type": "string"
                },
                "message": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "taskId": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "checkedAt": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "lastInformAt": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          },
          "counts": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "state",
                "count"
              ],
              "properties": {
                "state": {
                  "type": "string",
                  "enum": [
                    "PENDING",
                    "QUEUED",
                    "VERIFYING",
                    "READY",
                    "FAILED",
                    "UNSUPPORTED"
                  ]
                },
                "count": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            }
          },
          "page": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000
          },
          "limit": {
            "const": 25
          },
          "total": {
            "type": "integer",
            "minimum": 0
          }
        }
      }
    }
  }
}
