{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/federalaccountability/accountability-indicators/blob/main/schemas/kai-catalog.schema.json",
  "title": "CFA Key Accountability Indicators catalog",
  "type": "object",
  "required": [
    "name",
    "version",
    "updated",
    "evidence_tiers",
    "themes",
    "indicators"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "updated": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "evidence_tiers": {
      "type": "object",
      "required": [
        "P1",
        "P2",
        "P3",
        "F"
      ],
      "additionalProperties": {
        "type": "string"
      }
    },
    "themes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/theme"
      }
    },
    "indicators": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/indicator"
      }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "theme": {
      "type": "object",
      "required": [
        "id",
        "name",
        "csf_function",
        "ig_fisma_domain",
        "cr26_ksi_themes",
        "fiscam",
        "cfa_scoring_area"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^KAI-[A-Z]{3}$"
        },
        "name": {
          "type": "string"
        },
        "csf_function": {
          "type": [
            "string",
            "null"
          ]
        },
        "ig_fisma_domain": {
          "type": [
            "string",
            "null"
          ]
        },
        "cr26_ksi_themes": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^KSI-[A-Z]{3}$"
          }
        },
        "fiscam": {
          "type": [
            "string",
            "null"
          ]
        },
        "cfa_scoring_area": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "authority": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "tracker_id"
          ],
          "properties": {
            "tracker_id": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)+$"
            },
            "note": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "citation"
          ],
          "properties": {
            "citation": {
              "type": "string",
              "minLength": 1
            },
            "note": {
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "indicator": {
      "type": "object",
      "required": [
        "id",
        "theme",
        "name",
        "authority",
        "evidence",
        "validation",
        "crosswalk",
        "criticality",
        "result_rule",
        "ig_subscore",
        "status"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^KAI-[A-Z]{3}-[A-Z0-9]{3}$"
        },
        "theme": {
          "type": "string",
          "pattern": "^KAI-[A-Z]{3}$"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "authority": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/authority"
          }
        },
        "evidence": {
          "type": "object",
          "required": [
            "tiers",
            "description",
            "expected_access"
          ],
          "properties": {
            "tiers": {
              "type": "array",
              "minItems": 1,
              "items": {
                "enum": [
                  "P1",
                  "P2",
                  "P3",
                  "F"
                ]
              }
            },
            "description": {
              "type": "string"
            },
            "expected_access": {
              "enum": [
                "public",
                "foia_releasable",
                "likely_withheld"
              ]
            }
          },
          "additionalProperties": false
        },
        "validation": {
          "type": "object",
          "required": [
            "methods",
            "cycle"
          ],
          "properties": {
            "methods": {
              "type": "array",
              "minItems": 1,
              "items": {
                "enum": [
                  "machine",
                  "analyst"
                ]
              }
            },
            "cycle": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "additionalProperties": false,
          "if": {
            "properties": {
              "methods": {
                "contains": {
                  "const": "machine"
                }
              }
            }
          },
          "then": {
            "properties": {
              "cycle": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        "crosswalk": {
          "type": "object",
          "required": [
            "cr26_ksi",
            "fiscam"
          ],
          "properties": {
            "cr26_ksi": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^KSI-[A-Z]{3}-[A-Z0-9]{3}$"
              }
            },
            "fiscam": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "additionalProperties": false
        },
        "criticality": {
          "enum": [
            "fatal",
            "major",
            "minor"
          ],
          "description": "How much a failure weighs. A fatal failure caps the agency's grade at material. Every draft starts at major until an analyst sets it."
        },
        "result_rule": {
          "enum": [
            "any_failure",
            "share",
            "auditor"
          ],
          "description": "How the result is decided across the cases the requirement covers. any_failure: one piece of contrary evidence makes it not met. share: partly met in proportion to the cases that pass. auditor: the result follows the conclusion of the agency's auditors: the inspector general, GAO or the financial statement auditor."
        },
        "ig_subscore": {
          "type": "boolean"
        },
        "status": {
          "enum": [
            "draft",
            "active",
            "retired"
          ]
        }
      },
      "additionalProperties": false
    }
  }
}
