{
    "$id": "https://schemas.highbyte.com/intelligencehub/instance/4.5.0.json",
    "$defs": {
        "InstanceAttribute": {
            "type": "object",
            "properties": {
                "attributes": {
                    "description": "Nested child attributes. Mirrors the structure of the referenced Model schema.",
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/InstanceAttribute"
                    }
                },
                "defaultValue": {
                    "$ref": "#/$defs/JsonNode",
                    "description": "Default value applied when the expression yields no result."
                },
                "description": {
                    "type": "string",
                    "description": "Description of the configuration element."
                },
                "expression": {
                    "anyOf": [
                        {
                            "allOf": [
                                {
                                    "type": "object",
                                    "properties": {
                                        "expression": {
                                            "type": "string",
                                            "description": "The JavaScript source to evaluate. A return statement is required."
                                        },
                                        "type": {
                                            "const": "JavaScript"
                                        }
                                    },
                                    "description": "An expression that evaluates a JavaScript snippet to produce the attribute's value. Used when the value requires logic, transformation, or computation beyond a simple reference.",
                                    "required": [
                                        "type"
                                    ]
                                },
                                {
                                    "description": "The expression that produces this attribute's value. May be a JavaScript expression that returns a value, a reference to another field or input, or a pipeline stage reference."
                                }
                            ]
                        },
                        {
                            "allOf": [
                                {
                                    "type": "object",
                                    "properties": {
                                        "reference": {
                                            "anyOf": [
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "type": {
                                                            "const": "Empty"
                                                        }
                                                    },
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "params": {
                                                            "$ref": "#/$defs/ObjectNode"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "type": {
                                                            "const": "Instance"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "params": {
                                                            "$ref": "#/$defs/ObjectNode"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "type": {
                                                            "const": "Pipeline"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "connectionName": {
                                                            "type": "string"
                                                        },
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "params": {
                                                            "$ref": "#/$defs/ObjectNode"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "type": {
                                                            "const": "Input"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "params": {
                                                            "$ref": "#/$defs/ObjectNode"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "source": {
                                                            "type": "string"
                                                        },
                                                        "type": {
                                                            "const": "Condition"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "params": {
                                                            "$ref": "#/$defs/ObjectNode"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "reference": {
                                                            "type": "object",
                                                            "properties": {
                                                                "type": {
                                                                    "const": "ResolvedReference"
                                                                }
                                                            },
                                                            "required": [
                                                                "type"
                                                            ]
                                                        },
                                                        "type": {
                                                            "const": "DynamicCondition"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "source": {
                                                            "type": "string"
                                                        },
                                                        "type": {
                                                            "const": "System"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "type": {
                                                            "const": "Dictionary"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "legacyParams": {
                                                            "$ref": "#/$defs/JsonNode"
                                                        },
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "type": {
                                                            "const": "LegacyPipeline"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "ioName": {
                                                            "type": "string"
                                                        },
                                                        "name": {
                                                            "type": "string"
                                                        },
                                                        "params": {
                                                            "type": "string"
                                                        },
                                                        "path": {
                                                            "type": "string"
                                                        },
                                                        "refType": {
                                                            "type": "string"
                                                        },
                                                        "type": {
                                                            "const": "Advanced"
                                                        }
                                                    },
                                                    "required": [
                                                        "type"
                                                    ],
                                                    "description": "The reference to resolve. Supports Input, Instance, Condition, and System reference types and may include a path into the referenced value."
                                                }
                                            ]
                                        },
                                        "type": {
                                            "const": "Reference"
                                        }
                                    },
                                    "description": "An expression that resolves a reference to produce the attribute's value directly from an Input, Instance, Condition, or System value."
                                },
                                {
                                    "description": "The expression that produces this attribute's value. May be a JavaScript expression that returns a value, a reference to another field or input, or a pipeline stage reference."
                                }
                            ]
                        },
                        {
                            "allOf": [
                                {
                                    "type": "object",
                                    "properties": {
                                        "stageReference": {
                                            "type": "string",
                                            "description": "Simple event or System reference identifying the value to pull from an earlier pipeline stage."
                                        },
                                        "type": {
                                            "const": "PipelineStageReference"
                                        }
                                    },
                                    "description": "An expression that references a value produced by an earlier pipeline stage. Used inside the modeling stage of a pipeline.",
                                    "required": [
                                        "type"
                                    ]
                                },
                                {
                                    "description": "The expression that produces this attribute's value. May be a JavaScript expression that returns a value, a reference to another field or input, or a pipeline stage reference."
                                }
                            ]
                        }
                    ]
                },
                "groupAs": {
                    "type": "string",
                    "description": "Optional grouping identifier for organizing configuration elements into logical groups."
                },
                "id": {
                    "type": "string",
                    "description": "UUID for the configuration element. If not provided, a random UUID will be generated. This ID is used to track the element across changes and should be stable for the lifetime of the process."
                },
                "name": {
                    "type": "string",
                    "description": "Name of the configuration element."
                }
            }
        },
        "InternalTypeAttribute": {
            "type": "object",
            "properties": {
                "array": {
                    "type": "boolean",
                    "description": "Whether the attribute is an array."
                },
                "defaultValue": {
                    "$ref": "#/$defs/JsonNode",
                    "description": "The default value for the attribute."
                },
                "description": {
                    "type": "string",
                    "description": "Description of the configuration element."
                },
                "groupAs": {
                    "type": "string",
                    "description": "Optional grouping identifier for organizing configuration elements into logical groups."
                },
                "id": {
                    "type": "string",
                    "description": "UUID for the configuration element. If not provided, a random UUID will be generated. This ID is used to track the element across changes and should be stable for the lifetime of the process."
                },
                "internalType": {
                    "type": "string"
                },
                "name": {
                    "type": "string",
                    "description": "Name of the configuration element."
                },
                "nullable": {
                    "type": "boolean",
                    "description": "Whether the attribute can be null."
                },
                "required": {
                    "type": "boolean",
                    "description": "Whether the attribute is required."
                },
                "attributeType": {
                    "const": "Internal"
                }
            },
            "required": [
                "attributeType"
            ]
        },
        "JsonNode": {
            "type": "object"
        },
        "ModeledAttribute": {
            "type": "object",
            "properties": {
                "array": {
                    "type": "boolean",
                    "description": "Whether the attribute is an array."
                },
                "defaultValue": {
                    "$ref": "#/$defs/JsonNode",
                    "description": "The default value for the attribute."
                },
                "description": {
                    "type": "string",
                    "description": "Description of the configuration element."
                },
                "groupAs": {
                    "type": "string",
                    "description": "Optional grouping identifier for organizing configuration elements into logical groups."
                },
                "id": {
                    "type": "string",
                    "description": "UUID for the configuration element. If not provided, a random UUID will be generated. This ID is used to track the element across changes and should be stable for the lifetime of the process."
                },
                "model": {
                    "type": "string",
                    "description": "The name of the referenced model for this attribute."
                },
                "name": {
                    "type": "string",
                    "description": "Name of the configuration element."
                },
                "nullable": {
                    "type": "boolean",
                    "description": "Whether the attribute can be null."
                },
                "required": {
                    "type": "boolean",
                    "description": "Whether the attribute is required."
                },
                "attributeType": {
                    "const": "Modeled"
                }
            },
            "description": "Represents a modeled attribute, referencing another model by name.",
            "required": [
                "attributeType"
            ]
        },
        "ObjectModelAttribute-1": {
            "type": "object",
            "properties": {
                "array": {
                    "type": "boolean",
                    "description": "Whether the attribute is an array."
                },
                "attributes": {
                    "type": "array",
                    "items": {
                        "anyOf": [
                            {
                                "$ref": "#/$defs/ModeledAttribute"
                            },
                            {
                                "$ref": "#/$defs/InternalTypeAttribute"
                            },
                            {
                                "$ref": "#/$defs/ObjectModelAttribute-2"
                            }
                        ]
                    }
                },
                "defaultValue": {
                    "$ref": "#/$defs/JsonNode",
                    "description": "The default value for the attribute."
                },
                "description": {
                    "type": "string",
                    "description": "Description of the configuration element."
                },
                "groupAs": {
                    "type": "string",
                    "description": "Optional grouping identifier for organizing configuration elements into logical groups."
                },
                "id": {
                    "type": "string",
                    "description": "UUID for the configuration element. If not provided, a random UUID will be generated. This ID is used to track the element across changes and should be stable for the lifetime of the process."
                },
                "name": {
                    "type": "string",
                    "description": "Name of the configuration element."
                },
                "nullable": {
                    "type": "boolean",
                    "description": "Whether the attribute can be null."
                },
                "required": {
                    "type": "boolean",
                    "description": "Whether the attribute is required."
                }
            }
        },
        "ObjectModelAttribute-2": {
            "$ref": "#/$defs/ObjectModelAttribute-1",
            "type": "object",
            "properties": {
                "attributeType": {
                    "const": "Object"
                }
            },
            "required": [
                "attributeType"
            ]
        },
        "ObjectNode": {
            "type": "object"
        }
    },
    "type": "object",
    "properties": {
        "attributes": {
            "description": "The attributes that make up this instance. Each attribute is populated by either a JavaScript expression or a reference, with an optional default value.",
            "type": "array",
            "items": {
                "$ref": "#/$defs/InstanceAttribute"
            }
        },
        "description": {
            "type": "string",
            "description": "Description of the configuration element."
        },
        "executeMode": {
            "type": "string",
            "enum": [
                "V3Legacy",
                "V4"
            ],
            "description": "Selects which expression engine evaluates the instance's expressions. V4 is the current engine; V3Legacy supports the expression syntax deprecated in version 4.0 of the product."
        },
        "groupAs": {
            "type": "string",
            "description": "Optional grouping identifier for organizing configuration elements into logical groups."
        },
        "id": {
            "type": "string",
            "description": "UUID for the configuration element. If not provided, a random UUID will be generated. This ID is used to track the element across changes and should be stable for the lifetime of the process."
        },
        "initExpression": {
            "type": "string",
            "description": "Expression executed once before any attribute expressions. The variables object can be assigned data or functions here and is then available (read-only) inside every attribute expression."
        },
        "model": {
            "type": "string",
            "description": "The Model that defines the shape of data produced by this instance."
        },
        "name": {
            "type": "string",
            "description": "Name of the configuration element."
        },
        "parameters": {
            "allOf": [
                {
                    "type": "object",
                    "properties": {
                        "model": {
                            "allOf": [
                                {
                                    "type": "object",
                                    "properties": {
                                        "attributes": {
                                            "description": "The attributes defined for this model.",
                                            "type": "array",
                                            "items": {
                                                "anyOf": [
                                                    {
                                                        "$ref": "#/$defs/ModeledAttribute"
                                                    },
                                                    {
                                                        "$ref": "#/$defs/InternalTypeAttribute"
                                                    },
                                                    {
                                                        "$ref": "#/$defs/ObjectModelAttribute-2"
                                                    }
                                                ]
                                            }
                                        },
                                        "description": {
                                            "type": "string",
                                            "description": "Description of the configuration element."
                                        },
                                        "extendsModel": {
                                            "type": "string",
                                            "description": "The name of the model this one extends, if any."
                                        },
                                        "groupAs": {
                                            "type": "string",
                                            "description": "Optional grouping identifier for organizing configuration elements into logical groups."
                                        },
                                        "id": {
                                            "type": "string",
                                            "description": "UUID for the configuration element. If not provided, a random UUID will be generated. This ID is used to track the element across changes and should be stable for the lifetime of the process."
                                        },
                                        "name": {
                                            "type": "string",
                                            "description": "Name of the configuration element."
                                        },
                                        "tags": {
                                            "description": "Tags for organizing and filtering configuration elements.",
                                            "type": "array",
                                            "items": {
                                                "type": "string"
                                            }
                                        }
                                    },
                                    "description": "Represents a configured model, including its attributes and inheritance."
                                },
                                {
                                    "description": "Embedded model definition for inline parameters."
                                }
                            ]
                        },
                        "type": {
                            "const": "inline"
                        }
                    },
                    "description": "Represents inline parameters for a pipeline trigger or stage, including an embedded model definition.",
                    "required": [
                        "type"
                    ]
                },
                {
                    "description": "Instance-level parameters that can be referenced from attribute expressions and the initialization expression."
                }
            ]
        },
        "rootValueAs": {
            "type": "string",
            "enum": [
                "Object",
                "Array"
            ],
            "description": "Controls how root-level arrays are handled. When set to Array, root-level arrays are expanded into individual outputs; when set to Object, the root is emitted as a single object."
        },
        "tags": {
            "description": "Tags for organizing and filtering configuration elements.",
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "template": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "params": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string"
                            },
                            "pattern": {
                                "type": "string"
                            }
                        }
                    }
                },
                "reference": {
                    "type": "string"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "Off",
                        "Dynamic",
                        "Static"
                    ]
                }
            },
            "description": "Templating configuration for this instance. When type is Static, parameters are defined locally as key/value pairs. When type is Dynamic, parameters are pulled from a data source (e.g. SQL). When Off, no templating is applied."
        }
    },
    "description": "An Instance produces shaped data conforming to a referenced Model. Attributes are populated using expressions or references and can be parameterized, templated, and initialized with a setup expression."
}
