{
  "openapi": "3.1.0",
  "info": {
    "title": "NooriACS — visibilidade dos totais de clientes",
    "version": "1.1.0",
    "description": "Extensão de segurança do contrato v1: totais comerciais restritos aos papéis administrativos existentes. Listagem e detalhes individuais mantidos. Não altera Compatibility API."
  },
  "security": [
    {
      "sessionCookie": []
    }
  ],
  "paths": {
    "/api/v1/customers": {
      "get": {
        "summary": "Consulta no escopo da empresa com minimização de totais comerciais",
        "x-required-permission": "customers:read",
        "responses": {
          "200": {
            "description": "Totais só para proprietário/administrador com customers:read; campos restritos são null.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerList"
                }
              }
            }
          },
          "401": {
            "description": "Sessão ausente"
          },
          "403": {
            "description": "Permissão insuficiente"
          }
        }
      }
    },
    "/api/v1/customer-cpe-inventory": {
      "get": {
        "summary": "Consulta no escopo da empresa com minimização de totais comerciais",
        "x-required-permission": "customers:read",
        "responses": {
          "200": {
            "description": "Totais só para proprietário/administrador com customers:read; campos restritos são null.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerInventory"
                }
              }
            }
          },
          "401": {
            "description": "Sessão ausente"
          },
          "403": {
            "description": "Permissão insuficiente"
          }
        }
      }
    },
    "/api/v1/integrations/hubsoft": {
      "get": {
        "summary": "Consulta no escopo da empresa com minimização de totais comerciais",
        "x-required-permission": "integrations:read",
        "responses": {
          "200": {
            "description": "Totais só para proprietário/administrador com customers:read; campos restritos são null.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IntegrationStatus"
                }
              }
            }
          },
          "401": {
            "description": "Sessão ausente"
          },
          "403": {
            "description": "Permissão insuficiente"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "nooriacs_session"
      }
    },
    "schemas": {
      "CustomerList": {
        "type": "object",
        "required": [
          "items",
          "totalsVisible",
          "summary",
          "pagination"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              }
            }
          },
          "totalsVisible": {
            "type": "boolean"
          },
          "summary": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            }
          },
          "pagination": {
            "type": "object",
            "required": [
              "page",
              "limit",
              "total",
              "totalPages",
              "hasNext"
            ],
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1
              },
              "limit": {
                "type": "integer",
                "minimum": 5,
                "maximum": 50
              },
              "total": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "totalPages": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "hasNext": {
                "type": "boolean"
              }
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "totalsVisible": {
                  "const": false
                }
              }
            },
            "then": {
              "properties": {
                "summary": {
                  "type": "null"
                },
                "pagination": {
                  "properties": {
                    "total": {
                      "type": "null"
                    },
                    "totalPages": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "CustomerInventory": {
        "type": "object",
        "required": [
          "items",
          "totalsVisible",
          "summary"
        ],
        "properties": {
          "items": {
            "type": "array"
          },
          "totalsVisible": {
            "type": "boolean"
          },
          "summary": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "totalsVisible": {
                  "const": false
                }
              }
            },
            "then": {
              "properties": {
                "summary": {
                  "type": "null"
                }
              }
            }
          }
        ]
      },
      "IntegrationStatus": {
        "type": "object",
        "required": [
          "lastRun"
        ],
        "properties": {
          "lastRun": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "customers_seen": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "services_seen": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "auto_links_created": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "status": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
