{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://veydrin.codeberg.page/protocols/vrs/vrs-v1.0.schema.json",
  "title": "VRS v1.0 Record",
  "description": "Veydrin Rating Standard v1.0 — counter or rating record.",
  "type": "object",
  "oneOf": [
    { "$ref": "#/$defs/counter_record" },
    { "$ref": "#/$defs/rating_record" }
  ],
  "$defs": {
    "counter_record": {
      "type": "object",
      "required": [
        "vrs_version",
        "record_type",
        "record_id",
        "source_app",
        "source_app_version",
        "timestamp",
        "public_key",
        "signature"
      ],
      "properties": {
        "vrs_version": {
          "type": "string",
          "const": "1.0",
          "description": "VRS specification version."
        },
        "record_type": {
          "type": "string",
          "const": "counter",
          "description": "Record type discriminator."
        },
        "record_id": {
          "type": "string",
          "format": "uuid",
          "description": "UUID v4, unique per record."
        },
        "source_app": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9]*(\\.[a-z][a-z0-9]*)+$",
          "maxLength": 256,
          "description": "Reverse-domain package identifier."
        },
        "source_app_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "description": "Semantic version per SemVer 2.0.0."
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 with timezone (RFC 3339)."
        },
        "public_key": {
          "type": "string",
          "minLength": 44,
          "maxLength": 44,
          "description": "Raw 32-byte Ed25519 public key, Base64-encoded with padding."
        },
        "signature": {
          "type": "string",
          "minLength": 88,
          "maxLength": 88,
          "description": "Raw 64-byte Ed25519 signature, Base64-encoded with padding."
        }
      },
      "additionalProperties": false
    },
    "rating_record": {
      "type": "object",
      "required": [
        "vrs_version",
        "record_type",
        "record_id",
        "source_app",
        "source_app_version",
        "timestamp",
        "stars",
        "contribution_proof",
        "public_key",
        "signature"
      ],
      "properties": {
        "vrs_version": {
          "type": "string",
          "const": "1.0",
          "description": "VRS specification version."
        },
        "record_type": {
          "type": "string",
          "const": "rating",
          "description": "Record type discriminator."
        },
        "record_id": {
          "type": "string",
          "format": "uuid",
          "description": "UUID v4, unique per record."
        },
        "source_app": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9]*(\\.[a-z][a-z0-9]*)+$",
          "maxLength": 256,
          "description": "Reverse-domain package identifier."
        },
        "source_app_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "description": "Semantic version per SemVer 2.0.0."
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 with timezone (RFC 3339)."
        },
        "stars": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5,
          "description": "Quality assessment. Whole stars only."
        },
        "comment": {
          "type": "string",
          "maxLength": 500,
          "description": "Optional free-text comment. Maximum 500 UTF-8 characters."
        },
        "contribution_proof": {
          "type": "string",
          "pattern": "^(vods|counter):[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
          "description": "Proof of usage. Format: 'vods:{export_id}' or 'counter:{record_id}'."
        },
        "public_key": {
          "type": "string",
          "minLength": 44,
          "maxLength": 44,
          "description": "Raw 32-byte Ed25519 public key, Base64-encoded with padding."
        },
        "signature": {
          "type": "string",
          "minLength": 88,
          "maxLength": 88,
          "description": "Raw 64-byte Ed25519 signature, Base64-encoded with padding."
        }
      },
      "additionalProperties": false
    }
  }
}
