{
  "type": "object",
  "description": "DForms Form Schema",
  "required": [
    "sections"
  ],
  "definitions": {
    "section": {
      "properties": {
        "label": {
          "type": "string"
        },
        "fields": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9_]+$": {
              "$ref": "#/definitions/fields"
            }
          }
        }
      },
      "additionalProperties": false
    },
    "fields": {
      "oneOf": [
        {
          "$ref": "#/definitions/textField"
        },
        {
          "$ref": "#/definitions/numericField"
        },
        {
          "$ref": "#/definitions/emailField"
        },
        {
          "$ref": "#/definitions/currencyField"
        },
        {
          "$ref": "#/definitions/staticField"
        },
        {
          "$ref": "#/definitions/enumField"
        },
        {
          "$ref": "#/definitions/multipleField"
        },
        {
          "$ref": "#/definitions/dateField"
        },
        {
          "$ref": "#/definitions/timeField"
        },
        {
          "$ref": "#/definitions/datetimeField"
        },
        {
          "$ref": "#/definitions/repeatingField"
        }
      ]
    },
    "expressionId": {
      "type": "string"
    },
    "textField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "text"
          ]
        },
        "suggestions": {
          "type": "array"
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "required": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "string"
            }
          ]
        },
        "placeholder": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "emailField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "email"
          ]
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "required": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "string"
            }
          ]
        },
        "placeholder": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "currencyField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "currency"
          ]
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "required": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "string"
            }
          ]
        },
        "placeholder": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "staticField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "static"
          ]
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "enumField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "enum"
          ]
        },
        "options": {
          "anyOf": [
            {
              "type": "array",
              "minItems": 1,
              "_uniqueItems": true,
              "items": {
                "type": "string"
              }
            },
            {
              "type": "object",
              "minProperties": 1
            }
          ]
        },
        "default": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "required": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "string"
            }
          ]
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "multipleField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "multiple"
          ]
        },
        "fields": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9_]+$": {
              "$ref": "#/definitions/fields"
            }
          }
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "numericField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "number",
            "decimal"
          ]
        },
        "min": {
          "type": "number"
        },
        "max": {
          "type": "number"
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "required": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "string"
            }
          ]
        },
        "placeholder": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "dateField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "date"
          ]
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "required": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "string"
            }
          ]
        },
        "placeholder": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "timeField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "time"
          ]
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "required": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "string"
            }
          ]
        },
        "placeholder": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "datetimeField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "datetime"
          ]
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "required": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "string"
            }
          ]
        },
        "placeholder": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/fieldSize"
        },
        "visible": {
          "$ref": "#/definitions/expressionId"
        },
        "valid": {
          "$ref": "#/definitions/expressionId"
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "fieldSize": {
      "type": "number",
      "minimum": 1,
      "maximum": 12,
      "multipleOf": 1
    },
    "repeatingField": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "repeating"
          ]
        },
        "fields": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9_]+$": {
              "$ref": "#/definitions/fields"
            }
          }
        },
        "label": {
          "type": "string"
        },
        "help": {
          "type": "string"
        },
        "minRows": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "string"
            }
          ]
        },
        "maxRows": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "string"
            }
          ]
        },
        "inline": {
          "type": "boolean"
        },
        "expressions": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9_]+$": {
              "$ref": "#/definitions/expressions"
            }
          },
          "additionalProperties": false
        }
      },
      "required": [
        "label"
      ],
      "additionalProperties": false
    },
    "conditionAnd": {
      "type": "array",
      "minItems": 2,
      "items": {
        "$ref": "#/definitions/expressions"
      }
    },
    "conditionOr": {
      "type": "array",
      "minItems": 2,
      "items": {
        "$ref": "#/definitions/expressions"
      }
    },
    "conditionGreaterThan": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "items": {
        "$ref": "#/definitions/expressions"
      }
    },
    "conditionGreaterThanOrEqualTo": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "items": {
        "$ref": "#/definitions/expressions"
      }
    },
    "conditionLessThan": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "items": {
        "$ref": "#/definitions/expressions"
      }
    },
    "conditionLessThanOrEqualTo": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "items": {
        "$ref": "#/definitions/expressions"
      }
    },
    "conditionNot": {
      "$ref": "#/definitions/expressions"
    },
    "conditionEmpty": {
      "$ref": "#/definitions/expressions"
    },
    "conditionValue": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        }
      ]
    },
    "conditionEquals": {
      "type": "array",
      "minItems": 2,
      "items": {
        "$ref": "#/definitions/expressions"
      }
    },
    "conditionField": {
      "type": "string"
    },
    "conditionExpression": {
      "type": "string"
    },
    "expressions": {
      "oneOf": [
        {
          "properties": {
            "and": {
              "$ref": "#/definitions/conditionAnd"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "or": {
              "$ref": "#/definitions/conditionOr"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "not": {
              "$ref": "#/definitions/conditionNot"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "field": {
              "$ref": "#/definitions/conditionField"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "equals": {
              "$ref": "#/definitions/conditionEquals"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "empty": {
              "$ref": "#/definitions/conditionEmpty"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "value": {
              "$ref": "#/definitions/conditionValue"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            ">": {
              "$ref": "#/definitions/conditionGreaterThan"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            ">=": {
              "$ref": "#/definitions/conditionGreaterThanOrEqualTo"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "<": {
              "$ref": "#/definitions/conditionLessThan"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "<=": {
              "$ref": "#/definitions/conditionLessThanOrEqualTo"
            }
          },
          "additionalProperties": false
        },
        {
          "properties": {
            "expression": {
              "$ref": "#/definitions/conditionExpression"
            }
          },
          "additionalProperties": false
        }
      ]
    }
  },
  "properties": {
    "sections": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_]+$": {
          "$ref": "#/definitions/section"
        }
      },
      "additionalProperties": false
    },
    "expressions": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_]+$": {
          "$ref": "#/definitions/expressions"
        }
      },
      "additionalProperties": false
    }
  }
}