{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openfreytprotocol.example/schemas/v0/common-envelope",
  "title": "CommonEnvelope",
  "description": "Shared envelope included in every PCX resource. Resource schemas extend this by merging its properties rather than $ref-composing it, to avoid additionalProperties conflicts.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "UUIDv7 resource identifier. Opaque to consumers; ordering is time-monotonic."
    },
    "resourceVersion": {
      "type": "integer",
      "minimum": 1,
      "description": "Monotonically increasing optimistic-concurrency counter. Incremented by the broker 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.)."
    }
  },
  "required": [
    "id",
    "resourceVersion",
    "ownerOrganizationId",
    "createdAt",
    "updatedAt"
  ],
  "$defs": {
    "ExternalReference": {
      "title": "ExternalReference",
      "description": "A typed pointer to a record in an external system.",
      "type": "object",
      "properties": {
        "system": {
          "type": "string",
          "description": "Identifier of the external system, e.g. 'carrier-a-tms' or 'shipper-b-erp'."
        },
        "type": {
          "type": "string",
          "description": "Record type within the external system, e.g. 'trip', 'order', 'shipment'."
        },
        "value": {
          "type": "string",
          "description": "Identifier value within the external system."
        }
      },
      "required": ["system", "type", "value"]
    }
  }
}
