{
  "openapi": "3.1.0",
  "info": {
    "title": "ComplyOnSite Digital Waste Tracking API",
    "version": "2026-07-27",
    "description": "Endpoints used by the public Receipt of Waste spreadsheet checker. The workbook endpoint is not a stable integration API. This is not a Defra submission API."
  },
  "servers": [
    {
      "url": "https://complyonsite.com"
    }
  ],
  "paths": {
    "/api/digital-waste-tracking-check": {
      "post": {
        "summary": "Check a supported Receipt of Waste workbook",
        "description": "Same-origin endpoint used by the public checker. It accepts one supported XLSX workbook and returns the deterministic check result. It is not a stable third-party integration contract.",
        "operationId": "checkDigitalWasteTrackingWorkbook",
        "requestBody": {
          "required": true,
          "content": {
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Workbook checked. The body is one of ready, improved, blocked or unsupported.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    { "$ref": "#/components/schemas/DwtReady" },
                    { "$ref": "#/components/schemas/DwtImproved" },
                    { "$ref": "#/components/schemas/DwtBlocked" },
                    { "$ref": "#/components/schemas/DwtUnsupported" }
                  ],
                  "discriminator": {
                    "propertyName": "status"
                  }
                }
              }
            }
          },
          "405": {
            "description": "Use POST for this endpoint.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DwtFailed" }
              }
            }
          },
          "413": {
            "description": "Workbook exceeds the size limit.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DwtFailed" }
              }
            }
          },
          "415": {
            "description": "Request is not a supported workbook upload.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DwtFailed" }
              }
            }
          },
          "429": {
            "description": "Request limit reached.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DwtFailed" }
              }
            }
          },
          "500": {
            "description": "The checker or its output proof failed. No workbook is returned.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DwtFailed" }
              }
            }
          },
          "503": {
            "description": "Workbook checking is temporarily unavailable.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DwtFailed" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DwtWireFinding": {
        "type": "object",
        "additionalProperties": false,
        "required": ["code", "kind", "row", "cell"],
        "properties": {
          "code": { "type": "string" },
          "kind": { "type": "string", "enum": ["movement", "item"] },
          "row": { "type": "integer", "minimum": 1 },
          "cell": { "type": "string" },
          "movementReference": { "type": "string" }
        }
      },
      "DwtWireRepair": {
        "type": "object",
        "additionalProperties": false,
        "required": ["kind", "row", "cell", "oldValue", "newValue"],
        "properties": {
          "kind": { "type": "string", "enum": ["movement", "item"] },
          "row": { "type": "integer", "minimum": 1 },
          "cell": { "type": "string" },
          "oldValue": { "type": "string" },
          "newValue": { "type": "string" }
        }
      },
      "DwtReady": {
        "type": "object",
        "additionalProperties": false,
        "required": ["status", "workbookBase64", "movementCount", "itemCount", "repairs", "warnings"],
        "properties": {
          "status": { "const": "ready" },
          "workbookBase64": { "type": "string", "contentEncoding": "base64" },
          "movementCount": { "type": "integer", "minimum": 0 },
          "itemCount": { "type": "integer", "minimum": 0 },
          "repairs": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/DwtWireRepair" }
          },
          "warnings": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/DwtWireFinding" }
          }
        }
      },
      "DwtImproved": {
        "type": "object",
        "additionalProperties": false,
        "required": ["status", "workbookBase64", "movementCount", "itemCount", "repairs", "blockers", "warnings"],
        "properties": {
          "status": { "const": "improved" },
          "workbookBase64": { "type": "string", "contentEncoding": "base64" },
          "movementCount": { "type": "integer", "minimum": 0 },
          "itemCount": { "type": "integer", "minimum": 0 },
          "repairs": {
            "type": "array",
            "minItems": 1,
            "items": { "$ref": "#/components/schemas/DwtWireRepair" }
          },
          "blockers": {
            "type": "array",
            "minItems": 1,
            "items": { "$ref": "#/components/schemas/DwtWireFinding" }
          },
          "warnings": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/DwtWireFinding" }
          }
        }
      },
      "DwtBlocked": {
        "type": "object",
        "additionalProperties": false,
        "required": ["status", "movementCount", "itemCount", "blockers", "warnings"],
        "properties": {
          "status": { "const": "blocked" },
          "movementCount": { "type": "integer", "minimum": 0 },
          "itemCount": { "type": "integer", "minimum": 0 },
          "blockers": {
            "type": "array",
            "minItems": 1,
            "items": { "$ref": "#/components/schemas/DwtWireFinding" }
          },
          "warnings": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/DwtWireFinding" }
          }
        }
      },
      "DwtUnsupported": {
        "type": "object",
        "additionalProperties": false,
        "required": ["status", "problems"],
        "properties": {
          "status": { "const": "unsupported" },
          "problems": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["code"],
              "properties": {
                "code": { "type": "string" }
              }
            }
          }
        }
      },
      "DwtFailed": {
        "type": "object",
        "additionalProperties": false,
        "required": ["status", "code", "message", "retryable"],
        "properties": {
          "status": { "const": "failed" },
          "code": { "type": "string" },
          "message": { "type": "string" },
          "retryable": { "type": "boolean" }
        }
      }
    }
  }
}
