{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.schemafirst.org/schemas/utm-source.schema.json",
  "title": "SchemaFirst UTM Source Record",
  "description": "A canonical source record in the SchemaFirst UTM Source Registry.",
  "type": "object",
  "required": ["id", "registry_version", "status", "display_name", "canonical_source", "aliases", "category", "contexts", "provenance", "references"],
  "additionalProperties": false,
  "$defs": {
    "token": {
      "type": "string",
      "pattern": "^[a-z0-9]+(_[a-z0-9]+)*$"
    },
    "provenanceClass": {
      "enum": ["google_defined", "schemafirst_default", "organization_override_permitted"]
    }
  },
  "properties": {
    "$schema": { "type": "string", "format": "uri" },
    "id": { "$ref": "#/$defs/token" },
    "registry_version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
    "status": { "enum": ["draft", "stable", "deprecated"] },
    "display_name": { "type": "string", "minLength": 1 },
    "canonical_source": { "$ref": "#/$defs/token" },
    "aliases": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "category": { "enum": ["search", "social", "video", "email", "sms", "display", "referral", "affiliate", "audio", "other"] },
    "contexts": {
      "type": "object",
      "minProperties": 1,
      "propertyNames": { "$ref": "#/$defs/token" },
      "additionalProperties": {
        "type": "object",
        "required": ["description", "utm_medium", "intended_google_channel"],
        "additionalProperties": false,
        "properties": {
          "description": { "type": "string" },
          "utm_medium": { "$ref": "#/$defs/token" },
          "intended_google_channel": { "type": "string" }
        }
      }
    },
    "notes": {
      "type": "array",
      "items": { "type": "string" }
    },
    "provenance": {
      "type": "object",
      "required": ["canonical_source", "explanation"],
      "properties": {
        "explanation": { "type": "string" }
      },
      "additionalProperties": { "$ref": "#/$defs/provenanceClass" }
    },
    "references": {
      "type": "array",
      "items": { "type": "string", "format": "uri" }
    }
  }
}
