{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Viewrule guide frontmatter v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "version", "id", "kind", "title", "summary"],
  "properties": {
    "id": {
      "type": "string",
      "minLength": 1
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "summary": {
      "type": "string",
      "minLength": 1
    },
    "schemaVersion": {
      "const": 1
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "kind": {
      "enum": ["index", "authoring", "template", "pattern", "evidence"]
    },
    "applicability": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true,
      "minItems": 1
    },
    "related": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "rules": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true,
      "minItems": 1
    },
    "evidenceType": {
      "enum": ["experimental", "practitioner", "standard", "convention"]
    },
    "citation": {
      "type": "string",
      "minLength": 1
    },
    "url": {
      "type": "string",
      "pattern": "^https://"
    },
    "reviewed": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "examples": {
      "type": "array",
      "minItems": 2,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "quality", "href", "task", "consequence"],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "href": {
            "type": "string",
            "minLength": 1
          },
          "task": {
            "type": "string",
            "minLength": 1
          },
          "consequence": {
            "type": "string",
            "minLength": 1
          },
          "quality": {
            "enum": ["good", "bad"]
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "const": "pattern"
          }
        }
      },
      "then": {
        "required": ["applicability", "related", "rules", "sources", "examples"]
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "evidence"
          }
        }
      },
      "then": {
        "required": ["evidenceType", "citation", "url", "reviewed"]
      }
    }
  ]
}
