{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "chronicleSignature": {
      "description": "ES256 cryptographic signature proving record authenticity",
      "properties": {
        "alg": {
          "description": "Signing algorithm (ES256)",
          "type": "string"
        },
        "kid": {
          "description": "Key identifier for the signing key",
          "type": "string"
        },
        "nonce": {
          "description": "Unique random nonce to prevent replay",
          "type": "string"
        },
        "sig": {
          "description": "Base64-encoded ES256 signature",
          "type": "string"
        },
        "signedAt": {
          "description": "When the record was signed",
          "format": "datetime",
          "type": "string"
        },
        "version": {
          "description": "Signature schema version",
          "type": "integer"
        }
      },
      "required": [
        "sig",
        "alg",
        "kid",
        "signedAt",
        "nonce",
        "version"
      ],
      "type": "object"
    },
    "main": {
      "description": "Signed player progression state, one record per game season, overwritten via putRecord. rkey is self before the 2027 season, and the season id (e.g. 2027) from then on. Backend validates XP claims before signing.",
      "key": "any",
      "record": {
        "properties": {
          "createdAt": {
            "description": "When the record was first created",
            "format": "datetime",
            "type": "string"
          },
          "level": {
            "description": "Current player level (derived from XP table)",
            "maximum": 99,
            "minimum": 1,
            "type": "integer"
          },
          "progressPercentage": {
            "description": "Progress toward next level as decimal string",
            "type": "string"
          },
          "season": {
            "description": "The game season this record counts toward, e.g. 2027. Absent: before the 2027 season.",
            "maxLength": 8,
            "type": "string"
          },
          "signature": {
            "ref": "#chronicleSignature",
            "type": "ref"
          },
          "totalXP": {
            "description": "Total accumulated XP",
            "minimum": 0,
            "type": "integer"
          },
          "triggerSource": {
            "description": "What triggered this save (level_up, session_end, visibility_hidden, periodic, card_advance)",
            "type": "string"
          },
          "updatedAt": {
            "description": "When the record was last updated",
            "format": "datetime",
            "type": "string"
          },
          "xpGainedSinceLastSign": {
            "description": "XP gained since the last signed progress record (for rate validation against daily activity)",
            "minimum": 0,
            "type": "integer"
          },
          "xpToNextLevel": {
            "description": "XP remaining to reach next level",
            "minimum": 0,
            "type": "integer"
          }
        },
        "required": [
          "totalXP",
          "level",
          "signature",
          "createdAt"
        ],
        "type": "object"
      },
      "type": "record"
    }
  },
  "id": "net.anisota.chronicle.progress",
  "lexicon": 1
}
