{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://yarramate.org/schema/check-result/v1",
  "title": "YarraMate check result",
  "type": "object",
  "additionalProperties": false,
  "required": ["format", "ok", "diagnostics"],
  "properties": {
    "format": {
      "const": "yarramate/check-result/v1"
    },
    "ok": {
      "type": "boolean"
    },
    "diagnostics": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/diagnostic"
      }
    },
    "counted": {
      "$ref": "#/$defs/counted"
    },
    "strict": {
      "$ref": "#/$defs/strict"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "ok": {
            "const": true
          }
        },
        "required": ["ok"]
      },
      "then": {
        "required": ["counted"],
        "properties": {
          "diagnostics": {
            "maxItems": 0
          }
        }
      },
      "else": {
        "properties": {
          "diagnostics": {
            "minItems": 1
          }
        }
      }
    }
  ],
  "$defs": {
    "strict": {
      "type": "object",
      "additionalProperties": false,
      "required": ["observations", "contradicted"],
      "properties": {
        "observations": { "type": "integer", "minimum": 0 },
        "contradicted": { "type": "integer", "minimum": 0 }
      }
    },
    "counted": {
      "type": "object",
      "additionalProperties": false,
      "required": ["documents", "concepts", "relationships", "states"],
      "properties": {
        "documents": { "type": "integer", "minimum": 0 },
        "concepts": { "type": "integer", "minimum": 0 },
        "relationships": { "type": "integer", "minimum": 0 },
        "states": { "type": "integer", "minimum": 0 }
      }
    },
    "diagnostic": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "severity",
        "code",
        "message",
        "path",
        "pointer",
        "line",
        "column"
      ],
      "properties": {
        "severity": {
          "const": "error"
        },
        "code": {
          "type": "string",
          "pattern": "^YM[0-9]{3}$"
        },
        "message": {
          "type": "string",
          "minLength": 1
        },
        "path": {
          "type": "string",
          "minLength": 1
        },
        "pointer": {
          "type": "string",
          "pattern": "^/"
        },
        "line": {
          "type": "integer",
          "minimum": 1
        },
        "column": {
          "type": "integer",
          "minimum": 1
        },
        "subjects": {
          "description": "Subjects this diagnostic is about, most relevant first, when its pointer names one. Absent when the diagnostic belongs to no subject: a parse failure, a whole-document schema violation, a manifest, or a projection's own definition.",
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  }
}
