{
  "$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": "Multiply two numbers. Example: {op:'mul', left:{op:'literal', value:5}, right:{op:'literal', value:3}}",
          "properties": {
            "left": {
              "$ref": "#/$defs/operation"
            },
            "op": {
              "const": "mul"
            },
            "right": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "left",
            "right"
          ],
          "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": "Remove duplicate values from list. For count distinct: pipe | map(get field) | distinct | count",
          "properties": {
            "op": {
              "const": "distinct"
            }
          },
          "required": [
            "op"
          ],
          "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": "Construct object with evaluated values. Example: {op:'object', fields:{count:{op:'var', name:'n'}, name:'test'}}",
          "properties": {
            "fields": {
              "type": "object"
            },
            "op": {
              "const": "object"
            }
          },
          "required": [
            "op",
            "fields"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Get value at field or path. Use field for single key: {op:'get', field:'name'}. Use path for nested: {op:'get', path:['user', 'name']}",
          "properties": {
            "default": {},
            "field": {
              "type": "string"
            },
            "op": {
              "const": "get"
            },
            "path": {
              "items": {
                "type": "string"
              },
              "type": "array"
            }
          },
          "required": [
            "op"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Keep items where field value is a member of a set. Example: {op:'filter_in', field:'status', value:['active', 'pending']}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "filter_in"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "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": "Get type of current value as string. Returns 'object', 'list', 'string', 'number', 'boolean', or 'null'. Example: {op:'typeof'}",
          "properties": {
            "op": {
              "const": "typeof"
            }
          },
          "required": [
            "op"
          ],
          "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": "Sort list by field. Example: {op:'sort_by', field:'price'} or {op:'sort_by', field:'price', order:'desc'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "sort_by"
            },
            "order": {
              "type": "string"
            }
          },
          "required": [
            "op",
            "field"
          ],
          "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": "Round a number to N decimal places (default 0). Precision must be a non-negative integer (0-15). Example: {op:'round', value:{op:'var', name:'x'}, precision:2}",
          "properties": {
            "op": {
              "const": "round"
            },
            "precision": {},
            "value": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Drop first N elements from list. Example: {op:'drop', count:5}",
          "properties": {
            "count": {
              "minimum": 0,
              "type": "integer"
            },
            "op": {
              "const": "drop"
            }
          },
          "required": [
            "op",
            "count"
          ],
          "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": "Value is member of field set. Example: {op:'in', field:'tags', value:'featured'}",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "in"
            },
            "value": {}
          },
          "required": [
            "op",
            "field",
            "value"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Get sorted list of keys in a map. Example: {op:'keys'}",
          "properties": {
            "op": {
              "const": "keys"
            }
          },
          "required": [
            "op"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Get the row with minimum field value. Example: {op:'min_by', field:'price'} returns the item with lowest price",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "min_by"
            }
          },
          "required": [
            "op",
            "field"
          ],
          "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": "Take first N elements from list. Example: {op:'take', count:5}",
          "properties": {
            "count": {
              "minimum": 0,
              "type": "integer"
            },
            "op": {
              "const": "take"
            }
          },
          "required": [
            "op",
            "count"
          ],
          "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": "Calculate percentage: (part / whole) * 100. Convenience operation for common ratio calculations. Example: {op:'pct', part:{op:'var', name:'delivered'}, whole:{op:'var', name:'total'}}",
          "properties": {
            "op": {
              "const": "pct"
            },
            "part": {
              "$ref": "#/$defs/operation"
            },
            "whole": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "part",
            "whole"
          ],
          "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": "Divide two numbers (always returns float; error on divide by zero). Example: {op:'div', left:{op:'literal', value:10}, right:{op:'literal', value:4}}",
          "properties": {
            "left": {
              "$ref": "#/$defs/operation"
            },
            "op": {
              "const": "div"
            },
            "right": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "left",
            "right"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Add two numbers. Example: {op:'add', left:{op:'var', name:'a'}, right:{op:'literal', value:10}}",
          "properties": {
            "left": {
              "$ref": "#/$defs/operation"
            },
            "op": {
              "const": "add"
            },
            "right": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "left",
            "right"
          ],
          "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": "Get the row with maximum field value. Example: {op:'max_by', field:'years'} returns the item with highest years",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "const": "max_by"
            }
          },
          "required": [
            "op",
            "field"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "description": "Subtract two numbers. Example: {op:'sub', left:{op:'var', name:'total'}, right:{op:'var', name:'spent'}}",
          "properties": {
            "left": {
              "$ref": "#/$defs/operation"
            },
            "op": {
              "const": "sub"
            },
            "right": {
              "$ref": "#/$defs/operation"
            }
          },
          "required": [
            "op",
            "left",
            "right"
          ],
          "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"
}