{
  "openapi": "3.0.3",
  "info": {
    "title": "DPass — Soste attive per area",
    "version": "1.0",
    "description": "Patch 61I. Report aggregato condiviso con amministrazione DPass. Nessuna targa o operazione individuale."
  },
  "servers": [
    {
      "url": "https://dpass.example.invalid",
      "description": "Sostituire con la stessa base URL usata dal controllo targa"
    }
  ],
  "paths": {
    "/api/v2/parking/reports/active-by-area": {
      "post": {
        "operationId": "activeParkingByArea",
        "summary": "Report corrente Soste attive per area",
        "security": [
          {
            "DPassToken": []
          },
          {
            "BearerAuth": []
          },
          {
            "LegacyApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReportRequest"
              },
              "example": {
                "municipality_code": "anacapri",
                "area_type": "street"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Report disponibile, anche senza aree o con tutti i contatori a zero.",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportResponse"
                }
              }
            }
          },
          "400": {
            "description": "INVALID_JSON",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Token mancante, errato, scaduto o revocato",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ambito, IP, tenant o servizio non autorizzati",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "SOURCE_NOT_FOUND oppure NO_ACTIVE_FACILITIES; marcatore presente",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "INVALID_CONTENT_TYPE",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "INVALID_REQUEST oppure MUNICIPALITY_REQUIRED",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMIT_EXCEEDED: budget condiviso con controllo targa",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              },
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Errore temporaneo, non report vuoto",
            "headers": {
              "X-DPass-Report": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "active_by_area"
                  ]
                }
              },
              "X-DPass-Report-Version": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "1.0"
                  ]
                }
              },
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "example": "no-store, private"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "DPassToken": {
        "type": "apiKey",
        "in": "header",
        "name": "X-DPass-Token"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },
      "LegacyApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key"
      }
    },
    "schemas": {
      "ReportRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "municipality_code": {
            "type": "string",
            "maxLength": 80,
            "nullable": true,
            "description": "Codice DPass; obbligatorio con più Comuni attivi autorizzati"
          },
          "area_type": {
            "type": "string",
            "enum": [
              "street",
              "facility"
            ],
            "nullable": true,
            "default": "street"
          },
          "source_id": {
            "type": "integer",
            "minimum": 1,
            "nullable": true
          }
        }
      },
      "Source": {
        "type": "object",
        "required": [
          "id",
          "code",
          "name",
          "category",
          "active",
          "is_system"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "is_system": {
            "type": "boolean"
          }
        }
      },
      "AreaRow": {
        "type": "object",
        "required": [
          "area",
          "capacity",
          "active_now",
          "active_after_30",
          "active_after_60",
          "ending_within_30",
          "ending_between_30_60",
          "available_now",
          "available_after_30",
          "available_after_60",
          "excess_now",
          "source_active_now",
          "source_active_after_30",
          "source_active_after_60",
          "occupancy_percent"
        ],
        "properties": {
          "area": {
            "type": "object",
            "required": [
              "id",
              "code",
              "name",
              "area_type"
            ],
            "properties": {
              "id": {
                "type": "integer"
              },
              "code": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "area_type": {
                "type": "string",
                "enum": [
                  "street",
                  "facility"
                ]
              }
            }
          },
          "capacity": {
            "type": "integer",
            "nullable": true
          },
          "active_now": {
            "type": "integer",
            "nullable": true
          },
          "active_after_30": {
            "type": "integer",
            "nullable": true
          },
          "active_after_60": {
            "type": "integer",
            "nullable": true
          },
          "ending_within_30": {
            "type": "integer",
            "nullable": true
          },
          "ending_between_30_60": {
            "type": "integer",
            "nullable": true
          },
          "available_now": {
            "type": "integer",
            "nullable": true
          },
          "available_after_30": {
            "type": "integer",
            "nullable": true
          },
          "available_after_60": {
            "type": "integer",
            "nullable": true
          },
          "excess_now": {
            "type": "integer",
            "nullable": true
          },
          "source_active_now": {
            "type": "integer",
            "nullable": true
          },
          "source_active_after_30": {
            "type": "integer",
            "nullable": true
          },
          "source_active_after_60": {
            "type": "integer",
            "nullable": true
          },
          "occupancy_percent": {
            "type": "number",
            "nullable": true
          }
        }
      },
      "Counts": {
        "type": "object",
        "properties": {
          "active_now": {
            "type": "integer",
            "nullable": true
          },
          "active_after_30": {
            "type": "integer",
            "nullable": true
          },
          "active_after_60": {
            "type": "integer",
            "nullable": true
          },
          "ending_within_30": {
            "type": "integer",
            "nullable": true
          },
          "ending_within_60": {
            "type": "integer",
            "nullable": true
          },
          "ending_between_30_60": {
            "type": "integer",
            "nullable": true
          },
          "areas_count": {
            "type": "integer",
            "nullable": true
          },
          "configured_count": {
            "type": "integer",
            "nullable": true
          },
          "unconfigured_count": {
            "type": "integer",
            "nullable": true
          },
          "configured_areas_count": {
            "type": "integer",
            "nullable": true
          },
          "spaces_count": {
            "type": "integer",
            "nullable": true
          },
          "available_now": {
            "type": "integer",
            "nullable": true
          },
          "available_after_30": {
            "type": "integer",
            "nullable": true
          },
          "available_after_60": {
            "type": "integer",
            "nullable": true
          },
          "excess_now": {
            "type": "integer",
            "nullable": true
          },
          "occupancy_percent": {
            "type": "number",
            "nullable": true
          }
        }
      },
      "ReportResponse": {
        "type": "object",
        "required": [
          "success",
          "ok",
          "request_id",
          "api_version",
          "report",
          "report_version",
          "supported",
          "timezone",
          "refresh_after_seconds",
          "municipality",
          "filters",
          "sources",
          "selected_source",
          "areas_count",
          "rows",
          "totals",
          "source_totals",
          "capacity_totals",
          "source_freshness",
          "generated_at",
          "checked_at",
          "after_30",
          "after_60"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "ok": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "api_version": {
            "type": "string",
            "enum": [
              "2.0"
            ]
          },
          "report": {
            "type": "string",
            "enum": [
              "active_by_area"
            ]
          },
          "report_version": {
            "type": "string",
            "enum": [
              "1.0"
            ]
          },
          "supported": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "timezone": {
            "type": "string"
          },
          "refresh_after_seconds": {
            "type": "integer",
            "example": 60
          },
          "municipality": {
            "type": "object",
            "required": [
              "code",
              "name"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "filters": {
            "type": "object",
            "required": [
              "area_type",
              "source_id"
            ],
            "properties": {
              "area_type": {
                "type": "string",
                "enum": [
                  "street",
                  "facility"
                ]
              },
              "source_id": {
                "type": "integer",
                "nullable": true
              }
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          },
          "selected_source": {
            "type": "object",
            "required": [
              "id",
              "code",
              "name",
              "category",
              "active",
              "is_system"
            ],
            "properties": {
              "id": {
                "type": "integer"
              },
              "code": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "category": {
                "type": "string"
              },
              "active": {
                "type": "boolean"
              },
              "is_system": {
                "type": "boolean"
              }
            },
            "nullable": true
          },
          "areas_count": {
            "type": "integer"
          },
          "rows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AreaRow"
            }
          },
          "totals": {
            "$ref": "#/components/schemas/Counts"
          },
          "source_totals": {
            "type": "object",
            "nullable": true,
            "properties": {
              "active_now": {
                "type": "integer",
                "nullable": true
              },
              "active_after_30": {
                "type": "integer",
                "nullable": true
              },
              "active_after_60": {
                "type": "integer",
                "nullable": true
              },
              "ending_within_30": {
                "type": "integer",
                "nullable": true
              },
              "ending_within_60": {
                "type": "integer",
                "nullable": true
              },
              "ending_between_30_60": {
                "type": "integer",
                "nullable": true
              },
              "areas_count": {
                "type": "integer",
                "nullable": true
              },
              "configured_count": {
                "type": "integer",
                "nullable": true
              },
              "unconfigured_count": {
                "type": "integer",
                "nullable": true
              },
              "configured_areas_count": {
                "type": "integer",
                "nullable": true
              },
              "spaces_count": {
                "type": "integer",
                "nullable": true
              },
              "available_now": {
                "type": "integer",
                "nullable": true
              },
              "available_after_30": {
                "type": "integer",
                "nullable": true
              },
              "available_after_60": {
                "type": "integer",
                "nullable": true
              },
              "excess_now": {
                "type": "integer",
                "nullable": true
              },
              "occupancy_percent": {
                "type": "number",
                "nullable": true
              }
            }
          },
          "capacity_totals": {
            "$ref": "#/components/schemas/Counts"
          },
          "source_freshness": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "source_id",
                "status",
                "last_successful_import_at"
              ],
              "properties": {
                "source_id": {
                  "type": "integer"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "native",
                    "fresh",
                    "stale",
                    "never",
                    "error"
                  ]
                },
                "last_successful_import_at": {
                  "type": "string",
                  "format": "date-time",
                  "nullable": true
                }
              }
            }
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          },
          "after_30": {
            "type": "string",
            "format": "date-time"
          },
          "after_60": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "success",
          "ok",
          "request_id",
          "error"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "ok": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "request_id": {
            "type": "string"
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object"
              }
            }
          }
        }
      }
    }
  }
}
