{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://api-evangelist.github.io/tripetto/json-schema/tripetto-form-schema.json",
  "title": "Tripetto Form",
  "description": "Schema for a Tripetto form including its metadata and definition",
  "type": "object",
  "required": ["id", "name", "definition"],
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique form identifier"
    },
    "name": {
      "type": "string",
      "description": "Human-readable form name"
    },
    "description": {
      "type": "string",
      "description": "Optional description of the form's purpose"
    },
    "definition": {
      "$ref": "#/definitions/FormDefinition"
    },
    "created": {
      "type": "string",
      "format": "date-time",
      "description": "Form creation timestamp"
    },
    "modified": {
      "type": "string",
      "format": "date-time",
      "description": "Last modification timestamp"
    },
    "responseCount": {
      "type": "integer",
      "description": "Total number of responses collected",
      "minimum": 0
    }
  },
  "definitions": {
    "FormDefinition": {
      "type": "object",
      "description": "JSON definition of a Tripetto form generated by the Builder",
      "properties": {
        "nodes": {
          "type": "array",
          "description": "Array of form nodes representing questions and blocks",
          "items": {
            "$ref": "#/definitions/FormNode"
          }
        },
        "sections": {
          "type": "array",
          "description": "Grouping sections within the form",
          "items": {
            "$ref": "#/definitions/FormSection"
          }
        },
        "conditions": {
          "type": "array",
          "description": "Conditional logic rules for branching",
          "items": {
            "type": "object"
          }
        }
      }
    },
    "FormNode": {
      "type": "object",
      "required": ["id", "type"],
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique node identifier"
        },
        "type": {
          "type": "string",
          "description": "Block type identifier",
          "enum": [
            "text",
            "email",
            "number",
            "yes-no",
            "dropdown",
            "multiple-choice",
            "date",
            "url",
            "phone",
            "file-upload",
            "rating",
            "opinion-scale",
            "matrix",
            "calculation"
          ]
        },
        "name": {
          "type": "string",
          "description": "Question or field label"
        },
        "required": {
          "type": "boolean",
          "description": "Whether a response is required",
          "default": false
        },
        "settings": {
          "type": "object",
          "description": "Block-specific configuration settings"
        }
      }
    },
    "FormSection": {
      "type": "object",
      "required": ["id"],
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique section identifier"
        },
        "name": {
          "type": "string",
          "description": "Section label displayed to respondents"
        },
        "nodes": {
          "type": "array",
          "description": "Node IDs belonging to this section",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}
