{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://slopvac.github.io/slopvac/schemas/v3/genre.schema.json",
  "title": "slopvac v3 genre",
  "description": "A document purpose class as data. A genre may extend other genres, so a content type such as how-to extends a broader genre. Detection signals score a document, and the genre with the highest score at or above its threshold wins. A config [[genres]] block or front matter overrides detection. Semantics are specified in docs/contract/plugins.md. Owner: slopvac-8l4.2.4.",
  "type": "object",
  "properties": {
    "schema_version": {
      "$ref": "common.schema.json#/$defs/SchemaVersion"
    },
    "id": {
      "$ref": "rule.schema.json#/$defs/Genre"
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "surfaces": {
      "description": "Typical documents, for people.",
      "type": "string",
      "minLength": 1
    },
    "extends": {
      "description": "Genres this one builds on, lowest first. Their settings apply below this genre's.",
      "type": "array",
      "items": {
        "$ref": "config.schema.json#/$defs/Ref"
      },
      "uniqueItems": true
    },
    "profile": {
      "description": "Strictness profile that the genre selects when no other layer sets one.",
      "enum": [
        "strict",
        "normal",
        "relaxed"
      ]
    },
    "detect": {
      "$ref": "#/$defs/Detect"
    },
    "styles": {
      "description": "Styles the genre activates, in order.",
      "type": "array",
      "items": {
        "$ref": "config.schema.json#/$defs/Ref"
      }
    },
    "contexts": {
      "description": "Context tags that every document of this genre carries, whole document, at confidence 1. A genre that extends this one inherits them. Use it for a context that only a declaration should set, such as security, which no vocabulary signal may infer.",
      "type": "array",
      "items": {
        "$ref": "common.schema.json#/$defs/ContextTag"
      },
      "uniqueItems": true
    },
    "categories": {
      "type": "object",
      "propertyNames": {
        "$ref": "config.schema.json#/$defs/RuleKey"
      },
      "additionalProperties": {
        "$ref": "config.schema.json#/$defs/CategorySettings"
      },
      "description": "Levels keyed by category name. Keys are data, so the x- convention does not apply."
    },
    "rules": {
      "type": "object",
      "propertyNames": {
        "$ref": "config.schema.json#/$defs/RuleKey"
      },
      "additionalProperties": {
        "$ref": "config.schema.json#/$defs/RuleLevel"
      },
      "description": "Levels keyed by rule name. Keys are data, so the x- convention does not apply."
    }
  },
  "required": [
    "schema_version",
    "id"
  ],
  "patternProperties": {
    "^x-": {}
  },
  "additionalProperties": false,
  "$defs": {
    "Detect": {
      "description": "Signals that suggest the genre. A document scores the sum of the weights of the signals that match. The genre is a candidate when the score reaches min_score.",
      "type": "object",
      "properties": {
        "min_score": {
          "type": "number",
          "exclusiveMinimum": 0,
          "default": 1
        },
        "signals": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/Signal"
          }
        }
      },
      "required": [
        "signals"
      ],
      "patternProperties": {
        "^x-": {}
      },
      "additionalProperties": false
    },
    "Signal": {
      "description": "One detection signal. kind selects which other field applies: path takes a glob over the file path, front-matter takes a key and an optional value, heading takes a PCRE2 pattern over heading text, and text takes a PCRE2 pattern over the body.",
      "type": "object",
      "properties": {
        "kind": {
          "enum": [
            "path",
            "front-matter",
            "heading",
            "text"
          ]
        },
        "weight": {
          "type": "number",
          "exclusiveMinimum": 0,
          "default": 1
        },
        "glob": {
          "type": "string",
          "minLength": 1
        },
        "key": {
          "type": "string",
          "minLength": 1
        },
        "equals": {
          "type": [
            "string",
            "number",
            "boolean"
          ]
        },
        "pattern": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "kind"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "path"
              }
            }
          },
          "then": {
            "required": [
              "glob"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "key"
                  ]
                },
                {
                  "required": [
                    "equals"
                  ]
                },
                {
                  "required": [
                    "pattern"
                  ]
                }
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "front-matter"
              }
            }
          },
          "then": {
            "required": [
              "key"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "glob"
                  ]
                },
                {
                  "required": [
                    "pattern"
                  ]
                }
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "enum": [
                  "heading",
                  "text"
                ]
              }
            }
          },
          "then": {
            "required": [
              "pattern"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "glob"
                  ]
                },
                {
                  "required": [
                    "key"
                  ]
                },
                {
                  "required": [
                    "equals"
                  ]
                }
              ]
            }
          }
        }
      ],
      "patternProperties": {
        "^x-": {}
      },
      "additionalProperties": false
    }
  }
}
