{
  "$id": "graphplotting.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "GraphPlotting Question Schema",
  "description": "Schema for GraphPlotting question type, consistent with Learnosity standards.",
  "$ref": "learnosity-question-base.schema.json",
  "type": "object",
  "required": ["stimulus", "axis_x", "axis_y", "canvas", "grid", "toolbar", "background_shapes", "feedback_attempts", "ui_style", "is_math"],
  "properties": {
    "type": {
      "type": "string",
      "const": "graphplotting",
      "description": "Question type identifier. Must be 'graphplotting'."
    },
    "stimulus": {
      "type": "string",
      "description": "The question prompt or stimulus."
    },
    "axis_x": {
      "type": "object",
      "properties": {
        "draw_labels": { "type": "boolean" },
        "show_first_arrow": { "type": "boolean" },
        "show_last_arrow": { "type": "boolean" },
        "ticks_distance": { "type": "number" },
        "show_axis_label": { "type": "boolean" },
        "axis_label": { "type": "string" }
      },
      "required": ["draw_labels", "show_first_arrow", "show_last_arrow", "ticks_distance", "show_axis_label", "axis_label"],
      "additionalProperties": false
    },
    "axis_y": {
      "type": "object",
      "properties": {
        "draw_labels": { "type": "boolean" },
        "show_first_arrow": { "type": "boolean" },
        "show_last_arrow": { "type": "boolean" },
        "ticks_distance": { "type": "number" },
        "show_axis_label": { "type": "boolean" },
        "axis_label": { "type": "string" }
      },
      "required": ["draw_labels", "show_first_arrow", "show_last_arrow", "ticks_distance", "show_axis_label", "axis_label"],
      "additionalProperties": false
    },
    "canvas": {
      "type": "object",
      "properties": {
        "snap_to": { "type": "string", "enum": ["grid", "none"] },
        "x_max": { "type": "number" },
        "x_min": { "type": "number" },
        "y_max": { "type": "number" },
        "y_min": { "type": "number" }
      },
      "required": ["snap_to", "x_max", "x_min", "y_max", "y_min"],
      "additionalProperties": false
    },
    "grid": {
      "type": "object",
      "properties": {
        "x_distance": { "type": "number" },
        "y_distance": { "type": "number" }
      },
      "required": ["x_distance", "y_distance"],
      "additionalProperties": false
    },
    "toolbar": {
      "type": "object",
      "properties": {
        "default_tool": { "type": "string", "enum": ["polygon", "point", "line", "move"] },
        "tools": {
          "type": "array",
          "items": { "type": "string", "enum": ["polygon", "point", "line", "move"] },
          "minItems": 1
        }
      },
      "required": ["default_tool", "tools"],
      "additionalProperties": false
    },
    "background_shapes": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "type": { "type": "string", "enum": ["point", "polygon", "line"] },
          "coords": {
            "type": "object",
            "properties": {
              "x": { "type": "number" },
              "y": { "type": "number" }
            },
            "required": ["x", "y"],
            "additionalProperties": false
          },
          "subElement": { "type": "boolean" },
          "subElementsIds": {
            "type": "array",
            "items": { "type": "string" }
          }
        },
        "required": ["id", "type"],
        "additionalProperties": true
      },
      "minItems": 1
    },
    "background_image": {
      "type": "object",
      "properties": {
        "src": { "type": "string" }
      },
      "required": ["src"],
      "additionalProperties": false
    },
    "feedback_attempts": {
      "type": ["integer", "string"],
      "description": "Number of attempts before showing feedback"
    },
    "ui_style": {
      "allOf": [
        { "$ref": "ui_style.schema.json" },
        { "required": ["height", "width", "validation_stem_numeration"] }
      ]
    },
    "is_math": {
      "type": "boolean",
      "description": "Indicates if the question is math-related."
    }
  },
  "additionalProperties": true
}
