<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">


    <xsd:complexType name="groups-type">
    	<xsd:sequence maxOccurs="unbounded" minOccurs="0">
    		<xsd:element name="group" type="group-type">
   				<xsd:unique name="memberGroupGuid">
		    		<xsd:selector xpath="./member-group" />
		    		<xsd:field xpath="@guid" />
   				</xsd:unique>
		    	<xsd:unique name="memberUserLogin">
		    		<xsd:selector xpath="./member-user" />
		    		<xsd:field xpath="@login" />
		    	</xsd:unique>
		    	<xsd:unique name="adminUserLogin">
		    		<xsd:selector xpath="./group-admin" />
		    		<xsd:field xpath="@login" />
		    	</xsd:unique>
    		</xsd:element>
    	</xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="group-type">
    	<xsd:sequence minOccurs="0" maxOccurs="unbounded">
    		<xsd:choice>
    			<xsd:element name="group-admin"
    				type="member-user-type">
    			</xsd:element>
    			<xsd:element name="member-user"
    				type="member-user-type">
    			</xsd:element>
    			<xsd:element name="member-group"
    				type="member-group-type">
    			</xsd:element>
    		</xsd:choice>
    	</xsd:sequence>
    	<xsd:attribute name="guid" type="xsd:token" use="required">
    		<xsd:annotation>
    			<xsd:documentation>ID for group that is unique across all groups.</xsd:documentation>
    		</xsd:annotation></xsd:attribute>
    	<xsd:attribute name="title" type="xsd:normalizedString"
    		use="required">
            <xsd:annotation>
            	<xsd:documentation>Human readable title for the group, not necessarily unique.</xsd:documentation>
            </xsd:annotation>
    	</xsd:attribute>
    	<xsd:attribute name="description" type="xsd:string"
    		use="optional">
    	</xsd:attribute>
    	<xsd:attribute name="allow-associate-with-reviews"
    		type="xsd:boolean" use="optional">
    	</xsd:attribute>
    	<xsd:attribute name="includes-all-users" type="xsd:boolean"
    		use="optional">
    	</xsd:attribute>
    	<xsd:attribute name="enabled" type="xsd:boolean"
    		use="optional">
    	</xsd:attribute>
    	<xsd:attribute name="review-pool" type="xsd:boolean"
    		use="optional">
    	</xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="member-group-type">
    	<xsd:attribute name="guid" type="xsd:token" use="required">
    		<xsd:annotation>
    			<xsd:documentation>GUID of group that is a member of the enclosing group.</xsd:documentation>
    		</xsd:annotation></xsd:attribute>
    </xsd:complexType>
    
    <xsd:complexType name="member-user-type">
    	<xsd:attribute name="login" type="xsd:token" use="required">
    		<xsd:annotation>
    			<xsd:documentation>Login of user that is a member of enclosing group.</xsd:documentation>
    		</xsd:annotation></xsd:attribute>
    </xsd:complexType>
    
    <xsd:element name="groups" type="groups-type">
    	<xsd:key name="groupGuid">
    		<xsd:selector xpath="./group" />
    		<xsd:field xpath="@guid" />
    	</xsd:key>
		<xsd:keyref name="memberGroupGuidRef" refer="groupGuid">
	   		<xsd:selector xpath="./group/member-group" />
	   		<xsd:field xpath="@guid" />
		</xsd:keyref>
    </xsd:element>
</xsd:schema>
