{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openfreytprotocol.example/schemas/v0/capacity-offer",
  "title": "CapacityOffer",
  "description": "A carrier's offer of available transport capacity between two areas within a departure window.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "UUIDv7 resource identifier."
    },
    "resourceVersion": {
      "type": "integer",
      "minimum": 1,
      "description": "Optimistic-concurrency counter. Incremented on every mutation."
    },
    "ownerOrganizationId": {
      "type": "string",
      "description": "Opaque broker-scoped identifier of the organization that owns this resource."
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 / RFC 3339 timestamp when the resource was first created."
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 / RFC 3339 timestamp of the most recent mutation."
    },
    "externalReferences": {
      "type": "array",
      "items": { "$ref": "#/$defs/ExternalReference" },
      "description": "Namespaced references to records in external systems (TMS, ERP, etc.)."
    },
    "status": {
      "type": "string",
      "enum": ["draft", "published", "partiallyMatched", "matched", "withdrawn", "expired", "cancelled"],
      "description": "Lifecycle state of the capacity offer."
    },
    "originArea": {
      "$ref": "https://openfreytprotocol.example/schemas/v0/area",
      "description": "Geographic area from which the vehicle departs."
    },
    "destinationArea": {
      "$ref": "https://openfreytprotocol.example/schemas/v0/area",
      "description": "Geographic area where the vehicle arrives."
    },
    "vehicleSpec": {
      "$ref": "https://openfreytprotocol.example/schemas/v0/vehicle-spec",
      "description": "Specification of the vehicle or vehicle type being offered."
    },
    "departureWindowStart": {
      "type": "string",
      "format": "date-time",
      "description": "Earliest ISO 8601 date-time at which the vehicle is available to depart."
    },
    "departureWindowEnd": {
      "type": "string",
      "format": "date-time",
      "description": "Latest ISO 8601 date-time at which the vehicle can depart."
    },
    "availableCapacity": {
      "type": "object",
      "description": "The capacity currently available for loading.",
      "properties": {
        "weightKg": {
          "type": "number",
          "minimum": 0,
          "description": "Available weight capacity in kilograms."
        },
        "volumeM3": {
          "type": "number",
          "minimum": 0,
          "description": "Available volume capacity in cubic metres."
        },
        "loadingMetres": {
          "type": "number",
          "minimum": 0,
          "description": "Available loading metres on the trailer floor."
        }
      }
    }
  },
  "required": [
    "id",
    "resourceVersion",
    "ownerOrganizationId",
    "createdAt",
    "updatedAt",
    "status",
    "originArea",
    "destinationArea",
    "vehicleSpec",
    "departureWindowStart",
    "departureWindowEnd",
    "availableCapacity"
  ],
  "$defs": {
    "ExternalReference": {
      "type": "object",
      "properties": {
        "system": { "type": "string" },
        "type": { "type": "string" },
        "value": { "type": "string" }
      },
      "required": ["system", "type", "value"]
    }
  }
}
