{
  "type": "object",
  "description": "{ok, data, error} envelope. Exactly one of data/error is non-null.",
  "properties": {
    "ok": {
      "type": "boolean"
    },
    "data": {
      "type": [
        "object",
        "null"
      ],
      "description": "Present only when ok=true",
      "properties": {
        "rates": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "serviceId": {
                "type": "string"
              },
              "displayName": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "PICKUP_POINT",
                  "PARCEL_LOCKER",
                  "DOOR",
                  "MAILBOX",
                  "MAILBOX_ABROAD",
                  "PARCEL_TO_BUSINESS",
                  "GROUPAGE",
                  "PALLET"
                ]
              },
              "brand": {
                "type": "string"
              },
              "price": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string",
                    "description": "ISO 4217 currency code declared by cart.currency; no conversion is performed"
                  }
                },
                "required": [
                  "amount",
                  "currency"
                ],
                "additionalProperties": false
              },
              "agreedDelivery": {
                "type": "boolean",
                "description": "True when this service has an agreed/guaranteed delivery date"
              },
              "leadTime": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "deliveryDate": {
                    "type": "string",
                    "format": "date"
                  },
                  "deliveryTimeWindow": {
                    "type": "object",
                    "description": "Delivery time window. Times are HH:mm (24-hour, local time), or null if unknown.",
                    "properties": {
                      "from": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "to": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "additionalProperties": false
                  },
                  "deliveryDateAlternatives": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "object",
                      "properties": {
                        "deliveryDate": {
                          "type": "string",
                          "format": "date"
                        },
                        "deliveryTimeWindows": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "description": "Delivery time window. Times are HH:mm (24-hour, local time), or null if unknown.",
                            "properties": {
                              "from": {
                                "type": [
                                  "string",
                                  "null"
                                ]
                              },
                              "to": {
                                "type": [
                                  "string",
                                  "null"
                                ]
                              }
                            },
                            "additionalProperties": false
                          }
                        }
                      },
                      "required": [
                        "deliveryDate",
                        "deliveryTimeWindows"
                      ],
                      "additionalProperties": false
                    }
                  }
                },
                "required": [
                  "deliveryDate"
                ]
              },
              "pickupPoints": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The pickupPointId used to match a recommendation/rejectedOption to a specific pickup point"
                    },
                    "displayName": {
                      "type": "string"
                    },
                    "address": {
                      "type": "object",
                      "properties": {
                        "addressLine": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "postalCode": {
                          "type": "string"
                        },
                        "city": {
                          "type": "string"
                        },
                        "countryCode": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "postalCode",
                        "city",
                        "countryCode"
                      ],
                      "additionalProperties": false
                    },
                    "formattedAddress": {
                      "type": "string"
                    },
                    "distanceInKm": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "open247": {
                      "type": "boolean"
                    },
                    "openingHours": {
                      "type": "string",
                      "description": "Free text, in the language given by openingHoursLanguage"
                    },
                    "openingHoursLanguage": {
                      "type": "string",
                      "description": "BCP 47 tag for the language openingHours is written in"
                    },
                    "coordinates": {
                      "type": "object",
                      "properties": {
                        "lat": {
                          "type": "number"
                        },
                        "long": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "lat",
                        "long"
                      ],
                      "additionalProperties": false
                    },
                    "leadTime": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "deliveryDate": {
                          "type": "string",
                          "format": "date"
                        },
                        "deliveryTimeWindow": {
                          "type": "object",
                          "description": "Delivery time window. Times are HH:mm (24-hour, local time), or null if unknown.",
                          "properties": {
                            "from": {
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "to": {
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "additionalProperties": false
                        },
                        "deliveryDateAlternatives": {
                          "type": [
                            "array",
                            "null"
                          ],
                          "items": {
                            "type": "object",
                            "properties": {
                              "deliveryDate": {
                                "type": "string",
                                "format": "date"
                              },
                              "deliveryTimeWindows": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "description": "Delivery time window. Times are HH:mm (24-hour, local time), or null if unknown.",
                                  "properties": {
                                    "from": {
                                      "type": [
                                        "string",
                                        "null"
                                      ]
                                    },
                                    "to": {
                                      "type": [
                                        "string",
                                        "null"
                                      ]
                                    }
                                  },
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "deliveryDate",
                              "deliveryTimeWindows"
                            ],
                            "additionalProperties": false
                          }
                        }
                      },
                      "required": [
                        "deliveryDate"
                      ]
                    },
                    "environmentalData": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "null fields mean unknown, not false",
                      "properties": {
                        "fossilFree": {
                          "type": [
                            "boolean",
                            "null"
                          ]
                        },
                        "nordicSwanEcoLabel": {
                          "type": [
                            "boolean",
                            "null"
                          ]
                        },
                        "tagUrl": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      },
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "id",
                    "displayName",
                    "address",
                    "formattedAddress",
                    "open247",
                    "openingHours",
                    "openingHoursLanguage",
                    "coordinates"
                  ],
                  "additionalProperties": false
                }
              },
              "environmentalData": {
                "type": [
                  "object",
                  "null"
                ],
                "description": "null fields mean unknown, not false",
                "properties": {
                  "fossilFree": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "nordicSwanEcoLabel": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "tagUrl": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "additionalProperties": false
              }
            },
            "required": [
              "serviceId",
              "displayName",
              "description",
              "type",
              "brand",
              "price",
              "agreedDelivery"
            ],
            "additionalProperties": false
          }
        },
        "recommendation": {
          "type": [
            "object",
            "null"
          ],
          "description": "The (serviceId, pickupPointId) here always corresponds exactly to an entry (or nested pickup point) in data.rates - never a dropped or unknown service.",
          "properties": {
            "serviceId": {
              "type": "string"
            },
            "pickupPointId": {
              "type": [
                "string",
                "null"
              ]
            },
            "intent": {
              "type": "string",
              "enum": [
                "CHEAPEST",
                "FASTEST",
                "LOWEST_EMISSIONS",
                "MOST_PREDICTABLE"
              ]
            },
            "reasonCodes": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "LOWEST_PRICE",
                  "EARLIEST_DELIVERY",
                  "KNOWN_DELIVERY_DATE",
                  "FOSSIL_FREE",
                  "NORDIC_SWAN_ECO_LABEL",
                  "AGREED_DELIVERY",
                  "NARROW_DELIVERY_WINDOW",
                  "PRICE_ABOVE_MAXIMUM",
                  "DELIVERY_AFTER_DEADLINE",
                  "DELIVERY_TYPE_NOT_ALLOWED",
                  "FOSSIL_FREE_REQUIRED",
                  "DELIVERY_DATE_UNKNOWN",
                  "ENVIRONMENTAL_DATA_INCOMPLETE"
                ]
              }
            },
            "explanation": {
              "type": "string",
              "description": "Always in English"
            },
            "rankingPolicyVersion": {
              "type": "string"
            }
          },
          "required": [
            "serviceId",
            "intent",
            "reasonCodes",
            "explanation",
            "rankingPolicyVersion"
          ]
        },
        "rejectedOptions": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "serviceId": {
                "type": "string"
              },
              "pickupPointId": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "reasonCodes": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "LOWEST_PRICE",
                    "EARLIEST_DELIVERY",
                    "KNOWN_DELIVERY_DATE",
                    "FOSSIL_FREE",
                    "NORDIC_SWAN_ECO_LABEL",
                    "AGREED_DELIVERY",
                    "NARROW_DELIVERY_WINDOW",
                    "PRICE_ABOVE_MAXIMUM",
                    "DELIVERY_AFTER_DEADLINE",
                    "DELIVERY_TYPE_NOT_ALLOWED",
                    "FOSSIL_FREE_REQUIRED",
                    "DELIVERY_DATE_UNKNOWN",
                    "ENVIRONMENTAL_DATA_INCOMPLETE"
                  ]
                }
              }
            },
            "required": [
              "serviceId",
              "reasonCodes"
            ],
            "additionalProperties": false
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "NO_AVAILABLE_RATES",
                  "NO_OPTIONS_MATCH_CONSTRAINTS",
                  "ENVIRONMENTAL_RANKING_USES_LABELS",
                  "ENVIRONMENTAL_DATA_INCOMPLETE",
                  "INSUFFICIENT_DELIVERY_DATA",
                  "INSUFFICIENT_PREDICTABILITY_DATA"
                ]
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "rates",
        "rejectedOptions",
        "warnings"
      ],
      "additionalProperties": false
    },
    "error": {
      "type": [
        "object",
        "null"
      ],
      "description": "Present only when ok=false. Never contains raw exception messages, stack traces, or internal identifiers.",
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "INVALID_ARGUMENT",
            "WEBSHOP_NOT_FOUND",
            "WEBSHOP_NOT_INSTALLED",
            "UNSUPPORTED_ORIGIN_COUNTRY",
            "UNSUPPORTED_DESTINATION_COUNTRY",
            "UPSTREAM_UNAVAILABLE",
            "RATE_CALCULATION_FAILED",
            "INTERNAL_ERROR"
          ]
        },
        "message": {
          "type": "string"
        },
        "field": {
          "type": [
            "string",
            "null"
          ],
          "description": "Dotted path of the offending request field, if applicable"
        },
        "retryable": {
          "type": "boolean",
          "description": "True only when retrying the same call could plausibly succeed, e.g. a transient upstream failure"
        }
      },
      "required": [
        "code",
        "message",
        "retryable"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "ok",
    "data",
    "error"
  ],
  "additionalProperties": false
}
