<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright The WildFly Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="urn:jboss:domain:jca:1.1"
           xmlns="urn:jboss:domain:jca:1.1"
           xmlns:threads="urn:jboss:domain:threads:1.1"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="1.1">

    <xs:import namespace="urn:jboss:domain:threads:1.1" schemaLocation="jboss-as-threads_1_1.xsd"/>

    <xs:element name="subsystem" type="subsystemType"/>

    <xs:complexType name="subsystemType">
        <xs:sequence>
            <xs:element name="archive-validation"
                type="archive-validationType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Toggle archive validation for the deployment
                        units. If it's not present it's considered true
                        with default attributes.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="bean-validation"
                type="bean-validationType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Toggle bean validation (JSR-303) for the
                        deployment units. If it's not present it's
                        considered true
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="default-workmanager" type="workmanagerType" minOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        The default work manager and its thread pools
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="workmanager" type="workmanagerType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        A custom work manager definition and its thread pools
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="bootstrap-contexts" type="bootstrap-contextsType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Definition of custom bootstrap contexts
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="cached-connection-manager" type="cached-connection-managerType" minOccurs="0" maxOccurs="1"></xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="archive-validationType">
        <xs:attribute name="enabled" type="xs:boolean" default="true" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Specify whether archive validation is enabled.  Default: true
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="fail-on-error" type="xs:boolean" default="true" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Should an archive validation error report fail the deployment. Default: true
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="fail-on-warn" type="xs:boolean" default="false" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Should an archive validation warning report fail the deployment. Default: false
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="bean-validationType">
        <xs:attribute name="enabled" type="xs:boolean" use="required">
            <xs:annotation>
                <xs:documentation>
                    Specify whether bean validation is enabled.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="workmanagerType">
        <xs:all>
            <xs:element name="short-running-threads" type="thread-pool" maxOccurs="1" minOccurs="1"></xs:element>
            <xs:element name="long-running-threads" type="thread-pool" maxOccurs="1" minOccurs="0"></xs:element>
        </xs:all>
        <xs:attribute name="name" type="xs:token" use="optional">
            <xs:annotation>
                <xs:documentation>
                   Specifies the name of the work manager. Note, that custom work managers need
                   to have a name defined.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="bootstrap-contextsType">
        <xs:sequence>
            <xs:element name="bootstrap-context" type="bootstrap-contextType" maxOccurs="unbounded" minOccurs="1"></xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="bootstrap-contextType">
        <xs:attribute name="name" type="xs:token" use="required">
            <xs:annotation>
                <xs:documentation>
                   Specifies the name of the bootstrap context.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="workmanager" type="xs:token" use="required">
            <xs:annotation>
                <xs:documentation>
                   Specifies the name of the work manager to use for this context.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="cached-connection-managerType">
        <xs:attribute name="debug" type="xs:boolean" use="optional"></xs:attribute>
        <xs:attribute name="error" type="xs:boolean" use="optional"></xs:attribute>
    </xs:complexType>

     <xs:complexType name="thread-pool">
        <xs:annotation>
            <xs:documentation>
            <![CDATA[
                See threads:blocking-bounded-queue-thread-pool.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="core-threads" type="threads:countType" minOccurs="0"/>
            <xs:element name="queue-length" type="threads:countType"/>
            <xs:element name="max-threads" type="threads:countType"/>
            <xs:element name="keepalive-time" type="threads:time" minOccurs="0"/>
            <xs:element name="thread-factory" type="threads:ref" minOccurs="0"/>
        </xs:all>
        <xs:attribute name="allow-core-timeout" use="optional" type="xs:boolean"/>
    </xs:complexType>
</xs:schema>
