{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://qazpolit.com/contracts/qazpolit-source-snapshot-queue-v1.schema.json",
  "title": "Qazpolit source snapshot queue",
  "description": "Read-only source capture candidates for QazPipe/QazLake. The payload never authorizes source trust labels, legal-use labels, statements, relationships or public profile publication changes.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "generated_at",
    "read_only",
    "automatic_mutation",
    "policy",
    "scope",
    "source",
    "summary",
    "items"
  ],
  "properties": {
    "schema": {"const": "qazpolit.source-snapshot-queue.v1"},
    "generated_at": {"type": "string", "format": "date-time"},
    "read_only": {"const": true},
    "automatic_mutation": {"const": false},
    "policy": {"type": "string", "minLength": 1},
    "scope": {"const": "priority cited sources without immutable SourceSnapshot records"},
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "project",
        "quality_endpoint",
        "content_jobs_endpoint",
        "platform_schema"
      ],
      "properties": {
        "project": {"const": "qazpolit"},
        "quality_endpoint": {"const": "https://qazpolit.com/api/data-quality"},
        "content_jobs_endpoint": {"const": "https://qazpolit.com/api/content-enrichment-jobs"},
        "platform_schema": {"const": "qazstack.source-snapshot-candidate.v1"}
      }
    },
    "filters": {
      "type": "object",
      "additionalProperties": false,
      "required": ["access_hint", "source_host"],
      "properties": {
        "access_hint": {
          "type": ["string", "null"],
          "enum": [
            "existing_metadata",
            "platform_archive_required",
            "archive_lookup_required",
            "priority_public_document",
            "bounded_public_fetch",
            null
          ]
        },
        "source_host": {"type": ["string", "null"]}
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "limit",
        "items",
        "skipped_without_url",
        "priority_counts",
        "capture_modes",
        "access_hints"
      ],
      "properties": {
        "limit": {"type": "integer", "minimum": 1, "maximum": 5000},
        "items": {"type": "integer", "minimum": 0},
        "skipped_without_url": {"type": "integer", "minimum": 0},
        "priority_counts": {
          "type": "object",
          "additionalProperties": {"type": "integer", "minimum": 0},
          "propertyNames": {"enum": ["P0", "P1", "P2", "P3", "P4"]}
        },
        "capture_modes": {
          "type": "object",
          "additionalProperties": {"type": "integer", "minimum": 0},
          "propertyNames": {"enum": ["materialize_existing_metadata", "fetch_hash_and_archive"]}
        },
        "access_hints": {
          "type": "object",
          "additionalProperties": {"type": "integer", "minimum": 0},
          "propertyNames": {
            "enum": [
              "existing_metadata",
              "platform_archive_required",
              "archive_lookup_required",
              "priority_public_document",
              "bounded_public_fetch"
            ]
          }
        }
      }
    },
    "items": {
      "type": "array",
      "items": {"$ref": "#/$defs/source_snapshot_candidate"}
    }
  },
  "$defs": {
    "source_snapshot_candidate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "schema",
        "priority",
        "source_id",
        "url",
        "source_host",
        "title",
        "publisher",
        "source_type",
        "language",
        "published_date",
        "existing_archived_url",
        "existing_content_checksum",
        "has_archive_metadata",
        "has_checksum_metadata",
        "capture_mode",
        "access_hint",
        "recommended_collector",
        "recommended_storage",
        "recommended_recovery_path",
        "next_action",
        "stop_condition",
        "allowed_actions",
        "automation_boundary",
        "publication_effect"
      ],
      "properties": {
        "id": {"type": "string", "pattern": "^snapshot:[a-f0-9]{16}$"},
        "schema": {"const": "qazstack.source-snapshot-candidate.v1"},
        "priority": {"enum": ["P0", "P1", "P2", "P3", "P4"]},
        "source_id": {"type": "integer", "minimum": 1},
        "url": {"type": "string", "format": "uri"},
        "source_host": {"type": ["string", "null"]},
        "title": {"type": "string"},
        "publisher": {"type": ["string", "null"]},
        "source_type": {"type": ["string", "null"]},
        "language": {"type": ["string", "null"]},
        "published_date": {"type": ["string", "null"]},
        "existing_archived_url": {"type": ["string", "null"], "format": "uri"},
        "existing_content_checksum": {"type": ["string", "null"]},
        "has_archive_metadata": {"type": "boolean"},
        "has_checksum_metadata": {"type": "boolean"},
        "capture_mode": {"enum": ["materialize_existing_metadata", "fetch_hash_and_archive"]},
        "access_hint": {
          "enum": [
            "existing_metadata",
            "platform_archive_required",
            "archive_lookup_required",
            "priority_public_document",
            "bounded_public_fetch"
          ]
        },
        "recommended_collector": {"const": "qazpipe"},
        "recommended_storage": {"const": "qazlake"},
        "recommended_recovery_path": {"type": "string", "minLength": 1},
        "next_action": {"type": "string", "minLength": 1},
        "stop_condition": {"type": "string", "minLength": 1},
        "allowed_actions": {
          "type": "array",
          "items": {
            "enum": [
              "capture_snapshot",
              "attach_checksum",
              "attach_archive_url",
              "skip_with_reason"
            ]
          },
          "uniqueItems": true,
          "minItems": 4
        },
        "automation_boundary": {"type": "string", "minLength": 1},
        "publication_effect": {"const": "none"}
      }
    }
  }
}
