{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.hoodbuybutton.com/schemas/bagwork-entry-v1.json",
  "title": "The Buy Button Proof of Bagwork daily entry",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "date",
    "publishedAt",
    "headline",
    "summary",
    "work",
    "xAnalytics",
    "artifacts"
  ],
  "properties": {
    "schemaVersion": { "const": 1 },
    "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": {
      "type": "array",
      "minItems": 1,
      "items": {
        "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": {
            "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 }
          }
        }
      }
    }
  }
}
