{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://atlasarc.io/schemas/repository-views-v1.schema.json",
  "title": "AtlasArc.io repository shared investigation views",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "schemaVersion", "presets"],
  "properties": {
    "$schema": { "const": "https://atlasarc.io/schemas/repository-views-v1.schema.json" },
    "schemaVersion": { "const": 1 },
    "presets": { "type": "array", "items": { "$ref": "#/$defs/preset" } }
  },
  "$defs": {
    "preset": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "description"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
        "name": { "type": "string", "minLength": 1, "pattern": "\\S" },
        "description": { "type": "string", "minLength": 1, "pattern": "\\S" },
        "view": { "$ref": "#/$defs/view" }
      }
    },
    "view": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "lens": { "enum": ["topology", "matrix", "subsystems", "hotspots", "composition"] },
        "anchor": { "$ref": "#/$defs/anchor" },
        "filters": { "$ref": "#/$defs/filters" },
        "hierarchy": { "$ref": "#/$defs/hierarchy" },
        "viewExclusions": { "type": "array", "items": { "$ref": "#/$defs/selector" } },
        "presentation": { "$ref": "#/$defs/presentation" }
      }
    },
    "anchor": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "mode": { "const": "normal" },
            "subject": { "type": "null" },
            "neighbourMesh": { "type": "boolean" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["mode", "subject"],
          "properties": {
            "mode": { "enum": ["root", "pinned"] },
            "subject": { "$ref": "#/$defs/subject" },
            "neighbourMesh": { "type": "boolean" }
          }
        }
      ]
    },
    "subject": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "architectureUnit"],
          "properties": {
            "kind": { "const": "jvm-module" },
            "architectureUnit": { "type": "string", "minLength": 1, "pattern": "\\S" },
            "module": { "type": "null" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "architectureUnit"],
          "properties": {
            "kind": { "const": "jvm-package" },
            "architectureUnit": { "type": "string", "minLength": 1, "pattern": "\\S" },
            "module": { "type": ["string", "null"], "minLength": 1 }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "architectureUnit"],
          "properties": {
            "kind": { "const": "typescript-source-folder" },
            "architectureUnit": { "type": "string", "minLength": 1, "pattern": "\\S" },
            "module": { "type": "null" }
          }
        }
      ]
    },
    "filters": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "minimumReferences": { "type": "integer", "minimum": 0 },
        "maximumReferences": { "type": "integer", "minimum": 0 },
        "minimumFanOut": { "type": "integer", "minimum": 0 },
        "maximumFanOut": { "type": "integer", "minimum": 0 },
        "minimumFanIn": { "type": "integer", "minimum": 0 },
        "maximumFanIn": { "type": "integer", "minimum": 0 },
        "hideIsolated": { "type": "boolean" },
        "onlyCycles": { "type": "boolean" },
        "cycleDetail": { "enum": ["full", "all-cycles", "architecture-and-folders", "architecture-only"] },
        "mutePinnedCycles": { "type": "boolean" }
      }
    },
    "hierarchy": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "compactFolders": { "type": "boolean" },
        "compactDepth": { "type": "integer", "minimum": 1 }
      }
    },
    "selector": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "pattern"],
          "properties": {
            "kind": { "const": "jvm-package-pattern" },
            "pattern": { "type": "string", "minLength": 1 },
            "module": { "type": ["string", "null"], "minLength": 1 }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "pattern"],
          "properties": {
            "kind": { "const": "typescript-source-folder-pattern" },
            "pattern": { "type": "string", "minLength": 1 },
            "module": { "type": "null" }
          }
        }
      ]
    },
    "presentation": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "heatmapMetric": {
          "enum": [
            "instability", "abstractness", "distance", "relativeVisibility", "fanOut", "fanIn",
            "loc", "classCount", "cyclomaticMax", "cyclomaticAverage", "cognitiveMax",
            "cognitiveAverage", "lineCoverage", "branchCoverage", null
          ]
        },
        "heatmapUsesSubsystemRollup": { "type": "boolean" },
        "hotspots": { "oneOf": [{ "$ref": "#/$defs/hotspotsPresentation" }, { "type": "null" }] },
        "subsystemView": { "enum": ["boundary-risk", "complexity-load", "visibility-surface", "internal-tangles", null] },
        "compositionDepth": { "enum": ["direct", "adaptive", "full", null] }
      }
    },
    "hotspotsPresentation": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["renderer", "item", "scope", "mapPreset"],
          "properties": {
            "renderer": { "const": "map" },
            "item": { "const": "packages" },
            "scope": { "enum": ["direct", "recursive"] },
            "mapPreset": { "enum": ["coupling", "complexity", "god-classes", "visibility", "zone-map", "coverage-risk"] }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["renderer", "item", "scope", "mapPreset"],
          "properties": {
            "renderer": { "const": "map" },
            "item": { "const": "classes" },
            "scope": { "enum": ["direct", "recursive"] },
            "mapPreset": { "enum": ["coupling", "complexity", "god-classes", "visibility"] }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["renderer", "item", "scope", "mapPreset", "depthMetric", "depthDirection", "routes"],
          "properties": {
            "renderer": { "const": "galaxy" },
            "item": { "const": "packages" },
            "scope": { "enum": ["direct", "recursive"] },
            "mapPreset": { "enum": ["coupling", "complexity", "god-classes", "visibility", "zone-map", "coverage-risk"] },
            "depthMetric": {
              "enum": [
                "fanOut", "fanIn", "instability", "abstractness", "distance", "relativeVisibility",
                "cyclomaticMax", "cognitiveMax", "classCount", "loc", "lineCoverage", "branchCoverage"
              ]
            },
            "depthDirection": { "enum": ["high-forward", "low-forward"] },
            "routes": { "type": "boolean" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["renderer", "item", "scope", "mapPreset", "depthMetric", "depthDirection"],
          "properties": {
            "renderer": { "const": "galaxy" },
            "item": { "const": "classes" },
            "scope": { "enum": ["direct", "recursive"] },
            "mapPreset": { "enum": ["coupling", "complexity", "god-classes", "visibility"] },
            "depthMetric": { "enum": ["fanOut", "fanIn", "cyclomaticMax", "cognitiveMax", "methodCount", "loc"] },
            "depthDirection": { "enum": ["high-forward", "low-forward"] }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["renderer", "item", "scope", "galaxyPreset", "routes"],
          "properties": {
            "renderer": { "const": "galaxy" },
            "item": { "const": "packages" },
            "scope": { "enum": ["direct", "recursive"] },
            "galaxyPreset": { "enum": ["risk-horizon", "maintenance-abyss", "coupling-galaxy", "complexity-frontier"] },
            "routes": { "type": "boolean" }
          }
        }
      ]
    }
  }
}
