{
  "id": "component-fallback-version.schema.json",
  "title": "Component Fallback Version",
  "description": "Represents a fallback version of a component that can be used under certain logical conditions, including flight and killswitch checks.",
  "type": "object",
  "required": ["version", "condition"],
  "properties": {
    "version": {
      "description": "The version of the component to be used as a fallback.",
      "oneOf": [{ "$ref": "semver.schema.json" }]
    },
    "condition": {
      "description": "The condition under which the fallback version should be used. Supports logical operators and flight/killswitch checks.",
      "$ref": "#/definitions/operatorOrSwitch"
    }
  },
  "definitions": {
    "operatorOrSwitch": {
      "oneOf": [
        {
          "type": "object",
          "required": ["and"],
          "properties": {
            "and": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/definitions/operatorOrSwitch" }
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["or"],
          "properties": {
            "or": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/definitions/operatorOrSwitch" }
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["xor"],
          "properties": {
            "xor": {
              "type": "array",
              "minItems": 2,
              "maxItems": 2,
              "items": { "$ref": "#/definitions/operatorOrSwitch" }
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["not"],
          "properties": {
            "not": { "$ref": "#/definitions/operatorOrSwitch" }
          },
          "additionalProperties": false
        },
        { "$ref": "#/definitions/flightOrKillSwitch" }
      ]
    },
    "flightOrKillSwitch": {
      "oneOf": [
        {
          "type": "object",
          "required": ["switchType", "id"],
          "properties": {
            "switchType": {
              "type": "string",
              "enum": ["flight"],
              "description": "Indicates this is a flight check."
            },
            "id": {
              "type": "integer",
              "description": "The numeric ID of the flight."
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["switchType", "id"],
          "properties": {
            "switchType": {
              "type": "string",
              "enum": ["killswitch"],
              "description": "Indicates this is a killswitch check."
            },
            "id": {
              "$ref": "guid.schema.json",
              "description": "The GUID of the killswitch."
            }
          },
          "additionalProperties": false
        }
      ]
    }
  },
  "additionalProperties": false
}
