{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "RequiredPermissionsPageViewModel",
  "type": "object",
  "required": ["tenant", "overview", "permissions", "filters"],
  "properties": {
    "tenant": {
      "type": "object",
      "required": ["id", "external_id", "name"],
      "properties": {
        "id": {"type": "integer"},
        "external_id": {"type": "string"},
        "name": {"type": "string"}
      }
    },
    "overview": {
      "type": "object",
      "required": ["overall", "counts", "feature_impacts"],
      "properties": {
        "overall": {"type": "string", "enum": ["ready", "needs_attention", "blocked", "running"]},
        "counts": {
          "type": "object",
          "required": ["missing_application", "missing_delegated", "present", "error"],
          "properties": {
            "missing_application": {"type": "integer", "minimum": 0},
            "missing_delegated": {"type": "integer", "minimum": 0},
            "present": {"type": "integer", "minimum": 0},
            "error": {"type": "integer", "minimum": 0}
          }
        },
        "feature_impacts": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["feature", "missing", "required_application", "required_delegated", "blocked"],
            "properties": {
              "feature": {"type": "string"},
              "missing": {"type": "integer", "minimum": 0},
              "required_application": {"type": "integer", "minimum": 0},
              "required_delegated": {"type": "integer", "minimum": 0},
              "blocked": {"type": "boolean"}
            }
          }
        }
      }
    },
    "permissions": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["key", "type", "features", "status"],
        "properties": {
          "key": {"type": "string"},
          "type": {"type": "string", "enum": ["application", "delegated"]},
          "description": {"type": ["string", "null"]},
          "features": {"type": "array", "items": {"type": "string"}},
          "status": {"type": "string", "enum": ["granted", "missing", "error"]},
          "details": {"type": ["object", "null"], "additionalProperties": true}
        }
      }
    },
    "filters": {
      "type": "object",
      "required": ["status", "type", "features", "search"],
      "properties": {
        "status": {"type": "string", "enum": ["missing", "present", "all"]},
        "type": {"type": "string", "enum": ["application", "delegated", "all"]},
        "features": {"type": "array", "items": {"type": "string"}},
        "search": {"type": "string"}
      }
    }
  }
}
