<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="query">
        <xs:complexType>
            <xs:choice>
                <xs:element name="fields" type="fields" />
                <xs:element name="field" type="field" />
            </xs:choice>
            <xs:attribute name="table" type="table" use="required" />
            <xs:attribute name="select" type="select" use="optional"
                default="*" />
            <xs:attribute name="order" type="xs:string"
                use="optional" />
            <xs:attribute name="asc" type="xs:boolean" use="optional"
                default="false" />
            <xs:attribute name="page" type="xs:integer"
                use="optional" default="1" />
            <xs:attribute name="size" type="xs:integer"
                use="optional" default="20" />
        </xs:complexType>
    </xs:element>
    <xs:complexType name="fields">
        <xs:sequence>
            <xs:element name="fields" type="fields"
                minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="field" type="field" minOccurs="1"
                maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="logic" type="logic" use="required" />
    </xs:complexType>
    <xs:complexType name="field">
        <xs:attribute name="name" type="xs:string" use="required" />
        <xs:attribute name="operator" type="operator" use="required" />
        <xs:attribute name="value" type="xs:string" use="required" />
    </xs:complexType>
    <xs:simpleType name="table">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Bug" />
            <xs:enumeration value="Case" />
            <xs:enumeration value="Result" />
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="select">
        <xs:restriction base="xs:string">
            <xs:enumeration value="*" />
            <xs:enumeration value="count(*)" />
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="logic">
        <xs:restriction base="xs:string">
            <xs:enumeration value="OR" />
            <xs:enumeration value="AND" />
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="operator">
        <xs:restriction base="xs:string">
            <xs:enumeration value="BETWEEN" />
            <xs:enumeration value="GT" />
            <xs:enumeration value="LT" />
            <xs:enumeration value="GE" />
            <xs:enumeration value="LE" />
            <xs:enumeration value="EQ" />
            <xs:enumeration value="NEQ" />
            <xs:enumeration value="LIKE" />
            <xs:enumeration value="NOTLIKE" />
            <xs:enumeration value="IN" />
            <xs:enumeration value="NOTIN" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>