{
  "$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"
    },
    "inAppCounts": {
      "description": "Per-category counts of activity performed inside anisota, summed across the period and across devices.",
      "properties": {
        "likes": {
          "description": "Likes created in anisota",
          "minimum": 0,
          "type": "integer"
        },
        "posts": {
          "description": "Top-level posts created in anisota",
          "minimum": 0,
          "type": "integer"
        },
        "quotes": {
          "description": "Quote posts created in anisota",
          "minimum": 0,
          "type": "integer"
        },
        "replies": {
          "description": "Replies created in anisota",
          "minimum": 0,
          "type": "integer"
        },
        "reposts": {
          "description": "Reposts created in anisota",
          "minimum": 0,
          "type": "integer"
        }
      },
      "type": "object"
    },
    "main": {
      "description": "Weekly aggregation of daily records. rkey is YYYY-WNN (ISO week). Updated once per day, finalized when week ends.",
      "key": "any",
      "record": {
        "properties": {
          "aggregates": {
            "ref": "#weeklyAggregates",
            "type": "ref"
          },
          "createdAt": {
            "description": "When the weekly record was first created",
            "format": "datetime",
            "type": "string"
          },
          "expeditionRefs": {
            "description": "AT URIs of expedition records that occurred during this week",
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "finalizedAt": {
            "description": "When the weekly record was finalized (end of week)",
            "format": "datetime",
            "type": "string"
          },
          "inApp": {
            "description": "Rolled-up in-anisota activity for the week (summed daily inApp across devices, per field). Optional and additive; the read side may instead compute this from the week's daily logs.",
            "ref": "#inAppCounts",
            "type": "ref"
          },
          "lowerLogRefs": {
            "description": "AT URIs of daily log records included in this week",
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "patterns": {
            "ref": "#weeklyPatterns",
            "type": "ref"
          },
          "signature": {
            "ref": "#chronicleSignature",
            "type": "ref"
          },
          "status": {
            "description": "Whether this week is still being updated or has been finalized",
            "enum": [
              "active",
              "finalized"
            ],
            "type": "string"
          },
          "trends": {
            "ref": "#trendData",
            "type": "ref"
          },
          "upperLogRefs": {
            "description": "AT URIs of containing logs (monthly, yearly) this week belongs to",
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "week": {
            "description": "ISO week string in YYYY-WNN format (e.g. 2026-W06)",
            "type": "string"
          }
        },
        "required": [
          "week",
          "aggregates",
          "status",
          "signature",
          "createdAt"
        ],
        "type": "object"
      },
      "type": "record"
    },
    "trendData": {
      "description": "Week-over-week trend comparisons",
      "properties": {
        "activityChange": {
          "description": "Percentage change in activity compared to previous week",
          "type": "string"
        },
        "engagementChange": {
          "description": "Percentage change in engagement compared to previous week",
          "type": "string"
        },
        "xpChange": {
          "description": "Percentage change in XP compared to previous week (e.g. '+12%')",
          "type": "string"
        }
      },
      "type": "object"
    },
    "weeklyAggregates": {
      "description": "Rolled-up counts from daily records",
      "properties": {
        "daysActive": {
          "description": "Number of days with activity this week",
          "minimum": 0,
          "type": "integer"
        },
        "likesReceived": {
          "description": "Total likes received this week",
          "minimum": 0,
          "type": "integer"
        },
        "postsCreated": {
          "description": "Total posts created this week",
          "minimum": 0,
          "type": "integer"
        },
        "postsRead": {
          "description": "Total posts read this week",
          "minimum": 0,
          "type": "integer"
        },
        "quotesReceived": {
          "description": "Total quotes received this week",
          "minimum": 0,
          "type": "integer"
        },
        "repliesReceived": {
          "description": "Total replies received this week",
          "minimum": 0,
          "type": "integer"
        },
        "repostsReceived": {
          "description": "Total reposts received this week",
          "minimum": 0,
          "type": "integer"
        },
        "specimensPhotographed": {
          "description": "New specimens photographed this week",
          "minimum": 0,
          "type": "integer"
        },
        "totalXPGained": {
          "description": "Total XP gained this week",
          "minimum": 0,
          "type": "integer"
        }
      },
      "type": "object"
    },
    "weeklyPatterns": {
      "description": "Activity pattern aggregation for the week based on half-hour blocks",
      "properties": {
        "avgBlocksPerDay": {
          "description": "Average active blocks per day (totalActiveBlocks / daysActive, rounded)",
          "minimum": 0,
          "type": "integer"
        },
        "peakBlocks": {
          "description": "Highest activeBlockCount for any single day in the week",
          "maximum": 48,
          "minimum": 0,
          "type": "integer"
        },
        "totalActiveBlocks": {
          "description": "Sum of activeBlockCount across all days in the week",
          "minimum": 0,
          "type": "integer"
        }
      },
      "type": "object"
    }
  },
  "id": "net.anisota.chronicle.log.weekly",
  "lexicon": 1
}
