<?xml version="1.0" encoding="UTF-8"?>

<!--
JBoss, Home of Professional Open Source

Copyright 2021, Red Hat, Inc., and individual contributors as indicated
by the @authors tag.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:jboss:cli:4.0" targetNamespace="urn:jboss:cli:4.0"
           elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:element name="jboss-cli">
        <xs:annotation>
            <xs:documentation>
                Root element for the WildFly Command Line Interface configuration.
            </xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="default-protocol" minOccurs="0" default="remote+http">
                    <xs:annotation>
                        <xs:documentation>
                            The default protocol to use when controller addresses are supplied without one.
                        </xs:documentation>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="xs:string">
                                <xs:attribute name="use-legacy-override" type="xs:boolean" default="true">
                                    <xs:annotation>
                                        <xs:documentation>
                                            The default protocol is used where a connection address is specified and no
                                            protocol is specified, in previous versions the port 9999 would have been used with the remote
                                            protocol - this attribute set to true causes the protocol to default to remote if the port
                                            number is 9999.

                                            If this attribute is set to false then the specified default is used regardless
                                            of the port number for addresses with no protocol.
                                        </xs:documentation>
                                    </xs:annotation>
                                </xs:attribute>
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>

                <xs:element name="default-controller" type="controllerAddress" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            If no default controller is specifed then the default will be assumed to be using host 'localhost'
                            along with the default-protocol (Which will be remote+http if not defined) and the port will be whatever
                            default corresponds to the selected protocol.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="controllers" type="controllersType" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            The names controller alias mappings.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="validate-operation-requests" type="xs:boolean" default="true" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            Indicates whether the parameter list of the operation reuqests should be validated before the
                            requests are sent to the controller for the execution.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="history" type="historyType" minOccurs="0" />

                <xs:element name="resolve-parameter-values" type="xs:boolean" minOccurs="0" maxOccurs="1" default="false">
                    <xs:annotation>
                        <xs:documentation>
                            Whether to resolve system properties specified as command argument (or operation parameter) values
                            before sending the operation request to the controller or let the resolution happen on the server side.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="connection-timeout" type="xs:int" default="5000" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            The time allowed to establish a connection with the controller.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="ssl" type="sslType" minOccurs="0" />

                <xs:element name="silent" type="xs:boolean" default="false" minOccurs="1">
                    <xs:annotation>
                        <xs:documentation>
                            Whether to write info and error messages to the terminal output.

                            Even if the value is false, the messages will still be logged using
                            the logger if its configuration allows and/or if the output target was
                            specified as part of the command line using '>'.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="access-control" type="xs:boolean" default="true" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            Whether the management-related commands and attributes should be filtered for the current user
                            based on the permissions the user has been granted. In other words, if access-control is true, the
                            tab-completion will hide commands and attributes the user is not allowed to access. In case the user attempts to
                            execute a command or an operation without having sufficient permissions to do so, regardless of the value this
                            element has, the attempt will fail with an access control error.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="echo-command" type="xs:boolean" default="false" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            Commands executed in non interactive modes (scripts, list of commands, CLI API), have their name and list of options
                            printed prior to the command actual output. This does help match command with printed result.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="command-timeout" type="xs:int" default="0" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            The maximum amount of seconds the CLI will wait for a command to complete. Default timeout of 0 means no timeout.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="output-json" type="xs:boolean" default="false" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            Display operation responses using JSON syntax. By default responses are displayed using
                            DMR string syntax.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>

                <xs:element name="color-output" type="colorConfigType" minOccurs="0" />

                <xs:element name="output-paging" type="xs:boolean" default="true" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            By default, if the OS supports it, the output of commands is not printed at once,
                            instead you can scroll through it and search in it.
                            This behaviour is similar to 'less' linux command.
                            When this option is set to false the paging will be disabled
                            and the whole output of all commands will be written at once(useful e.g.for copy/paste).
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="controllerAddress">
        <xs:annotation>
            <xs:documentation>
                The address of a controller.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="protocol" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        If no protocol is specified then the value for 'default-protocol' will be used.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="host" type="xs:string" minOccurs="0" default="localhost" />
            <xs:element name="port" type="xs:int" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        If a port is not specified then the default port will be identified based on the protocol selected.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="namedController">
        <xs:complexContent>
            <xs:extension base="controllerAddress">
                <xs:attribute name="name" use="required">
                    <xs:annotation>
                        <xs:documentation>
                            The name of this controller alias.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="controllersType">
        <xs:sequence>
            <xs:element name="controller" type="namedController" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="historyType">
        <xs:annotation>
            <xs:documentation>
                This element contains the configuration for the commands and operations history log.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="enabled" type="xs:boolean" minOccurs="0" default="true" />
            <xs:element name="file-name" type="xs:string" minOccurs="0" default=".jboss-cli-history" />
            <xs:element name="file-dir" type="xs:string" minOccurs="0" default="${user.home}" />
            <xs:element name="max-size" type="xs:int" minOccurs="0" default="500" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="sslType">
        <xs:annotation>
            <xs:documentation>
                This element contains the configuration for the Key and Trust stores
                used for SSL.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="key-store" type="xs:string" minOccurs="0" />
            <xs:element name="key-store-password" type="xs:string" minOccurs="0" />
            <xs:element name="alias" type="xs:string" minOccurs="0" />
            <xs:element name="key-password" type="xs:string" minOccurs="0" />
            <xs:element name="trust-store" type="xs:string" minOccurs="0" />
            <xs:element name="trust-store-password" type="xs:string" minOccurs="0" />
            <xs:element name="modify-trust-store" type="xs:boolean" default="true" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Setting to true will cause the CLI to prompt when unrecognised certificates are received and allow
                        them to be stored in the truststore.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="colorConfigType">
        <xs:annotation>
            <xs:documentation>
                Enables/disables and configures the CLI color output. Only foreground colors are configurable.
                Available colors: black, blue, cyan, green, magenta, red, white, yellow and default.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="enabled" type="xs:boolean" default="true" minOccurs="1"/>
            <xs:element name="error-color" type="colorChoiceType" default="red"/>
            <xs:element name="warn-color" type="colorChoiceType" default="yellow"/>
            <xs:element name="success-color" type="colorChoiceType" default="default"/>
            <xs:element name="required-color" type="colorChoiceType" default="magenta"/>
            <xs:element name="workflow-color" type="colorChoiceType" default="green"/>
            <xs:element name="prompt-color" type="colorChoiceType" default="blue"/>
        </xs:sequence>
    </xs:complexType>

    <xs:simpleType name="colorChoiceType">
        <xs:annotation>
            <xs:documentation>
                The available color choices
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:enumeration value="black" />
            <xs:enumeration value="blue" />
            <xs:enumeration value="cyan" />
            <xs:enumeration value="green" />
            <xs:enumeration value="magenta" />
            <xs:enumeration value="red" />
            <xs:enumeration value="white" />
            <xs:enumeration value="yellow" />
            <xs:enumeration value="default" />
        </xs:restriction>
    </xs:simpleType>

</xs:schema>
