{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mx8labs.com/schemas/mx8-completed-conjoint-design-v1.schema.json",
  "title": "MX8 Labs Completed Conjoint Design",
  "description": "A completed choice-based conjoint design whose supplied concepts and task order must be preserved.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "kind", "study", "attributes", "concepts", "taskSets"],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "schemaVersion": {
      "const": 1
    },
    "kind": {
      "const": "mx8.completed-conjoint-design"
    },
    "metadata": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "sourceName": { "type": "string", "minLength": 1 },
        "sourceFormat": { "type": "string", "minLength": 1 },
        "notes": { "type": "string", "minLength": 1 }
      }
    },
    "study": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "hasDontKnowOption"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "questionText": { "type": "string", "minLength": 1 },
        "hasDontKnowOption": { "type": "boolean" },
        "assignmentStrategy": {
          "enum": ["least-filled", "random", "sequential", "external"]
        },
        "randomizeTaskOrder": { "type": "boolean" },
        "randomizeConceptOrder": { "type": "boolean" }
      }
    },
    "attributes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "name", "type", "levels"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "name": { "type": "string", "minLength": 1 },
          "type": {
            "enum": ["categorical", "ordered", "numeric", "boolean"]
          },
          "levels": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["id", "label"],
              "properties": {
                "id": { "$ref": "#/$defs/id" },
                "label": { "type": "string", "minLength": 1 }
              }
            }
          }
        }
      }
    },
    "concepts": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "values"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "values": {
            "type": "object",
            "minProperties": 1,
            "propertyNames": { "$ref": "#/$defs/id" },
            "additionalProperties": { "$ref": "#/$defs/id" }
          }
        }
      }
    },
    "taskSets": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "tasks"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "tasks": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["id", "conceptIds"],
              "properties": {
                "id": { "$ref": "#/$defs/id" },
                "conceptIds": {
                  "type": "array",
                  "minItems": 2,
                  "items": { "$ref": "#/$defs/id" }
                }
              }
            }
          }
        }
      }
    },
    "prohibitions": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "left", "right"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "left": { "$ref": "#/$defs/prohibitionEndpoint" },
          "right": { "$ref": "#/$defs/prohibitionEndpoint" }
        }
      }
    },
    "unmappedItems": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["source", "description"],
        "properties": {
          "source": { "type": "string", "minLength": 1 },
          "description": { "type": "string", "minLength": 1 }
        }
      }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "prohibitionEndpoint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["attributeId", "levelId"],
      "properties": {
        "attributeId": { "$ref": "#/$defs/id" },
        "levelId": { "$ref": "#/$defs/id" }
      }
    }
  }
}
