{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openfreytprotocol.example/schemas/v0/organization-reference",
  "title": "OrganizationReference",
  "description": "Reference to a participating organization, with an optional legal identifier for cross-system reconciliation.",
  "type": "object",
  "properties": {
    "organizationId": {
      "type": "string",
      "description": "Opaque broker-scoped organization identifier. Consumers must treat this as an untyped string."
    },
    "legalIdentifier": {
      "$ref": "#/$defs/LegalIdentifier"
    }
  },
  "required": ["organizationId"],
  "$defs": {
    "LegalIdentifier": {
      "title": "LegalIdentifier",
      "description": "A recognized legal or trade identifier for an organization.",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["GLN", "EORI", "DUNS", "custom"],
          "description": "Identifier scheme. Use 'custom' when the scheme is proprietary or not yet in the standard enum."
        },
        "value": {
          "type": "string",
          "description": "Value of the legal identifier within the chosen scheme."
        }
      },
      "required": ["type", "value"]
    }
  }
}
