{
  "$id": "/1-0-0/interfaces.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Common Interfaces",
  "description": "This schema includes definitions for common interfaces across the AICA System",
  "$defs": {
    "encoded_state_type": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Encoded State Type",
      "description": "The state type of an encoded value from a collection of supported types, as defined in clproto.",
      "type": "string",
      "enum": [
        "state",
        "spatial_state",
        "cartesian_state",
        "cartesian_pose",
        "cartesian_twist",
        "cartesian_acceleration",
        "cartesian_wrench",
        "jacobian",
        "joint_state",
        "joint_positions",
        "joint_velocities",
        "joint_accelerations",
        "joint_torques",
        "shape",
        "ellipsoid",
        "parameter",
        "digital_io_state",
        "analog_io_state"
      ]
    },
    "parameter": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Parameter",
      "description": "A dynamic parameter that is publicly configurable.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "display_name": {
          "description": "The human-readable parameter name.",
          "examples": [
            "Reference Frame",
            "Gain"
          ],
          "type": "string"
        },
        "description": {
          "description": "A brief description of the parameter.",
          "type": "string"
        },
        "parameter_name": {
          "description": "The lower_snake_case parameter name as it is declared in the implementation.",
          "examples": [
            "reference_frame",
            "gain"
          ],
          "type": "string"
        },
        "parameter_type": {
          "description": "The parameter value type.",
          "$ref": "#/$defs/parameter_type"
        },
        "parameter_state_type": {
          "description": "The state type of the parameter, if the value type is an encoded state.",
          "$ref": "#/$defs/encoded_state_type"
        },
        "default_value": {
          "description": "The string representation of the default parameter value, or null if the parameter has no valid default value.",
          "examples": [
            "foo",
            "[ 1.0, 2.0, 3.0 ]",
            null
          ],
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "optional": {
          "description": "Specify if this parameter is optional (only applicable if the default value is null)",
          "type": "boolean"
        },
        "dynamic": {
          "description": "Specify if this parameter can be dynamically reconfigured.",
          "type": "boolean"
        },
        "internal": {
          "description": "Specify if this parameter is for internal use only and should be hidden from public users.",
          "type": "boolean",
          "default": false
        }
      },
      "required": [
        "display_name",
        "description",
        "parameter_name",
        "parameter_type",
        "default_value"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "default_value": {
                "not": {
                  "const": null
                }
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "optional"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "parameter_type": {
                "const": "state"
              }
            }
          },
          "then": {
            "required": [
              "parameter_state_type"
            ]
          }
        }
      ]
    },
    "parameter_type": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Parameter Type",
      "description": "The value type of a parameter from a collection of supported types.",
      "type": "string",
      "enum": [
        "bool",
        "bool_array",
        "int",
        "int_array",
        "double",
        "double_array",
        "string",
        "string_array",
        "vector",
        "matrix",
        "state"
      ]
    },
    "predicate": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Predicate",
      "description": "A predicate of a component or controller.",
      "type": "object",
      "properties": {
        "display_name": {
          "description": "The human-readable predicate name.",
          "type": "string"
        },
        "description": {
          "description": "A brief description of the predicate.",
          "type": "string"
        },
        "predicate_name": {
          "description": "The lower_snake_case predicate name as it is declared in the component or controller.",
          "type": "string"
        }
      },
      "required": [
        "display_name",
        "description",
        "predicate_name"
      ]
    },
    "service": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Service",
      "description": "A service endpoint of a component or controller.",
      "type": "object",
      "properties": {
        "display_name": {
          "description": "The human-readable service name.",
          "type": "string"
        },
        "description": {
          "description": "A brief description of the service.",
          "type": "string"
        },
        "service_name": {
          "description": "The lower_snake_case service name as it is declared in the component or controller.",
          "type": "string"
        },
        "payload_format": {
          "description": "Optional description of the payload format if the service has a string payload. If omitted, the service is assumed to be an empty trigger.",
          "type": "string"
        }
      },
      "required": [
        "display_name",
        "description",
        "service_name"
      ]
    },
    "signal": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Signal",
      "description": "A continuous data signal in the AICA framework that can be an input or an output.",
      "type": "object",
      "properties": {
        "display_name": {
          "description": "The short name of this signal (to be displayed on the edge of the node in the graph view).",
          "examples": [
            "Target Pose",
            "Sum",
            "Command Torque"
          ],
          "type": "string"
        },
        "description": {
          "description": "A description of the signal for tool-tips and documentation.",
          "type": "string"
        },
        "signal_name": {
          "description": "The registered name of the signal from which the default topic and parameter '<$signal_name>_topic' are determined.",
          "examples": [
            "target_pose",
            "sum",
            "command_torque"
          ],
          "type": "string"
        },
        "default_topic": {
          "description": "The default topic name assigned to this signal. If unspecified, it is assumed to be '~/<$signal_name>'. Setting the parameter '<$signal_name>_topic' will override the default value.",
          "default": "~/signal_name",
          "type": "string"
        },
        "reconfigurable_topic": {
          "description": "Indicate if the signal topic is reconfigurable and can be renamed while the parent node is inactive through the '<$signal_name>_topic' parameter.",
          "default": false,
          "type": "boolean"
        },
        "signal_type": {
          "description": "The fixed type of this signal.",
          "$ref": "#/$defs/signal_type"
        },
        "signal_types": {
          "description": "An array of signal types supported by configurable typing. The active type is set through the '<$signal_name>_type' parameter, and the default type is determined by the `signal_type` property.",
          "type": "array",
          "items": {
            "$ref": "#/$defs/signal_type"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "reconfigurable_type": {
          "description": "Indicate if the signal type is reconfigurable and can be renamed while the parent node is inactive through the '<$signal_name>_type' parameter.",
          "default": false,
          "type": "boolean"
        },
        "custom_signal_type": {
          "description": "The custom signal type of the signal",
          "examples": [
            "sensor_msgs::msg::JointState",
            "geometry_msgs::msg::Pose"
          ],
          "type": "string"
        }
      },
      "required": [
        "display_name",
        "description",
        "signal_name",
        "signal_type"
      ],
      "if": {
        "properties": {
          "signal_type": {
            "const": "other"
          }
        }
      },
      "then": {
        "required": [
          "custom_signal_type"
        ]
      }
    },
    "signal_type": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Signal Type",
      "description": "Supported signal value types as simple atomic types or encoded state types.",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "bool",
            "int",
            "double",
            "double_array",
            "string",
            "other"
          ]
        },
        {
          "$ref": "#/$defs/encoded_state_type"
        }
      ]
    }
  }
}