{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "FF Solver v2 Request",
  "type": "object",
  "required": [
    "variables"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "description": "Schema version. Defaults to 1 if absent; set to 2 for v2 features.",
      "default": 1
    },
    "variables": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "name",
          "type"
        ],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-zA-Z_]\\w*$"
          },
          "type": {
            "type": "string",
            "enum": [
              "int",
              "bool",
              "enum",
              "float"
            ]
          },
          "domain": {
            "type": "object",
            "oneOf": [
              {
                "properties": {
                  "min": {
                    "type": "integer"
                  },
                  "max": {
                    "type": "integer"
                  }
                },
                "additionalProperties": false
              },
              {
                "properties": {
                  "intervals": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "integer"
                      },
                      "minItems": 2,
                      "maxItems": 2
                    },
                    "minItems": 1
                  }
                },
                "required": [
                  "intervals"
                ],
                "additionalProperties": false
              }
            ]
          },
          "values": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 2,
            "description": "Required for enum type."
          }
        }
      }
    },
    "constraints": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "expression",
              "all_different",
              "implication",
              "cardinality",
              "any_of",
              "table"
            ]
          }
        },
        "oneOf": [
          {
            "properties": {
              "type": {
                "const": "expression"
              },
              "expression": {
                "type": "string"
              }
            },
            "required": [
              "type",
              "expression"
            ]
          },
          {
            "properties": {
              "type": {
                "const": "all_different"
              },
              "vars": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 2
              }
            },
            "required": [
              "type",
              "vars"
            ]
          },
          {
            "properties": {
              "type": {
                "const": "implication"
              },
              "if": {
                "type": "string"
              },
              "then": {
                "type": "string"
              }
            },
            "required": [
              "type",
              "if",
              "then"
            ]
          },
          {
            "properties": {
              "type": {
                "const": "cardinality"
              },
              "mode": {
                "type": "string",
                "enum": [
                  "at_most",
                  "at_least",
                  "exactly"
                ]
              },
              "vars": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 1
              },
              "count": {
                "type": "integer",
                "minimum": 0
              },
              "value": {
                "type": "integer"
              }
            },
            "required": [
              "type",
              "mode",
              "vars",
              "count"
            ]
          },
          {
            "properties": {
              "type": {
                "const": "any_of"
              },
              "constraints": {
                "type": "array",
                "items": {
                  "type": "object"
                },
                "minItems": 1
              }
            },
            "required": [
              "type",
              "constraints"
            ]
          },
          {
            "properties": {
              "type": {
                "const": "table"
              },
              "mode": {
                "type": "string",
                "enum": [
                  "allowed",
                  "forbidden"
                ]
              },
              "vars": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 1
              },
              "tuples": {
                "type": "array",
                "items": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                }
              }
            },
            "required": [
              "type",
              "mode",
              "vars",
              "tuples"
            ]
          }
        ]
      }
    },
    "objective": {
      "type": "object",
      "properties": {
        "target": {
          "type": "string"
        },
        "goal": {
          "type": "string",
          "enum": [
            "maximize",
            "minimize"
          ]
        }
      },
      "required": [
        "target",
        "goal"
      ]
    },
    "settings": {
      "type": "object",
      "properties": {
        "timeout_ms": {
          "type": "number",
          "exclusiveMinimum": 0,
          "default": 1000
        },
        "solver_hint": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            null,
            "scip",
            "cpsat",
            "z3"
          ]
        }
      }
    }
  }
}