{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.hoodbuybutton.com/schemas/bagwork-entry-v2.json",
  "title": "The Buy Button Proof of Bagwork daily entry with completed-day residue",
  "$defs": {
    "work": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/workItem" }
    },
    "workItem": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "category", "title", "impact", "state", "evidence"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{1,63}$" },
        "category": { "type": "string", "enum": ["proof", "ecosystem", "data", "listing", "distribution", "preservation", "outreach", "content", "product"] },
        "title": { "type": "string", "minLength": 3, "maxLength": 180 },
        "impact": { "type": "string", "minLength": 3, "maxLength": 220 },
        "state": { "type": "string", "enum": ["live", "submitted", "pending", "prepared"] },
        "evidence": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["label", "url"],
            "properties": {
              "label": { "type": "string", "minLength": 1, "maxLength": 60 },
              "url": { "type": "string", "format": "uri", "pattern": "^https://" }
            }
          }
        }
      }
    },
    "xAnalytics": {
      "type": "object",
      "additionalProperties": false,
      "required": ["date", "source", "observedAt", "accounts"],
      "properties": {
        "date": { "type": "string", "format": "date" },
        "source": { "const": "X account analytics" },
        "observedAt": { "type": "string", "format": "date-time" },
        "accounts": {
          "type": "array",
          "minItems": 2,
          "maxItems": 2,
          "items": { "$ref": "#/$defs/xAccount" }
        }
      }
    },
    "xAccount": {
      "type": "object",
      "additionalProperties": false,
      "required": ["handle", "role", "metrics", "precision"],
      "properties": {
        "handle": { "type": "string", "pattern": "^@[A-Za-z0-9_]{1,15}$" },
        "role": { "type": "string", "enum": ["official", "builder"] },
        "metrics": {
          "type": "object",
          "additionalProperties": false,
          "required": ["impressions", "engagements", "engagementRatePct", "profileVisits", "likes", "reposts", "replies", "bookmarks", "shares"],
          "properties": {
            "impressions": { "type": "number", "minimum": 0 },
            "engagements": { "type": "integer", "minimum": 0 },
            "engagementRatePct": { "type": "number", "minimum": 0, "maximum": 100 },
            "profileVisits": { "type": "integer", "minimum": 0 },
            "likes": { "type": "integer", "minimum": 0 },
            "reposts": { "type": "integer", "minimum": 0 },
            "replies": { "type": "integer", "minimum": 0 },
            "bookmarks": { "type": "integer", "minimum": 0 },
            "shares": { "type": "integer", "minimum": 0 }
          }
        },
        "precision": {
          "type": "object",
          "additionalProperties": false,
          "required": ["impressions"],
          "properties": { "impressions": { "type": "string", "enum": ["exact", "rounded"] } }
        }
      }
    },
    "artifacts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["memes"],
      "properties": {
        "memes": {
          "type": "object",
          "additionalProperties": false,
          "required": ["total"],
          "properties": { "total": { "type": "integer", "minimum": 0 } }
        }
      }
    }
  },
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "date", "publishedAt", "headline", "summary", "work", "xAnalytics", "completedDayResidue", "artifacts"],
  "properties": {
    "schemaVersion": { "const": 2 },
    "date": { "type": "string", "format": "date" },
    "publishedAt": { "type": "string", "format": "date-time" },
    "headline": { "type": "string", "minLength": 3, "maxLength": 120 },
    "summary": { "type": "string", "minLength": 10, "maxLength": 320 },
    "work": { "$ref": "#/$defs/work" },
    "xAnalytics": { "$ref": "#/$defs/xAnalytics" },
    "completedDayResidue": {
      "type": "object",
      "additionalProperties": false,
      "required": ["date", "sealedActivity"],
      "properties": {
        "date": { "type": "string", "format": "date" },
        "sealedActivity": {
          "type": "object",
          "additionalProperties": false,
          "required": ["source", "observedAt", "timezone", "chainId", "tokenAddress", "sealedBuyTransactions", "distinctBuyingAddresses", "latestSnapshotUrl", "coverage"],
          "properties": {
            "source": { "const": "BUY Pulse sealed archive" },
            "observedAt": { "type": "string", "format": "date-time" },
            "timezone": { "const": "UTC" },
            "chainId": { "const": 4663 },
            "tokenAddress": { "const": "0x0e8720b8cd84f95b4b6696adbfa8063c4b8b94f2" },
            "sealedBuyTransactions": { "type": "integer", "minimum": 0 },
            "distinctBuyingAddresses": { "type": "integer", "minimum": 0 },
            "latestSnapshotUrl": { "type": "string", "format": "uri", "pattern": "^https://www\\.hoodbuybutton\\.com/api/v1/snapshots/[0-9a-f]{64}$" },
            "coverage": {
              "type": "object",
              "additionalProperties": false,
              "required": ["state", "expectedBuckets", "storedBuckets", "missingBuckets", "invalidBuckets", "blockGaps", "blockOverlaps", "hashGaps", "walletEvidenceMismatches", "identityStrength", "identityFingerprint", "definitionVersion", "firstSnapshotHash", "lastSnapshotHash"],
              "properties": {
                "state": { "const": "complete" },
                "expectedBuckets": { "const": 288 },
                "storedBuckets": { "const": 288 },
                "missingBuckets": { "const": 0 },
                "invalidBuckets": { "const": 0 },
                "blockGaps": { "const": 0 },
                "blockOverlaps": { "const": 0 },
                "hashGaps": { "const": 0 },
                "walletEvidenceMismatches": { "const": 0 },
                "identityStrength": { "const": "exact" },
                "identityFingerprint": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
                "definitionVersion": { "type": "string", "minLength": 1, "maxLength": 160 },
                "firstSnapshotHash": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
                "lastSnapshotHash": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
              }
            }
          }
        }
      }
    },
    "artifacts": { "$ref": "#/$defs/artifacts" }
  }
}
