{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://sanctumshield.com/schemas/authority-record-1.0.schema.json",
  "title": "SanctumShield approval change record",
  "description": "One export file.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "_about": {
      "type": "string",
      "description": "A plain sentence a person can read: what this file is and where its fields are documented."
    },
    "schema_version": {
      "type": "string",
      "const": "1.0"
    },
    "schema": {
      "type": "string",
      "description": "Where this JSON Schema is published."
    },
    "organization": {
      "type": "object",
      "description": "The organization the record belongs to.",
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": [
            "string",
            "null"
          ],
          "description": "The organization's name as it gave it."
        },
        "name_status": {
          "type": "string",
          "enum": [
            "unknown",
            "not_recorded",
            "not_applicable"
          ],
          "description": "Present when name is null: why there is no value."
        }
      },
      "required": [
        "name"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "name": {
                "const": null
              }
            },
            "required": [
              "name"
            ]
          },
          "then": {
            "required": [
              "name_status"
            ]
          }
        }
      ]
    },
    "snapshot_as_of": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,3})?)?(Z|[+-]\\d{2}:\\d{2})?)?$",
      "description": "The moment the file was produced (ISO 8601). The file says nothing about anything after this moment."
    },
    "attestation_basis": {
      "type": "string",
      "const": "self_reported",
      "description": "Every entry was stated by the organization."
    },
    "freshness_statement": {
      "type": "string",
      "minLength": 40,
      "description": "The freshness boundary in words: the file covers only events recorded up to snapshot_as_of, was stated by the organization, and cannot establish that no later change occurred."
    },
    "agents": {
      "type": "array",
      "description": "Every agent the record speaks about.",
      "items": {
        "type": "object",
        "description": "One agent.",
        "additionalProperties": false,
        "properties": {
          "agent_id": {
            "type": "string",
            "pattern": "^agent-[a-z0-9-]+$",
            "description": "Stable across re-runs and re-imports."
          },
          "actor": {
            "type": "string",
            "minLength": 1,
            "description": "The agent's name."
          },
          "in_inventory": {
            "type": "boolean",
            "description": "False when the agent has history but is no longer listed in the organization's inventory."
          },
          "change_review": {
            "type": "object",
            "description": "The answer, in this review, to: has anything about this agent changed since the last review? A person who answered Not sure is recorded as answer null with answer_status unknown and the moment they answered. It is never recorded as an event.",
            "additionalProperties": false,
            "properties": {
              "answer": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "no_change or changed.",
                "enum": [
                  "no_change",
                  "changed",
                  null
                ]
              },
              "answer_status": {
                "type": "string",
                "enum": [
                  "unknown",
                  "not_recorded",
                  "not_applicable"
                ],
                "description": "Present when answer is null: why there is no value."
              },
              "answered_at": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "When the answer was given (ISO 8601).",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,3})?)?(Z|[+-]\\d{2}:\\d{2})?)?$"
              },
              "answered_at_status": {
                "type": "string",
                "enum": [
                  "unknown",
                  "not_recorded",
                  "not_applicable"
                ],
                "description": "Present when answered_at is null: why there is no value."
              }
            },
            "required": [
              "answer",
              "answered_at"
            ],
            "allOf": [
              {
                "if": {
                  "properties": {
                    "answer": {
                      "const": null
                    }
                  },
                  "required": [
                    "answer"
                  ]
                },
                "then": {
                  "required": [
                    "answer_status"
                  ]
                }
              },
              {
                "if": {
                  "properties": {
                    "answered_at": {
                      "const": null
                    }
                  },
                  "required": [
                    "answered_at"
                  ]
                },
                "then": {
                  "required": [
                    "answered_at_status"
                  ]
                }
              }
            ]
          },
          "issuer": {
            "type": [
              "string",
              "null"
            ],
            "description": "Who holds the authority to approve this agent: the agent's recorded owner or approver. A name or a role."
          },
          "issuer_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when issuer is null: why there is no value."
          },
          "operation": {
            "type": [
              "string",
              "null"
            ],
            "description": "What the agent is for, as the organization recorded it."
          },
          "operation_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when operation is null: why there is no value."
          },
          "scope": {
            "type": [
              "string",
              "null"
            ],
            "description": "What the agent can reach or do, in plain words, as the organization recorded it."
          },
          "scope_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when scope is null: why there is no value."
          }
        },
        "required": [
          "agent_id",
          "actor",
          "in_inventory",
          "change_review",
          "issuer",
          "operation",
          "scope"
        ],
        "allOf": [
          {
            "if": {
              "properties": {
                "issuer": {
                  "const": null
                }
              },
              "required": [
                "issuer"
              ]
            },
            "then": {
              "required": [
                "issuer_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "operation": {
                  "const": null
                }
              },
              "required": [
                "operation"
              ]
            },
            "then": {
              "required": [
                "operation_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "scope": {
                  "const": null
                }
              },
              "required": [
                "scope"
              ]
            },
            "then": {
              "required": [
                "scope_status"
              ]
            }
          }
        ]
      }
    },
    "events": {
      "type": "array",
      "description": "Every recorded event, oldest entry first within each agent. Events are never edited or removed; a correction is a later event.",
      "items": {
        "type": "object",
        "description": "One event.",
        "additionalProperties": false,
        "properties": {
          "event_id": {
            "type": "string",
            "pattern": "^evt-[0-9a-f]{16}$",
            "description": "Stable across re-runs and re-imports."
          },
          "agent_id": {
            "type": "string",
            "pattern": "^agent-[a-z0-9-]+$"
          },
          "actor": {
            "type": "string",
            "minLength": 1,
            "description": "The agent's name."
          },
          "event_type": {
            "type": [
              "string",
              "null"
            ],
            "description": "What happened. Null with event_type_status unknown for a change whose direction (wider or narrower) was not recorded.",
            "enum": [
              "granted",
              "scope_expanded",
              "scope_narrowed",
              "superseded",
              "withdrawn",
              "stop_tested",
              null
            ]
          },
          "event_type_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when event_type is null: why there is no value."
          },
          "issuer": {
            "type": [
              "string",
              "null"
            ],
            "description": "Who holds the authority to approve this agent: the agent's recorded owner or approver. A name or a role."
          },
          "issuer_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when issuer is null: why there is no value."
          },
          "decided_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "Who made this change. A name or a role; a role alone is accepted."
          },
          "decided_by_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when decided_by is null: why there is no value."
          },
          "operation": {
            "type": [
              "string",
              "null"
            ],
            "description": "What the agent is for, as the organization recorded it."
          },
          "operation_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when operation is null: why there is no value."
          },
          "scope": {
            "type": [
              "string",
              "null"
            ],
            "description": "What the agent can reach or do, in plain words, as the organization recorded it."
          },
          "scope_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when scope is null: why there is no value."
          },
          "supersedes": {
            "type": [
              "string",
              "null"
            ],
            "description": "For a superseded event: the event_id of the approval it replaces.",
            "pattern": "^evt-[0-9a-f]{16}$"
          },
          "supersedes_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when supersedes is null: why there is no value."
          },
          "effective_from": {
            "type": [
              "string",
              "null"
            ],
            "description": "When the change took effect (ISO 8601; may be a date only).",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,3})?)?(Z|[+-]\\d{2}:\\d{2})?)?$"
          },
          "effective_from_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when effective_from is null: why there is no value."
          },
          "effective_to": {
            "type": [
              "string",
              "null"
            ],
            "description": "For an approval that a later event replaced or withdrew: when it stopped applying.",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,3})?)?(Z|[+-]\\d{2}:\\d{2})?)?$"
          },
          "effective_to_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when effective_to is null: why there is no value."
          },
          "recorded_at": {
            "type": [
              "string",
              "null"
            ],
            "description": "When a review captured the event (ISO 8601). Kept apart from effective_from.",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,3})?)?(Z|[+-]\\d{2}:\\d{2})?)?$"
          },
          "recorded_at_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when recorded_at is null: why there is no value."
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Why, in the organization's words."
          },
          "reason_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when reason is null: why there is no value."
          },
          "evidence": {
            "type": [
              "string",
              "null"
            ],
            "description": "A reference the organization provides (for example a ticket number). Never stored content."
          },
          "evidence_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when evidence is null: why there is no value."
          },
          "assessment_run_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "The review the event was recorded in."
          },
          "assessment_run_id_status": {
            "type": "string",
            "enum": [
              "unknown",
              "not_recorded",
              "not_applicable"
            ],
            "description": "Present when assessment_run_id is null: why there is no value."
          }
        },
        "required": [
          "event_id",
          "agent_id",
          "actor",
          "event_type",
          "issuer",
          "decided_by",
          "operation",
          "scope",
          "supersedes",
          "effective_from",
          "effective_to",
          "recorded_at",
          "reason",
          "evidence",
          "assessment_run_id"
        ],
        "allOf": [
          {
            "if": {
              "properties": {
                "event_type": {
                  "const": null
                }
              },
              "required": [
                "event_type"
              ]
            },
            "then": {
              "required": [
                "event_type_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "issuer": {
                  "const": null
                }
              },
              "required": [
                "issuer"
              ]
            },
            "then": {
              "required": [
                "issuer_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "decided_by": {
                  "const": null
                }
              },
              "required": [
                "decided_by"
              ]
            },
            "then": {
              "required": [
                "decided_by_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "operation": {
                  "const": null
                }
              },
              "required": [
                "operation"
              ]
            },
            "then": {
              "required": [
                "operation_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "scope": {
                  "const": null
                }
              },
              "required": [
                "scope"
              ]
            },
            "then": {
              "required": [
                "scope_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "supersedes": {
                  "const": null
                }
              },
              "required": [
                "supersedes"
              ]
            },
            "then": {
              "required": [
                "supersedes_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "effective_from": {
                  "const": null
                }
              },
              "required": [
                "effective_from"
              ]
            },
            "then": {
              "required": [
                "effective_from_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "effective_to": {
                  "const": null
                }
              },
              "required": [
                "effective_to"
              ]
            },
            "then": {
              "required": [
                "effective_to_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "recorded_at": {
                  "const": null
                }
              },
              "required": [
                "recorded_at"
              ]
            },
            "then": {
              "required": [
                "recorded_at_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "reason": {
                  "const": null
                }
              },
              "required": [
                "reason"
              ]
            },
            "then": {
              "required": [
                "reason_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "evidence": {
                  "const": null
                }
              },
              "required": [
                "evidence"
              ]
            },
            "then": {
              "required": [
                "evidence_status"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "assessment_run_id": {
                  "const": null
                }
              },
              "required": [
                "assessment_run_id"
              ]
            },
            "then": {
              "required": [
                "assessment_run_id_status"
              ]
            }
          }
        ]
      }
    },
    "last_assessment_at": {
      "type": [
        "string",
        "null"
      ],
      "description": "The date of the review this file was produced from.",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "last_assessment_at_status": {
      "type": "string",
      "enum": [
        "unknown",
        "not_recorded",
        "not_applicable"
      ],
      "description": "Present when last_assessment_at is null: why there is no value."
    },
    "next_review_due": {
      "type": [
        "string",
        "null"
      ],
      "description": "The date the organization has set for its next review.",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "next_review_due_status": {
      "type": "string",
      "enum": [
        "unknown",
        "not_recorded",
        "not_applicable"
      ],
      "description": "Present when next_review_due is null: why there is no value."
    }
  },
  "required": [
    "_about",
    "schema_version",
    "schema",
    "organization",
    "snapshot_as_of",
    "attestation_basis",
    "freshness_statement",
    "agents",
    "events",
    "last_assessment_at",
    "next_review_due"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "last_assessment_at": {
            "const": null
          }
        },
        "required": [
          "last_assessment_at"
        ]
      },
      "then": {
        "required": [
          "last_assessment_at_status"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "next_review_due": {
            "const": null
          }
        },
        "required": [
          "next_review_due"
        ]
      },
      "then": {
        "required": [
          "next_review_due_status"
        ]
      }
    }
  ]
}
