{
  "openapi": "3.1.0",
  "info": {
    "title": "KopGek Partner API",
    "version": "1.0.0",
    "description": "Offerteaanvragen, catalogus en verzending. Productie pas na controle door KopGek."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "components": {
    "securitySchemes": {
      "partnerKey": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Item": {
        "type": "object",
        "required": [
          "productId",
          "quantity"
        ],
        "properties": {
          "productId": {
            "type": "string"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000
          },
          "pageCount": {
            "type": "integer",
            "minimum": 16,
            "maximum": 500,
            "multipleOf": 2
          }
        }
      },
      "Address": {
        "type": "object",
        "required": [
          "name",
          "line1",
          "postCode",
          "city",
          "country"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "line1": {
            "type": "string"
          },
          "postCode": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "country": {
            "type": "string",
            "enum": [
              "NL",
              "BE"
            ]
          }
        }
      },
      "OrderRequest": {
        "type": "object",
        "required": [
          "customer",
          "items",
          "shipping"
        ],
        "properties": {
          "reference": {
            "type": "string",
            "maxLength": 100
          },
          "customer": {
            "type": "object",
            "required": [
              "name",
              "email"
            ],
            "properties": {
              "name": {
                "type": "string",
                "maxLength": 120
              },
              "email": {
                "type": "string",
                "format": "email",
                "maxLength": 180
              }
            }
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/Item"
            }
          },
          "shipping": {
            "type": "object",
            "required": [
              "method"
            ],
            "properties": {
              "method": {
                "enum": [
                  "pickup",
                  "delivery",
                  "digital"
                ]
              },
              "address": {
                "$ref": "#/components/schemas/Address"
              }
            },
            "description": "Address is required for delivery. Digital products require digital; Print API books require delivery."
          },
          "personalization": {
            "type": "string",
            "maxLength": 2400
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "enum": [
              "requested",
              "approved",
              "submitting",
              "submitted",
              "processing",
              "shipped",
              "cancelled",
              "needs_review"
            ]
          },
          "request": {
            "$ref": "#/components/schemas/OrderRequest"
          },
          "trackingUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "productionMode": {
            "enum": [
              "test",
              "live",
              null
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "ShippingQuote": {
        "type": "object",
        "properties": {
          "method": {
            "type": "string"
          },
          "status": {
            "enum": [
              "available",
              "quote_required",
              "test_quote"
            ]
          },
          "amountCents": {
            "type": [
              "integer",
              "null"
            ],
            "description": "null means quotation required, never free."
          },
          "currency": {
            "const": "EUR"
          },
          "includesVat": {
            "type": "boolean"
          },
          "label": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/products": {
      "get": {
        "summary": "Productcatalogus",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/shipping/methods": {
      "get": {
        "summary": "Leveringsmogelijkheden",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/status": {
      "get": {
        "summary": "API-status",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/orders": {
      "post": {
        "summary": "Offerteaanvraag indienen",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{8,100}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderRequest"
              }
            }
          }
        },
        "responses": {
          "400": {
            "description": "Ongeldige invoer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ongeldige sleutel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Niet gevonden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limiet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Leverancier niet beschikbaar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Tijdelijk niet beschikbaar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Bestaande aanvraag",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "201": {
            "description": "Aangemaakt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/orders/{id}": {
      "get": {
        "summary": "Eigen aanvraag volgen",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "400": {
            "description": "Ongeldige invoer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ongeldige sleutel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Niet gevonden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limiet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Leverancier niet beschikbaar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Tijdelijk niet beschikbaar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Aanvraag",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/shipping/quote": {
      "post": {
        "summary": "Verzendkosten of offerte nodig",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "items",
                  "method"
                ],
                "properties": {
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 20,
                    "items": {
                      "$ref": "#/components/schemas/Item"
                    }
                  },
                  "method": {
                    "enum": [
                      "pickup",
                      "delivery",
                      "digital"
                    ]
                  },
                  "country": {
                    "enum": [
                      "NL",
                      "BE"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "400": {
            "description": "Ongeldige invoer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ongeldige sleutel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Niet gevonden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limiet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Leverancier niet beschikbaar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Tijdelijk niet beschikbaar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Verzendquote",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShippingQuote"
                }
              }
            }
          }
        }
      }
    }
  }
}