{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pflichten-pfad.de/regelwerk/schema.json",
  "title": "Regelwerk Pflichten-Pfad",
  "type": "object",
  "required": [
    "version",
    "rechtsstand",
    "felder",
    "rechtsformen",
    "branchen",
    "kiStufen",
    "profile",
    "regelwerke"
  ],
  "properties": {
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "rechtsstand": {
      "type": "string",
      "format": "date"
    },
    "sprache": {
      "type": "string"
    },
    "hinweis": {
      "type": "string"
    },
    "felder": {
      "type": "object",
      "additionalProperties": {
        "type": "object"
      }
    },
    "rechtsformen": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "id",
          "label",
          "haftungsbeschraenkt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "haftungsbeschraenkt": {
            "type": "boolean"
          }
        }
      }
    },
    "branchen": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "id",
          "label",
          "nis",
          "gruppe"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "nis": {
            "enum": [
              "a1",
              "a2",
              null
            ]
          },
          "gruppe": {
            "type": "string"
          }
        }
      }
    },
    "kiStufen": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "label"
        ]
      }
    },
    "profile": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "label",
          "werte"
        ],
        "properties": {
          "werte": {
            "type": "object"
          }
        }
      }
    },
    "regelwerke": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/regelwerk"
      }
    },
    "verlauf": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "version",
          "datum",
          "zusammenfassung",
          "eintraege"
        ],
        "properties": {
          "version": {
            "type": "string"
          },
          "datum": {
            "type": "string"
          },
          "zusammenfassung": {
            "type": "string"
          },
          "eintraege": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/verlaufseintrag"
            }
          }
        }
      }
    },
    "geplant": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "$defs": {
    "bedingung": {
      "oneOf": [
        {
          "const": true
        },
        {
          "type": "object",
          "required": [
            "feld",
            "op",
            "wert"
          ],
          "properties": {
            "feld": {
              "type": "string"
            },
            "op": {
              "enum": [
                ">=",
                ">",
                "<=",
                "<",
                "ist",
                "in"
              ]
            },
            "wert": {}
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "alle"
          ],
          "properties": {
            "alle": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/bedingung"
              }
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "eines"
          ],
          "properties": {
            "eines": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/bedingung"
              }
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "nicht"
          ],
          "properties": {
            "nicht": {
              "$ref": "#/$defs/bedingung"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "stufe": {
      "type": "object",
      "required": [
        "datum",
        "label"
      ],
      "properties": {
        "datum": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "label": {
          "type": "string"
        }
      }
    },
    "regelwerk": {
      "type": "object",
      "required": [
        "id",
        "name",
        "basis",
        "schwelle",
        "kurz",
        "pflicht",
        "sanktion",
        "quelle",
        "gilt",
        "kriterien",
        "varianten"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+$"
        },
        "name": {
          "type": "string"
        },
        "basis": {
          "type": "string"
        },
        "schwelle": {
          "type": "string"
        },
        "kurz": {
          "type": "string"
        },
        "pflicht": {
          "type": "string"
        },
        "sanktion": {
          "type": "string"
        },
        "ohne": {
          "type": "string"
        },
        "quelle": {
          "type": "object",
          "required": [
            "label",
            "url",
            "geprueft",
            "intervall"
          ],
          "properties": {
            "label": {
              "type": "string"
            },
            "url": {
              "type": "string",
              "format": "uri"
            },
            "geprueft": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "Tag der letzten Prüfung dieser Fundstelle"
            },
            "intervall": {
              "enum": [
                "monatlich",
                "quartalsweise",
                "halbjährlich",
                "jährlich"
              ],
              "description": "Vorgesehener Prüfrhythmus"
            }
          }
        },
        "gilt": {
          "$ref": "#/$defs/bedingung"
        },
        "kriterien": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "label"
            ],
            "properties": {
              "label": {
                "type": "string"
              },
              "feld": {
                "type": "string"
              },
              "op": {
                "enum": [
                  ">=",
                  ">",
                  "<=",
                  "<",
                  "ist",
                  "in"
                ]
              },
              "wert": {},
              "einheit": {
                "type": "string"
              },
              "bedingung": {
                "$ref": "#/$defs/bedingung"
              },
              "anzeige": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "optional": {
                "type": "boolean"
              }
            }
          }
        },
        "varianten": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "wenn",
              "stufen"
            ],
            "properties": {
              "wenn": {
                "$ref": "#/$defs/bedingung"
              },
              "einstufung": {
                "type": "string"
              },
              "sanktion": {
                "type": "string"
              },
              "hinweis": {
                "type": "string"
              },
              "stufen": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "$ref": "#/$defs/stufe"
                }
              }
            }
          }
        },
        "aufgaben": {
          "type": "array",
          "minItems": 4,
          "items": {
            "$ref": "#/$defs/aufgabe"
          },
          "description": "Was konkret zu tun ist, wenn das Regelwerk greift"
        }
      }
    },
    "aufgabe": {
      "type": "object",
      "required": [
        "art",
        "text"
      ],
      "additionalProperties": false,
      "properties": {
        "art": {
          "enum": [
            "einmalig",
            "laufend",
            "jaehrlich",
            "frist"
          ],
          "description": "einmalig, dauerhaft, jährlich wiederkehrend oder an eine gesetzliche Frist gebunden"
        },
        "text": {
          "type": "string",
          "minLength": 30
        }
      }
    },
    "verlaufseintrag": {
      "type": "object",
      "required": [
        "art",
        "rw",
        "titel",
        "text"
      ],
      "additionalProperties": false,
      "properties": {
        "art": {
          "enum": [
            "aufgenommen",
            "geaendert",
            "offen"
          ]
        },
        "rw": {
          "type": [
            "string",
            "null"
          ],
          "description": "id eines Regelwerks oder null für einen allgemeinen Eintrag"
        },
        "titel": {
          "type": "string"
        },
        "text": {
          "type": "string"
        },
        "fundstelle": {
          "type": "string"
        }
      }
    }
  }
}
