{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "github-watermark.v1",
  "title": "OMS GitHub sync watermark",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "repository", "generation", "completed_at", "observation_count", "batch_sha256", "streams", "inventory"],
  "properties": {
    "schema_version": { "const": 1 },
    "repository": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{0,38}/[a-z0-9._-]{1,100}$" },
    "generation": { "type": "integer", "minimum": 0 },
    "completed_at": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$" },
    "observation_count": { "type": "integer", "minimum": 0 },
    "batch_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "inventory": {
      "type": "array",
      "maxItems": 50000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["observation_key", "kind", "source_id_sha256", "payload_sha256", "presence_generation"],
        "properties": {
          "observation_key": { "type": "string", "pattern": "^github-obs-[a-f0-9]{48}$" },
          "kind": { "type": "string", "enum": ["issue", "comment", "label", "branch", "pull_request", "review", "check"] },
          "source_id_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "payload_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "presence_generation": { "type": "integer", "minimum": 0 }
        }
      }
    },
    "streams": {
      "type": "object",
      "additionalProperties": false,
      "required": ["issues", "branches", "pull_requests"],
      "properties": {
        "issues": {
          "type": "object",
          "additionalProperties": false,
          "required": ["page_count", "terminal_cursor_sha256"],
          "properties": {
            "page_count": { "type": "integer", "minimum": 1 },
            "terminal_cursor_sha256": { "type": ["string", "null"], "pattern": "^[a-f0-9]{64}$" }
          }
        },
        "branches": {
          "type": "object",
          "additionalProperties": false,
          "required": ["page_count", "terminal_cursor_sha256"],
          "properties": {
            "page_count": { "type": "integer", "minimum": 1 },
            "terminal_cursor_sha256": { "type": ["string", "null"], "pattern": "^[a-f0-9]{64}$" }
          }
        },
        "pull_requests": {
          "type": "object",
          "additionalProperties": false,
          "required": ["page_count", "terminal_cursor_sha256"],
          "properties": {
            "page_count": { "type": "integer", "minimum": 1 },
            "terminal_cursor_sha256": { "type": ["string", "null"], "pattern": "^[a-f0-9]{64}$" }
          }
        }
      }
    }
  }
}
