{
  "$defs": {
    "operation": {
      "oneOf": [
        {
          "additionalProperties": false,
          "description": "Load a resource by name. Use name='input' to load the input data. Example: {op:'load', name:'input'}",
          "properties": {
            "name": {
              "type": "string"
            },
            "op": {
              "const": "load"
            }
          },
          "required": [
            "op",
            "name"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Get last element. Example: {op:'last'}",
          "properties": {
            "op": {
              "const": "last"
            }
          },
          "required": [
            "op"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Sequence of operations. Example: {op:'pipe', steps:[{op:'load', name:'input'}, {op:'filter', where:{op:'gt', field:'price', value:10}}]}",
          "properties": {
            "op": {
              "const": "pipe"
            },
            "steps": {
              "items": {
                "$ref": "#/$defs/operation"
              },
              "type": "array"
            }
          },
          "required": [
            "op",
            "steps"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Concatenate multiple lists. Example: {op:'concat', lists:[{op:'literal', value:[1,2]}, {op:'literal', value:[3,4]}]}",
          "properties": {
            "lists": {
              "items": {
                "$ref": "#/$defs/operation"
              },
              "type": "array"
            },
            "op": {
              "const": "concat"
            }
          },
          "required": [
            "op",
            "lists"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Merge multiple objects. Example: {op:'merge', objects:[{op:'literal', value:{a:1}}, {op:'literal', value:{b:2}}]}",
          "properties": {
            "objects": {
              "items": {
                "$ref": "#/$defs/operation"
              },
              "type": "array"
            },
            "op": {
              "const": "merge"
            }
          },
          "required": [
            "op",
            "objects"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Count items in collection. Example: {op:'count'}",
          "properties": {
            "op": {
              "const": "count"
            }
          },
          "required": [
            "op"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Maximum value in field. Example: {op:'max', field:'price'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "max"
            }
          },
          "required": [
            "op",
            "field"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Field less than or equal to value. Example: {op:'lte', field:'quantity', value:0}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "lte"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Field equals value. Example: {op:'eq', field:'status', value:'active'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "eq"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Reject collection elements based on condition. Example: {op:'reject', where:{op:'eq', field:'status', value:'inactive'}}",
          "properties": {
            "op": {
              "const": "reject"
            },
            "where": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "where"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Get value at path. Example: {op:'get', path:['user', 'address', 'city']}",
          "properties": {
            "default": {},
            "op": {
              "const": "get"
            },
            "path": {
              "items": {
                "type": "string"
              },
              "type": "array"
            }
          },
          "required": [
            "op",
            "path"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Sum numeric field. Example: {op:'sum', field:'price'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "sum"
            }
          },
          "required": [
            "op",
            "field"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Select specific fields from objects. Example: {op:'select', fields:['name', 'email']}",
          "properties": {
            "fields": {
              "items": {
                "type": "string"
              },
              "type": "array"
            },
            "op": {
              "const": "select"
            }
          },
          "required": [
            "op",
            "fields"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Call a tool. Example: {op:'call', tool:'fetch_user', args:{id:123}}",
          "properties": {
            "args": {
              "type": "object"
            },
            "op": {
              "const": "call"
            },
            "tool": {
              "type": "string"
            }
          },
          "required": [
            "op",
            "tool"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Minimum value in field. Example: {op:'min', field:'price'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "min"
            }
          },
          "required": [
            "op",
            "field"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Get first element. Example: {op:'first'}",
          "properties": {
            "op": {
              "const": "first"
            }
          },
          "required": [
            "op"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Conditional expression. Example: {op:'if', condition:{op:'gt', field:'age', value:18}, then:{op:'literal', value:'adult'}, else:{op:'literal', value:'minor'}}",
          "properties": {
            "condition": {
              "$ref": "#/$defs/operation"
            },
            "else": {
              "$ref": "#/$defs/operation"
            },
            "op": {
              "const": "if"
            },
            "then": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "condition",
            "else",
            "then"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Field greater than value. Example: {op:'gt', field:'price', value:10}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "gt"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Field contains value. Example: {op:'contains', field:'tags', value:'featured'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "contains"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Transform collection elements. Example: {op:'map', expr:{op:'get', path:['name']}}",
          "properties": {
            "expr": {
              "$ref": "#/$defs/operation"
            },
            "op": {
              "const": "map"
            }
          },
          "required": [
            "op",
            "expr"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "A literal JSON value. Example: {op:'literal', value:42}",
          "properties": {
            "op": {
              "const": "literal"
            },
            "value": {}
          },
          "required": [
            "op",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Logical NOT of a condition. Example: {op:'not', condition:{op:'eq', field:'status', value:'deleted'}}",
          "properties": {
            "condition": {
              "$ref": "#/$defs/operation"
            },
            "op": {
              "const": "not"
            }
          },
          "required": [
            "op",
            "condition"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Get element at index. Example: {op:'nth', index:2}",
          "properties": {
            "index": {
              "minimum": 0,
              "type": "integer"
            },
            "op": {
              "const": "nth"
            }
          },
          "required": [
            "op",
            "index"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Field greater than or equal to value. Example: {op:'gte', field:'age', value:18}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "gte"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Reference a variable. Example: {op:'var', name:'count'}",
          "properties": {
            "name": {
              "type": "string"
            },
            "op": {
              "const": "var"
            }
          },
          "required": [
            "op",
            "name"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Field not equals value. Example: {op:'neq', field:'status', value:'deleted'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "neq"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Field less than value. Example: {op:'lt', field:'price', value:100}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "lt"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Logical AND of conditions. Example: {op:'and', conditions:[{op:'gt', field:'age', value:18}, {op:'eq', field:'status', value:'active'}]}",
          "properties": {
            "conditions": {
              "items": {
                "$ref": "#/$defs/operation"
              },
              "type": "array"
            },
            "op": {
              "const": "and"
            }
          },
          "required": [
            "op",
            "conditions"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Bind a value to a variable. Example: {op:'let', name:'x', value:{op:'literal', value:5}, in:{op:'var', name:'x'}}",
          "properties": {
            "in": {
              "$ref": "#/$defs/operation"
            },
            "name": {
              "type": "string"
            },
            "op": {
              "const": "let"
            },
            "value": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "in",
            "name",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Keep items matching condition. Example: {op:'filter', where:{op:'gt', field:'price', value:10}}",
          "properties": {
            "op": {
              "const": "filter"
            },
            "where": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "where"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Zip multiple lists together. Example: {op:'zip', lists:[{op:'literal', value:[1,2]}, {op:'literal', value:['a','b']}]}",
          "properties": {
            "lists": {
              "items": {
                "$ref": "#/$defs/operation"
              },
              "type": "array"
            },
            "op": {
              "const": "zip"
            }
          },
          "required": [
            "op",
            "lists"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Average of numeric field. Example: {op:'avg', field:'rating'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "avg"
            }
          },
          "required": [
            "op",
            "field"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Logical OR of conditions. Example: {op:'or', conditions:[{op:'eq', field:'status', value:'pending'}, {op:'eq', field:'status', value:'cancelled'}]}",
          "properties": {
            "conditions": {
              "items": {
                "$ref": "#/$defs/operation"
              },
              "type": "array"
            },
            "op": {
              "const": "or"
            }
          },
          "required": [
            "op",
            "conditions"
          ],
          "type": "object"
        }
      ]
    }
  },
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "properties": {
    "program": {
      "$ref": "#/$defs/operation",
      "description": "The PTC program operation"
    }
  },
  "required": [
    "program"
  ],
  "title": "PTC DSL Program",
  "type": "object"
}