{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cleanplaystandards.org/schemas/credential.schema.json",
  "title": "Clean Play Certified Signed Credential Payload",
  "description": "Payload signed as an ES256 compact JWS. Signature integrity does not replace current registry status.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "iss",
    "sub",
    "credential_id",
    "standard",
    "product",
    "scope",
    "audit",
    "issued_at",
    "expires_at",
    "status_at_issuance",
    "status_url",
    "registry_url"
  ],
  "properties": {
    "iss": {
      "const": "https://cleanplaystandards.org"
    },
    "sub": {
      "type": "string",
      "pattern": "^clean-play-product:CPS-A-[0-9]{4}-[0-9A-Z]{6,20}$"
    },
    "credential_id": {
      "type": "string",
      "pattern": "^CPS-[0-9]{4}-[0-9A-Z]{6,20}$"
    },
    "standard": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "code",
        "name",
        "version"
      ],
      "properties": {
        "code": {
          "const": "CPS-MG-1.0"
        },
        "name": {
          "const": "Clean Play Standards 1.0: Mobile Games"
        },
        "version": {
          "const": "1.0"
        }
      }
    },
    "product": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "organization",
        "store_urls"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "organization": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "store_urls": {
          "type": "array",
          "maxItems": 10,
          "items": {
            "type": "string",
            "format": "uri"
          }
        }
      }
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "platforms",
        "package_ids",
        "version_scope",
        "regions",
        "limitations"
      ],
      "properties": {
        "platforms": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "enum": [
              "iOS",
              "iPadOS",
              "Android"
            ]
          }
        },
        "package_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 3,
            "maxLength": 255
          }
        },
        "version_scope": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "regions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 2,
            "maxLength": 100
          }
        },
        "limitations": {
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 500
          }
        }
      }
    },
    "audit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "decision_id",
        "completed_at",
        "decision_digest",
        "public_summary"
      ],
      "properties": {
        "decision_id": {
          "type": "string",
          "minLength": 3,
          "maxLength": 100
        },
        "completed_at": {
          "type": "string",
          "format": "date-time"
        },
        "decision_digest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "public_summary": {
          "type": "string",
          "maxLength": 5000
        }
      }
    },
    "issued_at": {
      "type": "string",
      "format": "date-time"
    },
    "expires_at": {
      "type": "string",
      "format": "date-time"
    },
    "status_at_issuance": {
      "const": "active"
    },
    "status_url": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://cleanplaystandards\\.org/api/v1/credentials/.+/status$"
    },
    "registry_url": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://cleanplaystandards\\.org/verify/"
    }
  }
}
