{
    "$defs": {
        "DataIo": {
            "properties": {
                "inputs": {
                    "default": [],
                    "items": {
                        "$ref": "#/$defs/IOConfig"
                    },
                    "title": "Inputs",
                    "type": "array"
                },
                "outputs": {
                    "default": [],
                    "items": {
                        "$ref": "#/$defs/IOConfig"
                    },
                    "title": "Outputs",
                    "type": "array"
                }
            },
            "title": "DataIo",
            "type": "object"
        },
        "DataQualityIo": {
            "properties": {
                "inputs": {
                    "default": [],
                    "items": {
                        "$ref": "#/$defs/DataQualityIOConfig"
                    },
                    "title": "Inputs",
                    "type": "array"
                },
                "outputs": {
                    "default": [],
                    "items": {
                        "$ref": "#/$defs/DataQualityIOConfig"
                    },
                    "title": "Outputs",
                    "type": "array"
                }
            },
            "title": "DataIo",
            "type": "object"
        },
        "CustomActionDef": {
            "properties": {
                "type": {
                    "pattern": "^[a-zA-Z0-9]([-_ .a-zA-Z0-9]*[a-zA-Z0-9])?$",
                    "title": "Type",
                    "type": "string"
                }
            },
            "required": [
                "type"
            ],
            "title": "CustomActionDef",
            "type": "object"
        },
        "CustomActionsIO": {
            "properties": {
                "inputs": {
                    "default": [],
                    "items": {
                        "$ref": "#/$defs/CustomActionDef"
                    },
                    "title": "Inputs",
                    "type": "array"
                },
                "outputs": {
                    "default": [],
                    "items": {
                        "$ref": "#/$defs/CustomActionDef"
                    },
                    "title": "Outputs",
                    "type": "array"
                }
            },
            "title": "CustomActionsIO",
            "type": "object"
        },
        "DatastreamMapping": {
            "properties": {
                "app": {
                    "title": "App",
                    "type": "string"
                },
                "datastream": {
                    "title": "Datastream",
                    "type": "string"
                }
            },
            "required": [
                "app",
                "datastream"
            ],
            "title": "DatastreamMapping",
            "type": "object"
        },
        "DeploymentDefaults": {
            "properties": {
                "system": {
                    "default": {},
                    "$ref": "#/$defs/System"
                },
                "datastream_mapping": {
                    "default": [],
                    "items": {
                        "$ref": "#/$defs/DatastreamMapping"
                    },
                    "title": "Datastream Mapping",
                    "type": "array"
                },
                "configuration": {
                    "default": {},
                    "title": "Configuration",
                    "type": "object"
                },
                "parameters": {
                    "additionalProperties": {
                        "anyOf": [
                            {
                                "type": "boolean"
                            },
                            {
                                "type": "integer"
                            },
                            {
                                "type": "number"
                            },
                            {
                                "type": "string"
                            }
                        ]
                    },
                    "default": {},
                    "title": "Parameters",
                    "type": "object"
                }
            },
            "title": "DeploymentDefaults",
            "type": "object"
        },
        "IOConfig": {
            "properties": {
                "name": {
                    "title": "Name",
                    "type": "string"
                },
                "data_type": {
                    "title": "Data Type",
                    "type": "string"
                },
                "unit": {
                    "anyOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "null"
                        }
                    ],
                    "default": null,
                    "title": "Unit"
                }
            },
            "required": [
                "name",
                "data_type"
            ],
            "title": "IOConfig",
            "type": "object"
        },
        "DataQualityIOConfig": {
            "properties": {
                "name": {
                    "title": "Name",
                    "type": "string"
                },
                "data_type": {
                    "title": "Data Type",
                    "type": "string"
                },
                "data_streams": {
                    "type": "array",
                    "title": "Data Streams",
                    "items": {
                        "type": "string"
                    }
                }
            },
            "required": [
                "name",
                "data_type"
            ],
            "title": "DataQualityIOConfig",
            "type": "object"
        },
        "RuntimeUpdateConfig": {
            "properties": {
                "configuration": {
                    "default": false,
                    "title": "Configuration",
                    "type": "boolean"
                },
                "resources": {
                    "default": false,
                    "title": "Resources",
                    "type": "boolean"
                },
                "parameters": {
                    "default": true,
                    "title": "Parameters",
                    "type": "boolean"
                },
                "resource_properties": {
                    "default": true,
                    "title": "Resource Properties",
                    "type": "boolean"
                }
            },
            "title": "RuntimeUpdateConfig",
            "type": "object"
        },
        "SchemasConfig": {
            "properties": {
                "configuration": {
                    "anyOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "null"
                        }
                    ],
                    "default": null,
                    "title": "Configuration"
                },
                "parameters": {
                    "anyOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "null"
                        }
                    ],
                    "default": null,
                    "title": "Parameters"
                }
            },
            "title": "SchemasConfig",
            "type": "object"
        },
        "SmartAppFlags": {
            "properties": {
                "enable_runtime_update": {
                    "$ref": "#/$defs/RuntimeUpdateConfig",
                    "default": {
                        "configuration": false,
                        "resources": false,
                        "parameters": true,
                        "resource_properties": true
                    }
                }
            },
            "title": "SmartAppFlags",
            "type": "object"
        },
        "SmartAppParams": {
            "properties": {
                "name": {
                    "title": "Name",
                    "type": "string"
                },
                "data_type": {
                    "enum": [
                        "number",
                        "string",
                        "boolean"
                    ],
                    "title": "Data Type",
                    "type": "string"
                }
            },
            "required": [
                "name",
                "data_type"
            ],
            "title": "SmartAppParams",
            "type": "object"
        },
        "System": {
            "type": "object",
            "properties": {
                "health_check": {
                    "type": "object",
                    "title": "Health Check",
                    "properties": {
                        "liveness_probe": {
                            "type": "object",
                            "title": "Liveness Probe",
                            "description": "Checks if the container is running. Failing the probe restarts the container.",
                            "properties": {
                                "initial_delay_seconds": {
                                    "type": "integer",
                                    "title": "Initial Delay (s)",
                                    "description": "Seconds to wait before starting probes.",
                                    "default": 1,
                                    "minimum": 0,
                                    "maximum": 2147483647
                                },
                                "period_seconds": {
                                    "type": "integer",
                                    "title": "Probe Interval (s)",
                                    "description": "Frequency of probe execution.",
                                    "default": 10,
                                    "minimum": 1,
                                    "maximum": 2147483647
                                },
                                "timeout_seconds": {
                                    "type": "integer",
                                    "title": "Timeout (s)",
                                    "description": "Seconds before the probe times out.",
                                    "default": 1,
                                    "minimum": 1,
                                    "maximum": 2147483647
                                },
                                "failure_threshold": {
                                    "type": "integer",
                                    "title": "Failure Threshold",
                                    "description": "Failures before restarting the container.",
                                    "default": 3,
                                    "minimum": 1,
                                    "maximum": 2147483647
                                },
                                "type": {
                                    "type": "string",
                                    "description": "Method to perform the health check.",
                                    "enum": [
                                        "http_get",
                                        "tcp_socket",
                                        "exec"
                                    ]
                                },
                                "http_get": {
                                    "type": "object",
                                    "title": "HTTP GET Probe",
                                    "description": "Performs an HTTP GET request to check health.",
                                    "required": [
                                        "port"
                                    ],
                                    "properties": {
                                        "path": {
                                            "type": "string",
                                            "title": "Path",
                                            "description": "HTTP path to access."
                                        },
                                        "port": {
                                            "type": "integer",
                                            "title": "Port",
                                            "description": "Port for the HTTP server.",
                                            "minimum": 1,
                                            "maximum": 65535
                                        },
                                        "scheme": {
                                            "type": "string",
                                            "description": "Protocol to use.",
                                            "enum": [
                                                "http",
                                                "https"
                                            ]
                                        },
                                        "http_headers": {
                                            "type": "array",
                                            "title": "HTTP Headers",
                                            "description": "Custom headers for the request.",
                                            "items": {
                                                "type": "object",
                                                "properties": {
                                                    "name": {
                                                        "type": "string",
                                                        "title": "Header Name",
                                                        "format": "^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$"
                                                    },
                                                    "value": {
                                                        "type": "string",
                                                        "title": "Header Value",
                                                        "format": "^[\\x20-\\x7E]*$"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                },
                                "tcp_socket": {
                                    "type": "object",
                                    "title": "TCP Socket Probe",
                                    "description": "Checks if a TCP port is open.",
                                    "required": [
                                        "port"
                                    ],
                                    "properties": {
                                        "port": {
                                            "type": "integer",
                                            "title": "Port",
                                            "description": "TCP port to check.",
                                            "minimum": 1,
                                            "maximum": 65535
                                        }
                                    }
                                },
                                "exec": {
                                    "type": "object",
                                    "title": "Exec Probe",
                                    "description": "Runs a command inside the container to check health.",
                                    "required": [
                                        "command"
                                    ],
                                    "properties": {
                                        "command": {
                                            "type": "array",
                                            "title": "Command",
                                            "description": "Command to execute. Exit code 0 is healthy.",
                                            "items": {
                                                "type": "string"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "resources": {
                    "type": "object",
                    "title": "Resource Configuration",
                    "properties": {
                        "requests": {
                            "type": "object",
                            "title": "Resource Requests",
                            "properties": {
                                "cpu": {
                                    "type": "string",
                                    "title": "CPU Request",
                                    "description": "Minimum CPU required.",
                                    "format": "^([0-9]+m|[0-9]+(\\.[0-9]+)?|[0-9]+)$"
                                },
                                "memory": {
                                    "type": "string",
                                    "title": "Memory Request",
                                    "description": "Minimum memory required.",
                                    "format": "^([0-9]+(\\.[0-9]+)?(Ei|Pi|Ti|Gi|Mi|Ki|E|P|T|G|M|K)?|[0-9]+)$"
                                }
                            }
                        },
                        "limits": {
                            "type": "object",
                            "properties": {
                                "cpu": {
                                    "type": "string",
                                    "title": "CPU Limit",
                                    "description": "Maximum CPU allowed.",
                                    "format": "^([0-9]+m|[0-9]+(\\.[0-9]+)?|[0-9]+)$"
                                },
                                "memory": {
                                    "type": "string",
                                    "title": "Memory Limit",
                                    "description": "Maximum memory allowed.",
                                    "format": "^([0-9]+(\\.[0-9]+)?(Ei|Pi|Ti|Gi|Mi|Ki|E|P|T|G|M|K)?|[0-9]+)$"
                                }
                            }
                        }
                    }
                },
                "privileged": {
                    "type": "boolean",
                    "description": "Run the container in privileged mode.",
                    "default": false
                },
                "environment_vars": {
                    "type": "array",
                    "title": "Environment Variables",
                    "description": "List of environment variables.",
                    "items": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "title": "Variable Name",
                                "description": "Name of the environment variable.",
                                "format": "^[A-Za-z_][A-Za-z0-9_]*$"
                            },
                            "value": {
                                "type": "string",
                                "title": "Variable Value",
                                "description": "Value of the environment variable."
                            }
                        }
                    }
                },
                "ports": {
                    "type": "array",
                    "title": "Container Ports",
                    "description": "List of ports exposed by the container.",
                    "items": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "title": "Port Name",
                                "description": "Name identifier for the port.",
                                "format": "^[a-z0-9]([-_.a-z0-9]*[a-z0-9])?$"
                            },
                            "type": {
                                "type": "string",
                                "description": "Type of port to expose.",
                                "enum": [
                                    "host",
                                    "service"
                                ]
                            },
                            "host": {
                                "type": "object",
                                "title": "Host Configuration",
                                "required": [
                                    "port"
                                ],
                                "properties": {
                                    "port": {
                                        "type": "integer",
                                        "title": "Host Port",
                                        "description": "Port on the host machine.",
                                        "minimum": 1,
                                        "maximum": 65535
                                    }
                                }
                            },
                            "service": {
                                "type": "object",
                                "title": "Service Configuration",
                                "required": [
                                    "port"
                                ],
                                "properties": {
                                    "port": {
                                        "type": "integer",
                                        "title": "Service Port",
                                        "description": "Port exposed by the service.",
                                        "minimum": 1,
                                        "maximum": 65535
                                    },
                                    "container_port": {
                                        "type": "integer",
                                        "title": "Container Port",
                                        "description": "Port exposed by the container.",
                                        "minimum": 1,
                                        "maximum": 65535
                                    },
                                    "exposed": {
                                        "type": "boolean",
                                        "title": "Exposed",
                                        "description": "Expose the port outside the cluster.",
                                        "default": false
                                    },
                                    "exposed_port": {
                                        "type": "integer",
                                        "title": "Exposed Port",
                                        "description": "Port exposed outside the cluster.",
                                        "minimum": 30001,
                                        "maximum": 32767
                                    }
                                }
                            }
                        }
                    }
                },
                "volumes": {
                    "type": "array",
                    "title": "Volumes",
                    "description": "List of volumes mounted by the container.",
                    "items": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "title": "Volume Name",
                                "description": "Name identifier for the volume.",
                                "format": "^[a-z]([-a-z0-9]*[a-z0-9])?$"
                            },
                            "target": {
                                "type": "string",
                                "title": "Mount Path",
                                "description": "Path where the volume is mounted."
                            },
                            "type": {
                                "type": "string",
                                "description": "Type of volume to use.",
                                "enum": [
                                    "persistent",
                                    "host",
                                    "text"
                                ]
                            },
                            "text": {
                                "type": "object",
                                "title": "Text Volume",
                                "required": [
                                    "data"
                                ],
                                "properties": {
                                    "data": {
                                        "type": "string",
                                        "title": "Data",
                                        "description": "Text content of the volume."
                                    },
                                    "base64": {
                                        "type": "boolean",
                                        "title": "Base64 Encoded",
                                        "description": "Data is base64 encoded.",
                                        "default": false
                                    },
                                    "encoding": {
                                        "type": "string",
                                        "title": "Encoding",
                                        "description": "Text encoding format.",
                                        "enum": [
                                            "utf-8",
                                            "ascii",
                                            "latin_1"
                                        ]
                                    }
                                }
                            },
                            "host": {
                                "type": "object",
                                "title": "Host Volume",
                                "required": [
                                    "source"
                                ],
                                "properties": {
                                    "source": {
                                        "type": "string",
                                        "title": "Source Path",
                                        "description": "Path on the host machine."
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "properties": {
        "name": {
            "pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$",
            "title": "Name",
            "type": "string"
        },
        "title": {
            "title": "Title",
            "type": "string"
        },
        "description": {
            "title": "Description",
            "type": "string"
        },
        "type": {
            "const": "app",
            "title": "Type",
            "type": "string"
        },
        "version": {
            "pattern": "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$",
            "title": "Version",
            "type": "string"
        },
        "category": {
            "anyOf": [
                {
                    "type": "string"
                },
                {
                    "type": "null"
                }
            ],
            "default": null,
            "title": "Category"
        },
        "spec_version": {
            "default": "5.0.0",
            "title": "Spec Version",
            "type": "string"
        },
        "flags": {
            "$ref": "#/$defs/SmartAppFlags",
            "default": {
                "enable_runtime_update": {
                    "configuration": false,
                    "parameters": true,
                    "resource_properties": true,
                    "resources": false
                }
            }
        },
        "data_streams": {
            "$ref": "#/$defs/DataIo",
            "default": {
                "inputs": [],
                "outputs": []
            }
        },
        "control_changes": {
            "$ref": "#/$defs/DataIo",
            "default": {
                "inputs": [],
                "outputs": []
            }
        },
        "parameters": {
            "default": [],
            "items": {
                "$ref": "#/$defs/SmartAppParams"
            },
            "title": "Parameters",
            "type": "array"
        },
        "data_quality": {
            "$ref": "#/$defs/DataQualityIo",
            "default": {
                "inputs": [],
                "outputs": []
            }
        },
        "ui_schemas": {
            "$ref": "#/$defs/SchemasConfig",
            "default": {
                "configuration": null,
                "parameters": null
            }
        },
        "defaults": {
            "$ref": "#/$defs/DeploymentDefaults",
            "default": {
                "system": {},
                "datastream_mapping": [],
                "configuration": {},
                "parameters": {}
            }
        },
        "custom_actions": {
            "$ref": "#/$defs/CustomActionsIO",
            "default": {
                "inputs": [],
                "outputs": []
            }
        }
    },
    "required": [
        "name",
        "title",
        "description",
        "type",
        "version"
    ],
    "title": "SmartAppConfig",
    "type": "object",
    "additionalProperties": false
}