{
  "openapi": "3.1.0",
  "info": {
    "title": "API di PackHub",
    "version": "1.0.0",
    "description": "Le API di PackHub per collegare un negozio o un programma: preventivi, spedizioni, etichette, annullamenti e tracking, con i contratti del tuo account e il credito del tuo wallet.\n\n- **Chiave:** `Authorization: Bearer ph_live_…` (spedizioni vere) o `ph_test_…` (spedizioni di prova: nessun corriere, nessun addebito). Le crei nel tuo profilo su PackHub.\n- **Limite:** 120 richieste al minuto per chiave; oltre, 429 con `Retry-After`.\n- **Importi** in centesimi di euro, **pesi** in kg, **misure** in cm, **date** `AAAA-MM-GG` in ora italiana, istanti in ISO 8601.\n- **Doppioni:** la creazione vuole l’header `Idempotency-Key`. Ripetere la stessa richiesta con la stessa chiave dà la stessa risposta, senza una seconda spedizione né un secondo addebito.\n- **Errori:** `{ \"error\": { \"code\", \"message\", \"details\" } }`.\n\n| Codice | Stato | Significato |\n| --- | --- | --- |\n| `VALIDATION_ERROR` | 400 | Dati mancanti o non validi: `details.issues` dice quali campi. |\n| `UNAUTHENTICATED` | 401 | Chiave mancante, non valida o revocata. |\n| `FORBIDDEN` | 403 | Operazione non permessa con questa chiave. |\n| `NOT_FOUND` | 404 | Spedizione o contratto che non c’è, o non di questa chiave. |\n| `NO_PRICE_LIST` | 422 | Il contratto non ha un prezzo per questa spedizione. |\n| `NO_BAND_FOR_WEIGHT` | 422 | Il peso è fuori dal listino. |\n| `COD_NOT_AVAILABLE` | 422 | Il contrassegno non si può chiedere su questo contratto. |\n| `COD_OVER_MAX` | 422 | Il contrassegno supera il massimo (`details.maxCodCents`). |\n| `INSURANCE_NOT_AVAILABLE` | 422 | L’assicurazione non si può chiedere su questo contratto. |\n| `INSURANCE_OVER_MAX` | 422 | Il valore assicurato supera il massimo (`details.maxInsuranceCents`). |\n| `SERVICE_NOT_AVAILABLE` | 422 | Un servizio accessorio non si può chiedere su questo contratto. |\n| `DELIVERY_NOT_AVAILABLE` | 422 | Il contratto non consegna in questo modo (`details.reason`). |\n| `DESTINATION_NOT_AVAILABLE` | 422 | Il contratto non spedisce verso questa destinazione. |\n| `PICKUP_NOT_AVAILABLE` | 422 | Il ritiro non si può chiedere su questo contratto. |\n| `PICKUP_DATE_NOT_AVAILABLE` | 422 | Data del ritiro non valida: `details.problem` e `details.firstDate`, la prima data utile. |\n| `INSUFFICIENT_FUNDS` | 402 | Credito insufficiente: `details.availableCents`, `requiredCents` e `deficitCents`. Ricarica il wallet. |\n| `CARRIER_REJECTED` | 422 | Il corriere ha rifiutato la spedizione: nessun addebito. `details.shipmentId` e `details.reason`. |\n| `CARRIER_UNAVAILABLE` | 503 | Il corriere non risponde. Con `details.outcomeUnknown: true` la spedizione è in verifica: non ripetere con un’altra chiave di idempotenza. |\n| `CANCEL_NOT_ALLOWED` | 409 | La spedizione non si può (più) annullare (`details.reason`). |\n| `IDEMPOTENCY_CONFLICT` | 409 | La stessa Idempotency-Key è già stata usata con dati diversi. |\n| `RATE_LIMITED` | 429 | Troppe richieste: riprova dopo i secondi di `Retry-After`. |\n| `INTERNAL` | 500 | Errore interno. Con `details.outcomeUnknown: true` la spedizione è in verifica. |"
  },
  "servers": [
    {
      "url": "https://api.packhub.it/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Account",
      "description": "La chiave, il credito e i contratti."
    },
    {
      "name": "Preventivi",
      "description": "Il prezzo per ogni contratto."
    },
    {
      "name": "Spedizioni",
      "description": "Creazione, elenco, dettaglio, etichetta e annullamento."
    },
    {
      "name": "Tracking",
      "description": "Gli eventi del corriere."
    }
  ],
  "paths": {
    "/account": {
      "get": {
        "operationId": "getAccount",
        "tags": [
          "Account"
        ],
        "summary": "Prova la chiave",
        "description": "Nome dell’account, credito disponibile, tipo della chiave e numero di contratti. Gratis.",
        "responses": {
          "200": {
            "description": "L’account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/contracts": {
      "get": {
        "operationId": "listContracts",
        "tags": [
          "Account"
        ],
        "summary": "I contratti della chiave",
        "description": "I contratti con cui la chiave spedisce: corriere, nome del servizio, servizi accessori, colli massimi, misure obbligatorie, ritiro e come si annulla. L’`id` va in `contractId`.",
        "responses": {
          "200": {
            "description": "I contratti.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractsResponse"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/rates": {
      "post": {
        "operationId": "getRates",
        "tags": [
          "Preventivi"
        ],
        "summary": "Calcola il prezzo",
        "description": "Un prezzo per ogni contratto della chiave, o solo per `contractId`. Un contratto che non può fare questa spedizione torna con `available: false` e il motivo, senza far fallire gli altri. Non crea niente e non addebita niente.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RatesRequest"
              },
              "example": {
                "destination": {
                  "zipCode": "20121",
                  "city": "Milano"
                },
                "parcels": [
                  {
                    "weightKg": 2.5,
                    "lengthCm": 30,
                    "widthCm": 20,
                    "heightCm": 15
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "I prezzi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RatesResponse"
                }
              }
            }
          },
          "400": {
            "description": "Richiesta non valida (`VALIDATION_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Non trovato (`NOT_FOUND`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/shipments": {
      "post": {
        "operationId": "createShipment",
        "tags": [
          "Spedizioni"
        ],
        "summary": "Crea una spedizione",
        "description": "Crea la spedizione presso il corriere del contratto e addebita il prezzo sul tuo wallet. Con una chiave di prova la spedizione è finta: nessun corriere, nessun addebito, un’etichetta di prova e un tracking che avanza da solo. Il ritiro al domicilio si chiede solo qui, con `pickup.date`.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Un valore tuo, unico per ogni spedizione (per esempio il numero d’ordine). Ripetere con lo stesso valore e gli stessi dati dà la stessa spedizione; con dati diversi, 409.",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 100
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateShipmentRequest"
              },
              "example": {
                "contractId": "00000000-0000-4000-8000-000000000000",
                "recipient": {
                  "name": "Mario Rossi",
                  "street": "Via Roma",
                  "houseNumber": "10",
                  "city": "Milano",
                  "zipCode": "20121",
                  "province": "MI",
                  "phone": "3331234567",
                  "email": "mario.rossi@example.com"
                },
                "parcels": [
                  {
                    "weightKg": 2.5,
                    "lengthCm": 30,
                    "widthCm": 20,
                    "heightCm": 15
                  }
                ],
                "reference": "ORDINE-1001"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La stessa spedizione di una richiesta ripetuta.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Shipment"
                }
              }
            }
          },
          "201": {
            "description": "Spedizione creata.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Shipment"
                }
              }
            }
          },
          "400": {
            "description": "Richiesta non valida (`VALIDATION_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Credito insufficiente (`INSUFFICIENT_FUNDS`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Non trovato (`NOT_FOUND`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflitto (`IDEMPOTENCY_CONFLICT`, `CANCEL_NOT_ALLOWED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Spedizione non possibile su questo contratto: il codice dice perché.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Corriere non raggiungibile (`CARRIER_UNAVAILABLE`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listShipments",
        "tags": [
          "Spedizioni"
        ],
        "summary": "Elenco delle spedizioni",
        "description": "Dalla più recente, a pagine: per la pagina dopo passa `cursor` con il `nextCursor` ricevuto. Una chiave di prova vede solo le spedizioni di prova.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "default": 20,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Il `nextCursor` della pagina prima.",
            "schema": {
              "description": "Il `nextCursor` della pagina prima.",
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "`creating`: in verifica (il corriere non ha dato un esito: non ripetere). `created`: creata. `failed`: rifiutata dal corriere, nessun addebito. `cancelled`: annullata e rimborsata.",
            "schema": {
              "type": "string",
              "enum": [
                "creating",
                "created",
                "failed",
                "cancelled"
              ],
              "description": "`creating`: in verifica (il corriere non ha dato un esito: non ripetere). `created`: creata. `failed`: rifiutata dal corriere, nessun addebito. `cancelled`: annullata e rimborsata."
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "Create da questo giorno (ora italiana).",
            "schema": {
              "description": "Create da questo giorno (ora italiana).",
              "type": "string",
              "format": "date",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Create fino a questo giorno compreso (ora italiana).",
            "schema": {
              "description": "Create fino a questo giorno compreso (ora italiana).",
              "type": "string",
              "format": "date",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
            }
          },
          {
            "name": "trackingNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 60
            }
          },
          {
            "name": "reference",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Una pagina di spedizioni.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShipmentsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Richiesta non valida (`VALIDATION_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/shipments/{id}": {
      "get": {
        "operationId": "getShipment",
        "tags": [
          "Spedizioni"
        ],
        "summary": "Dettaglio di una spedizione",
        "description": "Stato, tracking, prezzo pagato, ritiro ed eventi del corriere.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "L’`id` della spedizione.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La spedizione.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Shipment"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Non trovato (`NOT_FOUND`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/shipments/{id}/label": {
      "get": {
        "operationId": "getLabel",
        "tags": [
          "Spedizioni"
        ],
        "summary": "Scarica l’etichetta",
        "description": "Il PDF dell’etichetta, da salvare così com’è. Dopo l’annullamento non si scarica più. Se il corriere non l’ha ancora pronta risponde 503: riprova tra poco.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "L’`id` della spedizione.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "L’etichetta.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Non trovato (`NOT_FOUND`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Corriere non raggiungibile (`CARRIER_UNAVAILABLE`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/shipments/{id}/cancel": {
      "post": {
        "operationId": "cancelShipment",
        "tags": [
          "Spedizioni"
        ],
        "summary": "Annulla una spedizione",
        "description": "Annulla e rimborsa sul wallet. Con `cancellation: carrier` l’annullamento arriva al corriere e il rimborso parte solo se il corriere conferma. Con `packhub` il corriere non ha l’annullamento automatico: la spedizione si annulla in PackHub, e se il pacco viene consegnato lo stesso si riaddebita. Dopo la presa in carico non si annulla più. Ripetere su una spedizione annullata dà la stessa risposta.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "L’`id` della spedizione.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La spedizione annullata.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Shipment"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Non trovato (`NOT_FOUND`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflitto (`IDEMPOTENCY_CONFLICT`, `CANCEL_NOT_ALLOWED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Corriere non raggiungibile (`CARRIER_UNAVAILABLE`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tracking/{number}": {
      "get": {
        "operationId": "getTracking",
        "tags": [
          "Tracking"
        ],
        "summary": "Tracking da numero",
        "description": "Gli eventi del corriere di una tua spedizione, dal numero di tracking. Accetta anche il riferimento provvisorio `PK…` che alcune spedizioni hanno prima del numero del corriere.",
        "parameters": [
          {
            "name": "number",
            "in": "path",
            "required": true,
            "description": "Il numero di tracking.",
            "schema": {
              "type": "string",
              "maxLength": 60
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Il tracking.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Tracking"
                }
              }
            }
          },
          "401": {
            "description": "Chiave mancante, non valida o revocata (`UNAUTHENTICATED`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Non trovato (`NOT_FOUND`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Troppe richieste (`RATE_LIMITED`): aspetta i secondi di `Retry-After`.",
            "headers": {
              "Retry-After": {
                "description": "Secondi da aspettare.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "La chiave del tuo profilo: `ph_live_…` o `ph_test_…`."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "VALIDATION_ERROR",
                  "UNAUTHENTICATED",
                  "FORBIDDEN",
                  "NOT_FOUND",
                  "NO_PRICE_LIST",
                  "NO_BAND_FOR_WEIGHT",
                  "COD_NOT_AVAILABLE",
                  "COD_OVER_MAX",
                  "INSURANCE_NOT_AVAILABLE",
                  "INSURANCE_OVER_MAX",
                  "SERVICE_NOT_AVAILABLE",
                  "DELIVERY_NOT_AVAILABLE",
                  "DESTINATION_NOT_AVAILABLE",
                  "PICKUP_NOT_AVAILABLE",
                  "PICKUP_DATE_NOT_AVAILABLE",
                  "INSUFFICIENT_FUNDS",
                  "CARRIER_REJECTED",
                  "CARRIER_UNAVAILABLE",
                  "CANCEL_NOT_ALLOWED",
                  "IDEMPOTENCY_CONFLICT",
                  "RATE_LIMITED",
                  "INTERNAL"
                ]
              },
              "message": {
                "type": "string",
                "description": "In italiano, mostrabile a chi usa il tuo programma."
              },
              "details": {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {}
              }
            },
            "required": [
              "code",
              "message"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      },
      "Account": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Nome dell’account: la ragione sociale, o l’email se manca."
          },
          "email": {
            "type": "string"
          },
          "currency": {
            "type": "string",
            "const": "EUR"
          },
          "wallet": {
            "type": "object",
            "properties": {
              "balanceCents": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991,
                "description": "Saldo del wallet."
              },
              "creditLimitCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Fido concesso: si può spendere fino a saldo più fido."
              },
              "availableCents": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991,
                "description": "Disponibile per nuove spedizioni: saldo più fido."
              }
            },
            "required": [
              "balanceCents",
              "creditLimitCents",
              "availableCents"
            ],
            "additionalProperties": false,
            "description": "Il credito del cliente. Finito il disponibile, la creazione risponde 402 `INSUFFICIENT_FUNDS`."
          },
          "contractsCount": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991,
            "description": "Contratti che questa chiave può usare."
          },
          "key": {
            "type": "object",
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "live",
                  "test"
                ],
                "description": "`live` crea spedizioni vere; `test` solo spedizioni di prova."
              },
              "label": {
                "type": "string"
              },
              "prefix": {
                "type": "string"
              },
              "allContracts": {
                "type": "boolean",
                "description": "false = la chiave è limitata ad alcuni contratti."
              }
            },
            "required": [
              "mode",
              "label",
              "prefix",
              "allContracts"
            ],
            "additionalProperties": false
          },
          "rateLimitPerMinute": {
            "type": "integer",
            "minimum": 1,
            "maximum": 9007199254740991,
            "description": "Richieste al minuto per chiave."
          }
        },
        "required": [
          "name",
          "email",
          "currency",
          "wallet",
          "contractsCount",
          "key",
          "rateLimitPerMinute"
        ],
        "additionalProperties": false
      },
      "ContractsResponse": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid",
                  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
                  "description": "Da usare come `contractId` nel preventivo e nella creazione."
                },
                "carrier": {
                  "type": "string",
                  "description": "Corriere che consegna, per esempio `BRT`, `GLS`, `POSTE`, `SDA`."
                },
                "name": {
                  "type": "string",
                  "description": "Nome del servizio."
                },
                "services": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "code": {
                        "type": "string",
                        "pattern": "^[A-Z][A-Z0-9_]{1,39}$"
                      },
                      "label": {
                        "type": "string"
                      },
                      "description": {
                        "type": "string"
                      },
                      "params": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "name": {
                              "type": "string"
                            },
                            "label": {
                              "type": "string"
                            },
                            "type": {
                              "type": "string",
                              "enum": [
                                "text",
                                "date",
                                "select",
                                "weekdays"
                              ]
                            },
                            "required": {
                              "type": "boolean"
                            },
                            "options": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "value": {
                                    "type": "string"
                                  },
                                  "label": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "value",
                                  "label"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "maxLength": {
                              "type": "integer",
                              "minimum": 1,
                              "maximum": 9007199254740991
                            },
                            "help": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "name",
                            "label",
                            "type",
                            "required"
                          ],
                          "additionalProperties": false
                        }
                      }
                    },
                    "required": [
                      "code",
                      "label",
                      "description"
                    ],
                    "additionalProperties": false
                  },
                  "description": "Servizi accessori che si possono chiedere, con il codice da mandare in `services`."
                },
                "deliveryModes": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "ADDRESS",
                      "PARCEL_SHOP",
                      "LOCKER",
                      "POST_OFFICE"
                    ]
                  },
                  "description": "Dove consegna. Nel primo pezzo dell’API si spedisce solo all’indirizzo (`ADDRESS`)."
                },
                "maxParcels": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991,
                  "description": "Colli al massimo per spedizione."
                },
                "requiresDimensions": {
                  "type": "boolean",
                  "description": "Il corriere vuole lunghezza, larghezza e altezza di ogni collo."
                },
                "scope": {
                  "type": "string",
                  "enum": [
                    "domestic",
                    "international"
                  ],
                  "description": "Italia o estero. Nel primo pezzo dell’API solo Italia."
                },
                "pickup": {
                  "type": "boolean",
                  "description": "Si può chiedere il ritiro al domicilio del mittente alla creazione."
                },
                "cancellation": {
                  "type": "string",
                  "enum": [
                    "carrier",
                    "packhub",
                    "none"
                  ],
                  "description": "`carrier`: l’annullamento arriva al corriere. `packhub`: il corriere non ha l’annullamento automatico, la spedizione si annulla solo in PackHub con il rimborso (se il pacco viene consegnato lo stesso, si riaddebita). `none`: non si annulla."
                },
                "senderFromContract": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": [
                        "company",
                        "custom"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ],
                  "description": "Il mittente che arriva al corriere viene dal contratto (indirizzo dell’azienda o uno scritto nel contratto). null = quello della spedizione."
                },
                "lockOrigin": {
                  "type": "boolean",
                  "description": "Il mittente deve partire dall’indirizzo del profilo."
                }
              },
              "required": [
                "id",
                "carrier",
                "name",
                "services",
                "deliveryModes",
                "maxParcels",
                "requiresDimensions",
                "scope",
                "pickup",
                "cancellation",
                "senderFromContract",
                "lockOrigin"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "items"
        ],
        "additionalProperties": false
      },
      "RatesRequest": {
        "type": "object",
        "properties": {
          "contractId": {
            "description": "Un solo contratto. Assente = tutti quelli della chiave.",
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "destination": {
            "type": "object",
            "properties": {
              "zipCode": {
                "type": "string",
                "pattern": "^\\d{5}$",
                "description": "CAP del destinatario."
              },
              "city": {
                "type": "string",
                "minLength": 1,
                "maxLength": 35,
                "description": "Comune del destinatario."
              }
            },
            "required": [
              "zipCode",
              "city"
            ],
            "additionalProperties": false
          },
          "parcels": {
            "minItems": 1,
            "maxItems": 10,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "weightKg": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999.99
                },
                "lengthCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                },
                "widthCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                },
                "heightCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                }
              },
              "required": [
                "weightKg"
              ],
              "description": "Un collo: peso in kg (obbligatorio), misure in cm (obbligatorie se il contratto ha `requiresDimensions`)."
            },
            "description": "Da 1 a 10 colli."
          },
          "codAmountCents": {
            "description": "Contrassegno da incassare, in centesimi.",
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "insuranceAmountCents": {
            "description": "Valore da assicurare, in centesimi.",
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "services": {
            "description": "Codici dei servizi accessori (`services` del contratto).",
            "maxItems": 10,
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[A-Z][A-Z0-9_]{1,39}$"
            }
          }
        },
        "required": [
          "destination",
          "parcels"
        ],
        "additionalProperties": false
      },
      "RatesResponse": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "available": {
                      "type": "boolean",
                      "const": true
                    },
                    "contractId": {
                      "type": "string",
                      "format": "uuid",
                      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                    },
                    "carrier": {
                      "type": "string",
                      "description": "Corriere che consegna, per esempio `BRT`, `GLS`, `POSTE`, `SDA`."
                    },
                    "name": {
                      "type": "string"
                    },
                    "price": {
                      "type": "object",
                      "properties": {
                        "currency": {
                          "type": "string",
                          "const": "EUR"
                        },
                        "totalCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Totale della spedizione, senza il ritiro."
                        },
                        "freightCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Nolo prima del carburante."
                        },
                        "fuelCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Supplemento carburante."
                        },
                        "codFeeCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Costo del contrassegno."
                        },
                        "insuranceFeeCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Costo dell’assicurazione."
                        },
                        "servicesCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Servizi accessori."
                        },
                        "tailLiftCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Sponda idraulica."
                        },
                        "oversizeCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Colli ingombranti."
                        },
                        "services": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "code": {
                                "type": "string"
                              },
                              "label": {
                                "type": "string"
                              },
                              "cents": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              }
                            },
                            "required": [
                              "code",
                              "label",
                              "cents"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "zone": {
                          "type": "string",
                          "enum": [
                            "NATIONAL",
                            "SICILY",
                            "SARDINIA",
                            "MINOR_ISLANDS",
                            "INTERNATIONAL"
                          ]
                        },
                        "zoneName": {
                          "type": "string"
                        },
                        "weight": {
                          "type": "object",
                          "properties": {
                            "actualKg": {
                              "type": "number",
                              "minimum": 0,
                              "description": "Peso reale."
                            },
                            "volumetricKg": {
                              "type": "number",
                              "minimum": 0,
                              "description": "Peso volumetrico (dalle misure)."
                            },
                            "chargeableKg": {
                              "type": "number",
                              "minimum": 0,
                              "description": "Peso su cui si calcola il prezzo."
                            }
                          },
                          "required": [
                            "actualKg",
                            "volumetricKg",
                            "chargeableKg"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "required": [
                        "currency",
                        "totalCents",
                        "freightCents",
                        "fuelCents",
                        "codFeeCents",
                        "insuranceFeeCents",
                        "servicesCents",
                        "tailLiftCents",
                        "oversizeCents",
                        "services",
                        "zone",
                        "zoneName",
                        "weight"
                      ],
                      "additionalProperties": false
                    },
                    "pickup": {
                      "oneOf": [
                        {
                          "type": "object",
                          "properties": {
                            "available": {
                              "type": "boolean",
                              "const": true
                            },
                            "amountCents": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991,
                              "description": "Prezzo del ritiro, in più rispetto a `price.totalCents`."
                            },
                            "firstDate": {
                              "type": "string",
                              "format": "date",
                              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$",
                              "description": "Prima data utile adesso (ora italiana)."
                            }
                          },
                          "required": [
                            "available",
                            "amountCents",
                            "firstDate"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "available": {
                              "type": "boolean",
                              "const": false
                            },
                            "reason": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "available",
                            "reason"
                          ],
                          "additionalProperties": false
                        }
                      ]
                    }
                  },
                  "required": [
                    "available",
                    "contractId",
                    "carrier",
                    "name",
                    "price",
                    "pickup"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "available": {
                      "type": "boolean",
                      "const": false
                    },
                    "contractId": {
                      "type": "string",
                      "format": "uuid",
                      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                    },
                    "carrier": {
                      "type": "string",
                      "description": "Corriere che consegna, per esempio `BRT`, `GLS`, `POSTE`, `SDA`."
                    },
                    "name": {
                      "type": "string"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        },
                        "details": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        }
                      },
                      "required": [
                        "code",
                        "message"
                      ],
                      "additionalProperties": false,
                      "description": "Perché questo contratto non spedisce questa spedizione."
                    }
                  },
                  "required": [
                    "available",
                    "contractId",
                    "carrier",
                    "name",
                    "error"
                  ],
                  "additionalProperties": false
                }
              ]
            }
          }
        },
        "required": [
          "items"
        ],
        "additionalProperties": false
      },
      "CreateShipmentRequest": {
        "type": "object",
        "properties": {
          "contractId": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
            "description": "Uno dei contratti di `GET /v1/contracts`."
          },
          "sender": {
            "description": "Mittente. Assente = il mittente del profilo.",
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 70
              },
              "contactName": {
                "type": "string",
                "maxLength": 35
              },
              "street": {
                "type": "string",
                "minLength": 1,
                "maxLength": 70
              },
              "houseNumber": {
                "type": "string",
                "maxLength": 10
              },
              "city": {
                "type": "string",
                "minLength": 1,
                "maxLength": 35
              },
              "zipCode": {
                "type": "string",
                "pattern": "^\\d{5}$"
              },
              "province": {
                "type": "string",
                "pattern": "^[A-Z]{2}$"
              },
              "country": {
                "default": "IT",
                "type": "string",
                "const": "IT"
              },
              "phone": {
                "type": "string",
                "pattern": "^\\+?\\d{6,15}$"
              },
              "email": {
                "type": "string",
                "format": "email",
                "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
              },
              "notes": {
                "type": "string",
                "maxLength": 140
              }
            },
            "required": [
              "name",
              "street",
              "city",
              "zipCode",
              "province",
              "phone"
            ]
          },
          "recipient": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 70
              },
              "contactName": {
                "type": "string",
                "maxLength": 35
              },
              "street": {
                "type": "string",
                "minLength": 1,
                "maxLength": 70
              },
              "houseNumber": {
                "type": "string",
                "maxLength": 10
              },
              "city": {
                "type": "string",
                "minLength": 1,
                "maxLength": 35
              },
              "zipCode": {
                "type": "string",
                "pattern": "^\\d{5}$"
              },
              "province": {
                "type": "string",
                "pattern": "^[A-Z]{2}$"
              },
              "country": {
                "default": "IT",
                "type": "string",
                "const": "IT"
              },
              "phone": {
                "type": "string",
                "pattern": "^\\+?\\d{6,15}$"
              },
              "email": {
                "type": "string",
                "format": "email",
                "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
              },
              "notes": {
                "type": "string",
                "maxLength": 140
              }
            },
            "required": [
              "name",
              "street",
              "city",
              "zipCode",
              "province",
              "phone"
            ],
            "description": "Destinatario, in Italia."
          },
          "parcels": {
            "minItems": 1,
            "maxItems": 10,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "weightKg": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999.99
                },
                "lengthCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                },
                "widthCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                },
                "heightCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                }
              },
              "required": [
                "weightKg"
              ],
              "description": "Un collo: peso in kg (obbligatorio), misure in cm (obbligatorie se il contratto ha `requiresDimensions`)."
            },
            "description": "Da 1 a 10 colli."
          },
          "cod": {
            "description": "Contrassegno: importo da incassare e come lo paga il destinatario.",
            "type": "object",
            "properties": {
              "amountCents": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "paymentType": {
                "type": "string",
                "enum": [
                  "CONTANTI",
                  "ASSEGNO_BANCARIO",
                  "ASSEGNO_CIRCOLARE"
                ]
              }
            },
            "required": [
              "amountCents",
              "paymentType"
            ],
            "additionalProperties": false
          },
          "insurance": {
            "description": "Assicurazione: valore assicurato.",
            "type": "object",
            "properties": {
              "amountCents": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              }
            },
            "required": [
              "amountCents"
            ],
            "additionalProperties": false
          },
          "notes": {
            "description": "Note per il corriere.",
            "type": "string",
            "maxLength": 140
          },
          "services": {
            "description": "Codici dei servizi accessori.",
            "maxItems": 10,
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[A-Z][A-Z0-9_]{1,39}$"
            }
          },
          "serviceParams": {
            "description": "Dati dei servizi scelti che ne hanno bisogno (`params` del servizio nel contratto).",
            "type": "object",
            "propertyNames": {
              "type": "string",
              "pattern": "^[A-Z][A-Z0-9_]{1,39}$"
            },
            "additionalProperties": {
              "type": "object",
              "propertyNames": {
                "type": "string",
                "pattern": "^[a-z][A-Za-z0-9]{0,39}$"
              },
              "additionalProperties": {
                "type": "string",
                "maxLength": 200
              }
            }
          },
          "reference": {
            "description": "Riferimento del mittente, per esempio l’ordine.",
            "type": "string",
            "minLength": 1,
            "maxLength": 30
          },
          "pickup": {
            "description": "Ritiro al domicilio del mittente: da lunedì a venerdì, non festivi; oggi solo prima delle 9:30; al massimo 10 giorni lavorativi. Si chiede solo qui, alla creazione.",
            "type": "object",
            "properties": {
              "date": {
                "type": "string",
                "format": "date",
                "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
              }
            },
            "required": [
              "date"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "contractId",
          "recipient",
          "parcels"
        ],
        "additionalProperties": false
      },
      "Shipment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
            "description": "Identificativo stabile della spedizione: il numero di tracking può cambiare."
          },
          "mode": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ],
            "description": "`test` per le spedizioni di prova."
          },
          "status": {
            "type": "string",
            "enum": [
              "creating",
              "created",
              "failed",
              "cancelled"
            ],
            "description": "`creating`: in verifica (il corriere non ha dato un esito: non ripetere). `created`: creata. `failed`: rifiutata dal corriere, nessun addebito. `cancelled`: annullata e rimborsata."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
          },
          "contractId": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "carrier": {
            "type": "string",
            "description": "Corriere che consegna, per esempio `BRT`, `GLS`, `POSTE`, `SDA`."
          },
          "contractName": {
            "type": "string"
          },
          "trackingNumber": {
            "description": "Numero di tracking. Su alcuni contratti nasce con un riferimento provvisorio di PackHub (`PK…`) e poi diventa quello del corriere: `GET /v1/tracking/{numero}` accetta tutti e due.",
            "type": [
              "string",
              "null"
            ]
          },
          "trackingStatus": {
            "type": [
              "string",
              "null"
            ]
          },
          "reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "recipient": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "contactName": {
                "type": "string"
              },
              "street": {
                "type": "string"
              },
              "houseNumber": {
                "type": "string"
              },
              "city": {
                "type": "string"
              },
              "zipCode": {
                "type": "string"
              },
              "province": {
                "type": "string"
              },
              "country": {
                "default": "IT",
                "description": "Codice ISO del paese, `IT` per l’Italia.",
                "type": "string"
              },
              "territory": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              },
              "email": {
                "type": "string"
              },
              "notes": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "street",
              "city",
              "zipCode",
              "country",
              "phone"
            ],
            "additionalProperties": false
          },
          "parcelsCount": {
            "type": "integer",
            "minimum": 1,
            "maximum": 9007199254740991
          },
          "priceCents": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991,
            "description": "Quanto è stato addebitato per il trasporto."
          },
          "sender": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "contactName": {
                "type": "string"
              },
              "street": {
                "type": "string"
              },
              "houseNumber": {
                "type": "string"
              },
              "city": {
                "type": "string"
              },
              "zipCode": {
                "type": "string"
              },
              "province": {
                "type": "string"
              },
              "country": {
                "default": "IT",
                "description": "Codice ISO del paese, `IT` per l’Italia.",
                "type": "string"
              },
              "territory": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              },
              "email": {
                "type": "string"
              },
              "notes": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "street",
              "city",
              "zipCode",
              "country",
              "phone"
            ],
            "additionalProperties": false
          },
          "parcels": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "weightKg": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999.99
                },
                "lengthCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                },
                "widthCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                },
                "heightCm": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 999
                }
              },
              "required": [
                "weightKg"
              ],
              "additionalProperties": false
            }
          },
          "codAmountCents": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "insuranceAmountCents": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "serviceParams": {
            "anyOf": [
              {
                "type": "object",
                "propertyNames": {
                  "type": "string",
                  "pattern": "^[A-Z][A-Z0-9_]{1,39}$"
                },
                "additionalProperties": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string",
                    "pattern": "^[a-z][A-Za-z0-9]{0,39}$"
                  },
                  "additionalProperties": {
                    "type": "string",
                    "maxLength": 200
                  }
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "price": {
            "type": "object",
            "properties": {
              "currency": {
                "type": "string",
                "const": "EUR"
              },
              "totalCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Totale della spedizione, senza il ritiro."
              },
              "freightCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Nolo prima del carburante."
              },
              "fuelCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Supplemento carburante."
              },
              "codFeeCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Costo del contrassegno."
              },
              "insuranceFeeCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Costo dell’assicurazione."
              },
              "servicesCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Servizi accessori."
              },
              "tailLiftCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Sponda idraulica."
              },
              "oversizeCents": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991,
                "description": "Colli ingombranti."
              },
              "services": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    },
                    "cents": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    }
                  },
                  "required": [
                    "code",
                    "label",
                    "cents"
                  ],
                  "additionalProperties": false
                }
              },
              "zone": {
                "type": "string",
                "enum": [
                  "NATIONAL",
                  "SICILY",
                  "SARDINIA",
                  "MINOR_ISLANDS",
                  "INTERNATIONAL"
                ]
              },
              "zoneName": {
                "type": "string"
              },
              "weight": {
                "type": "object",
                "properties": {
                  "actualKg": {
                    "type": "number",
                    "minimum": 0,
                    "description": "Peso reale."
                  },
                  "volumetricKg": {
                    "type": "number",
                    "minimum": 0,
                    "description": "Peso volumetrico (dalle misure)."
                  },
                  "chargeableKg": {
                    "type": "number",
                    "minimum": 0,
                    "description": "Peso su cui si calcola il prezzo."
                  }
                },
                "required": [
                  "actualKg",
                  "volumetricKg",
                  "chargeableKg"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "currency",
              "totalCents",
              "freightCents",
              "fuelCents",
              "codFeeCents",
              "insuranceFeeCents",
              "servicesCents",
              "tailLiftCents",
              "oversizeCents",
              "services",
              "zone",
              "zoneName",
              "weight"
            ],
            "additionalProperties": false
          },
          "pickup": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string",
                    "format": "date",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                  },
                  "state": {
                    "type": "string",
                    "enum": [
                      "booking",
                      "booked",
                      "failed",
                      "cancelled"
                    ],
                    "description": "`booking`: da prenotare. `booked`: prenotato. `failed`: non riuscito, lo gestiamo noi. `cancelled`: annullato."
                  },
                  "carrierRef": {
                    "description": "Numero del ritiro presso il corriere, quando c’è.",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "amountCents": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                },
                "required": [
                  "date",
                  "state",
                  "carrierRef",
                  "amountCents"
                ],
                "additionalProperties": false
              },
              {
                "type": "null"
              }
            ]
          },
          "labelAvailable": {
            "type": "boolean",
            "description": "L’etichetta si scarica con `GET /v1/shipments/{id}/label`."
          },
          "cancellation": {
            "type": "string",
            "enum": [
              "carrier",
              "packhub",
              "none"
            ],
            "description": "Come si annullerebbe adesso; `none` = non si può più annullare."
          },
          "failureReason": {
            "description": "Con `failed`: perché il corriere l’ha rifiutata.",
            "type": [
              "string",
              "null"
            ]
          },
          "events": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "at": {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                },
                "status": {
                  "description": "Stato normalizzato, per esempio `IN_TRANSITO`, `CONSEGNATO`.",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "description": {
                  "type": "string"
                },
                "location": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "at",
                "status",
                "description",
                "location"
              ],
              "additionalProperties": false
            },
            "description": "Eventi del corriere, dal più recente."
          }
        },
        "required": [
          "id",
          "mode",
          "status",
          "createdAt",
          "contractId",
          "carrier",
          "contractName",
          "trackingNumber",
          "trackingStatus",
          "reference",
          "recipient",
          "parcelsCount",
          "priceCents",
          "sender",
          "parcels",
          "codAmountCents",
          "insuranceAmountCents",
          "serviceParams",
          "price",
          "pickup",
          "labelAvailable",
          "cancellation",
          "failureReason",
          "events"
        ],
        "additionalProperties": false
      },
      "ShipmentsResponse": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid",
                  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
                  "description": "Identificativo stabile della spedizione: il numero di tracking può cambiare."
                },
                "mode": {
                  "type": "string",
                  "enum": [
                    "live",
                    "test"
                  ],
                  "description": "`test` per le spedizioni di prova."
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "creating",
                    "created",
                    "failed",
                    "cancelled"
                  ],
                  "description": "`creating`: in verifica (il corriere non ha dato un esito: non ripetere). `created`: creata. `failed`: rifiutata dal corriere, nessun addebito. `cancelled`: annullata e rimborsata."
                },
                "createdAt": {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                },
                "contractId": {
                  "type": "string",
                  "format": "uuid",
                  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                },
                "carrier": {
                  "type": "string",
                  "description": "Corriere che consegna, per esempio `BRT`, `GLS`, `POSTE`, `SDA`."
                },
                "contractName": {
                  "type": "string"
                },
                "trackingNumber": {
                  "description": "Numero di tracking. Su alcuni contratti nasce con un riferimento provvisorio di PackHub (`PK…`) e poi diventa quello del corriere: `GET /v1/tracking/{numero}` accetta tutti e due.",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "trackingStatus": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "reference": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "recipient": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "city": {
                      "type": "string"
                    },
                    "zipCode": {
                      "type": "string"
                    },
                    "province": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "name",
                    "city",
                    "zipCode",
                    "province"
                  ],
                  "additionalProperties": false
                },
                "parcelsCount": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "priceCents": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991,
                  "description": "Quanto è stato addebitato per il trasporto."
                }
              },
              "required": [
                "id",
                "mode",
                "status",
                "createdAt",
                "contractId",
                "carrier",
                "contractName",
                "trackingNumber",
                "trackingStatus",
                "reference",
                "recipient",
                "parcelsCount",
                "priceCents"
              ],
              "additionalProperties": false
            }
          },
          "nextCursor": {
            "description": "null = ultima pagina.",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items",
          "nextCursor"
        ],
        "additionalProperties": false
      },
      "Tracking": {
        "type": "object",
        "properties": {
          "shipmentId": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "mode": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ]
          },
          "trackingNumber": {
            "description": "Il numero attuale.",
            "type": [
              "string",
              "null"
            ]
          },
          "carrier": {
            "type": "string",
            "description": "Corriere che consegna, per esempio `BRT`, `GLS`, `POSTE`, `SDA`."
          },
          "status": {
            "type": "string",
            "enum": [
              "creating",
              "created",
              "failed",
              "cancelled"
            ],
            "description": "`creating`: in verifica (il corriere non ha dato un esito: non ripetere). `created`: creata. `failed`: rifiutata dal corriere, nessun addebito. `cancelled`: annullata e rimborsata."
          },
          "trackingStatus": {
            "type": [
              "string",
              "null"
            ]
          },
          "events": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "at": {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                },
                "status": {
                  "description": "Stato normalizzato, per esempio `IN_TRANSITO`, `CONSEGNATO`.",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "description": {
                  "type": "string"
                },
                "location": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "at",
                "status",
                "description",
                "location"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "shipmentId",
          "mode",
          "trackingNumber",
          "carrier",
          "status",
          "trackingStatus",
          "events"
        ],
        "additionalProperties": false
      }
    }
  }
}
