<?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:ejb3:1.1"
           xmlns="urn:jboss:domain:ejb3:1.1"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="1.1">

    <!-- The ejb3 subsystem root element -->
    <xs:element name="subsystem" type="ejb3-subsystemType"/>

    <xs:complexType name="ejb3-subsystemType">
        <xs:annotation>
            <xs:documentation>
                EJB3 subsystem configurations
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="mdb" type="mdbType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="session-bean" type="session-beanType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="pools" type="poolsType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="timer-service" type="timerServiceType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
        <xs:attribute name="lite" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="mdbType">
        <xs:all>
            <xs:element name="resource-adapter-ref" type="resource-adapter-refType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="bean-instance-pool-ref" type="bean-instance-pool-refType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="session-beanType">
        <xs:all>
            <xs:element name="stateless" type="stateless-beanType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="stateless-beanType">
        <xs:all>
            <xs:element name="bean-instance-pool-ref" type="bean-instance-pool-refType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="resource-adapter-refType">
        <xs:attribute name="resource-adapter-name" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="bean-instance-pool-refType">
        <xs:attribute name="pool-name" use="required" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="poolsType">
        <xs:all>
            <xs:element name="bean-instance-pools" type="bean-instance-poolsType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="bean-instance-poolsType">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="strict-max-pool" type="strict-max-poolType"/>
        </xs:choice>
    </xs:complexType>

    <xs:complexType name="strict-max-poolType">
        <xs:attribute name="name" type="xs:string" use="required"/>
        <xs:attribute name="max-pool-size" type="xs:positiveInteger" default="20" use="optional"/>
        <xs:attribute name="instance-acquisition-timeout" type="xs:positiveInteger" default="5" use="optional"/>
        <xs:attribute name="instance-acquisition-timeout-unit" type="instance-acquisition-timeout-unitType"
                      default="MINUTES" use="optional"/>
    </xs:complexType>

    <xs:simpleType name="instance-acquisition-timeout-unitType">
        <xs:annotation>
            <xs:documentation>
                TimeUnit that are allowed for instance-acquisition-timeout on a pool
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:token">
            <xs:enumeration value="HOURS"/>
            <xs:enumeration value="MINUTES"/>
            <xs:enumeration value="SECONDS"/>
            <xs:enumeration value="MILLISECONDS"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="timerServiceType">
        <xs:sequence>
            <xs:element name="thread-pool" type="threadPoolType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="data-store" type="dataStoreType" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="threadPoolType">
        <xs:attribute name="core-threads" type="xs:int">
            <xs:annotation>
                <xs:documentation>
                    The number of threads that the the thread pool will keep alive. Defaults to 0.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="max-threads" type="xs:int">
            <xs:annotation>
                <xs:documentation>
                    The maximum number of threads that will be used to run timer service tasks. Defaults to the
                    number of processes as returned by Runtime.availableProcessors()
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="dataStoreType">
        <xs:attribute name="path" type="xs:string" />
        <xs:attribute name="relative-to" type="xs:string" />
    </xs:complexType>

</xs:schema>
