{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "id": {
      "type": "string",
      "pattern": "^[0-9]{8}T[0-9]{6}Z$"
    },
    "kind": {
      "enum": [
        "bootstrap",
        "briefing"
      ]
    },
    "as_of": {
      "type": "string",
      "format": "date-time",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    },
    "window_start": {
      "type": "string",
      "format": "date-time",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    },
    "review_due_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
        },
        {
          "type": "null"
        }
      ]
    },
    "previous_id": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[0-9]{8}T[0-9]{6}Z$"
        },
        {
          "type": "null"
        }
      ]
    },
    "summary": {
      "$ref": "#/$defs/claim"
    },
    "checks": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/check"
      },
      "minItems": 2,
      "maxItems": 2
    },
    "entries": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/entry"
      },
      "minItems": 0,
      "maxItems": 12
    },
    "unknowns": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 500
      },
      "minItems": 1,
      "maxItems": 8
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/source"
      },
      "minItems": 0,
      "maxItems": 64
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "method": {
          "enum": [
            "manual",
            "assisted",
            "bootstrap"
          ]
        },
        "tools": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              },
              "version": {
                "anyOf": [
                  {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "name",
              "version"
            ]
          },
          "minItems": 0,
          "maxItems": 12
        },
        "note": {
          "type": "string",
          "minLength": 1,
          "maxLength": 600
        }
      },
      "required": [
        "method",
        "tools",
        "note"
      ]
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "state": {
          "enum": [
            "draft",
            "reviewed",
            "bootstrap"
          ]
        },
        "reviewed_by": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            },
            {
              "type": "null"
            }
          ]
        },
        "reviewed_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
            },
            {
              "type": "null"
            }
          ]
        },
        "content_sha256": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "state",
        "reviewed_by",
        "reviewed_at",
        "content_sha256"
      ]
    }
  },
  "required": [
    "schema_version",
    "id",
    "kind",
    "as_of",
    "window_start",
    "review_due_at",
    "previous_id",
    "summary",
    "checks",
    "entries",
    "unknowns",
    "sources",
    "provenance",
    "review"
  ],
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ishumanitysafe.com/schema/update.schema.json",
  "title": "Humanity Status update v1",
  "$defs": {
    "claim": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "text": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1200
        },
        "basis": {
          "enum": [
            "observation",
            "inference",
            "unknown",
            "site_note"
          ]
        },
        "source_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{0,63}$"
          },
          "uniqueItems": true,
          "maxItems": 8
        }
      },
      "required": [
        "text",
        "basis",
        "source_ids"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "basis": {
                "enum": [
                  "observation",
                  "inference"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "source_ids": {
                "minItems": 1
              }
            }
          }
        }
      ]
    },
    "check": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "enum": [
            "asteroids",
            "space-weather"
          ]
        },
        "status": {
          "enum": [
            "not_assessed",
            "reviewed",
            "source_unavailable"
          ]
        },
        "checked_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
            },
            {
              "type": "null"
            }
          ]
        },
        "valid_until": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
            },
            {
              "type": "null"
            }
          ]
        },
        "finding": {
          "$ref": "#/$defs/claim"
        }
      },
      "required": [
        "id",
        "status",
        "checked_at",
        "valid_until",
        "finding"
      ]
    },
    "entry": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,63}$"
        },
        "section": {
          "enum": [
            "improvement",
            "regression",
            "resolved",
            "known_issue",
            "unknown",
            "site_note"
          ]
        },
        "topic": {
          "enum": [
            "asteroids",
            "space_weather",
            "science",
            "infrastructure",
            "other",
            "site"
          ]
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "event_date": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ]
        },
        "scope": {
          "type": "string",
          "minLength": 1,
          "maxLength": 250
        },
        "summary": {
          "$ref": "#/$defs/claim"
        },
        "why_it_matters": {
          "$ref": "#/$defs/claim"
        },
        "limitations": {
          "$ref": "#/$defs/claim"
        },
        "what_would_change_this": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        }
      },
      "required": [
        "id",
        "section",
        "topic",
        "title",
        "event_date",
        "scope",
        "summary",
        "why_it_matters",
        "limitations",
        "what_would_change_this"
      ]
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,63}$"
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        "publisher": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://",
          "maxLength": 2048
        },
        "type": {
          "enum": [
            "primary",
            "secondary",
            "dataset"
          ]
        },
        "published_on": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ]
        },
        "retrieved_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
        }
      },
      "required": [
        "id",
        "title",
        "publisher",
        "url",
        "type",
        "published_on",
        "retrieved_at"
      ]
    }
  }
}
