{
  "openapi": "3.0.3",
  "info": {
    "title": "PassPost B2B API",
    "version": "1.0.0",
    "description": "Create and track deliveries on the PassPost network. Authenticate using a Bearer API key from your business dashboard.",
    "contact": {
      "name": "PassPost",
      "url": "https://passpost.app",
      "email": "support@passpost.io"
    }
  },
  "servers": [
    {
      "url": "https://passpost.app/api/public/v1",
      "description": "Production"
    },
    {
      "url": "https://passpost.lovable.app/api/public/v1",
      "description": "Lovable"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key"
      }
    },
    "schemas": {
      "Task": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "accepted",
              "picked_up",
              "delivered",
              "completed",
              "cancelled"
            ]
          },
          "item": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "size": {
            "type": "string"
          },
          "urgency": {
            "type": "string"
          },
          "reward_nok": {
            "type": "integer"
          },
          "pickup": {
            "$ref": "#/components/schemas/Location"
          },
          "dropoff": {
            "$ref": "#/components/schemas/Location"
          },
          "recipient": {
            "$ref": "#/components/schemas/Recipient"
          },
          "carrier_id": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Location": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          },
          "address": {
            "type": "string",
            "nullable": true
          },
          "lat": {
            "type": "number",
            "nullable": true
          },
          "lng": {
            "type": "number",
            "nullable": true
          }
        }
      },
      "Recipient": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "nullable": true
          },
          "phone": {
            "type": "string",
            "nullable": true
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/tasks": {
      "post": {
        "summary": "Create a delivery task",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "item",
                  "reward_nok",
                  "pickup",
                  "dropoff"
                ],
                "properties": {
                  "item": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "category": {
                    "type": "string",
                    "enum": [
                      "Documents",
                      "Luggage",
                      "Marketplace",
                      "Keys",
                      "Parts",
                      "Recycling",
                      "Other"
                    ]
                  },
                  "size": {
                    "type": "string",
                    "enum": [
                      "envelope",
                      "small",
                      "medium",
                      "large",
                      "xl"
                    ]
                  },
                  "urgency": {
                    "type": "string",
                    "enum": [
                      "flexible",
                      "standard",
                      "express"
                    ]
                  },
                  "reward_nok": {
                    "type": "integer"
                  },
                  "deadline": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "pickup": {
                    "$ref": "#/components/schemas/Location"
                  },
                  "dropoff": {
                    "$ref": "#/components/schemas/Location"
                  },
                  "recipient": {
                    "$ref": "#/components/schemas/Recipient"
                  },
                  "external_reference": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Task created"
          }
        }
      },
      "get": {
        "summary": "List your tasks",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/tasks/{id}": {
      "get": {
        "summary": "Get a single task",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tasks/{id}/cancel": {
      "post": {
        "summary": "Cancel an open or accepted task",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled"
          },
          "409": {
            "description": "Invalid state"
          }
        }
      }
    }
  }
}