<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:include schemaLocation="Core.xsd"></xs:include>
    <xs:element name="ProjectLinks" type="typeProjectLinks">
        <xs:annotation>
            <xs:documentation>
                Project IDs may be related to other project IDs by Links (Hierarchical or PeerProject) or by Groups. 
            </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:complexType name="typeProjectLinks"><xs:annotation>
        <xs:documentation>
            Project IDs may be related to other project IDs by Links (Hierarchical or PeerProject) or by Groups. 
        </xs:documentation>
    </xs:annotation>
        <xs:sequence>
            <xs:element name='Link' type="typeProjectLink" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="Group" minOccurs="0" maxOccurs="unbounded" type="typeProjectGroup">
                <xs:annotation>
                    <xs:documentation>An adhoc list of project IDs that are logically related in some manner.  
                        Groups provide a means to support retrieval and display for corner cases that are 
                        not otherwise supported by direct links (hierarchical or peer) or by available database indexing/query retrieval support.
                        Any archive database may assert a group without any ownership restriction (of the project).
                        Archives may opt to validate asserted groups and may opt to either accept for display or not.
                        Groups can include submitter-level projects (any project type) and/or administrative projects
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="typeLinkID">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="archive" type="typeArchive" use="optional">
                </xs:attribute>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>                            
        <xs:complexType name="typeProjectLink">
            <xs:sequence>
                <xs:element name="ProjectIDRef" type="typeArchiveID">
                    <xs:annotation>
                        <xs:documentation>
                            Reference to project where links originate. Links direction is always from lower level project to the higher level project. 
                            This element is a lower level part.
                            Example: child in a hierarchical relationship; parasite in a parasite-host relationship.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:choice>
                    <xs:element name='Hierarchical' maxOccurs="unbounded">
                        <xs:annotation><xs:documentation>
                            Vertical Hierarchical relationship, project points to the administrative top members (Top Single or Top Miltiple, depending on "type" attribute).
                            In a directional link between lower level and higher level projects this element is a higher level part.
                        </xs:documentation></xs:annotation>
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name='MemberID' type="typeArchiveID" minOccurs="1" maxOccurs="unbounded">
                                    <xs:annotation><xs:documentation>Member projects of a group - list archive ids</xs:documentation></xs:annotation>
                                </xs:element>                            
                            </xs:sequence>
                            <xs:attribute name='type' use="required">
                                <xs:annotation><xs:documentation>It is possible to name this relationship when needed</xs:documentation></xs:annotation>
                                <xs:simpleType>
                                    <xs:restriction base="xs:token">
                                        <xs:enumeration value="TopSingle">
                                        </xs:enumeration>
                                        <xs:enumeration value="TopAdmin">
                                        </xs:enumeration>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:attribute>
                        </xs:complexType>
                    </xs:element>
                    <xs:element name='PeerProject' maxOccurs="unbounded">
                        <xs:annotation><xs:documentation>
                            Pairwise peer-to-peer relationship for the project; Hierarchical restrictions do not apply.
                            In a directional link between lower level and higher level projects this element is a higher level part.
                            Example: host in a parasite-host relationship.
                        </xs:documentation></xs:annotation>
                        <xs:complexType>
                            <xs:sequence>
                                <xs:choice>
                                    <xs:element name="BioticRelationship">
                                        <xs:simpleType>
                                            <xs:restriction base="xs:token">
                                                <xs:enumeration value="eCommensal">
                                                </xs:enumeration>
                                                <xs:enumeration value="eParasitic">
                                                </xs:enumeration>
                                                <xs:enumeration value="eSymbiotic">
                                                </xs:enumeration>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:element>
                                    <xs:element name="CommonInputData">
                                        <xs:simpleType>
                                            <xs:restriction base="xs:token">
                                                <xs:enumeration value="eRefseqGenbank">
                                                </xs:enumeration>
                                                <xs:enumeration value="eSameSample">
                                                </xs:enumeration>
                                                <xs:enumeration value="eTopAdminTopSingleOrganism"></xs:enumeration>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:element>
                                </xs:choice>
                                <xs:element type="typeArchiveID" name="MemberID">
                                </xs:element>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:choice>
                <xs:element type="typeLinkID" name="ID" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>
                            ID (archive name as an attribute and unique across this archive accession as an element value) created by archive.
                            Identifies group itself but not projects included in the group.
                            TGR- Perhaps explain how this is different than ProjectIDRef.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="LinkExplanation" minOccurs="0" type="xs:string">
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    <xs:complexType name="typeProjectGroup">
        <xs:sequence>
            <xs:element name="ProjectIDRef" maxOccurs="unbounded" minOccurs="0" type="typeArchiveID">
                <xs:annotation>
                    <xs:documentation>
                        Reference to project that included in the group
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="typeLinkID" name="ID" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        ID created by archive
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Description" minOccurs="0" type="xs:string">
            </xs:element>
        </xs:sequence>
        <xs:attribute name="groupType" use="required">
            <xs:annotation>
                <xs:documentation>
                    Group type is a controlled vocabulary. Corresponds to GroupTyypes.abbr in the DB.
                </xs:documentation>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:token">
                    <xs:enumeration value="eComparativeGenomics">
                    </xs:enumeration>
                    <xs:enumeration value="eOther">
                    </xs:enumeration>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="label" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>
                    Short text that displayd in the presentation.
                    TGR - add descriptive text - how is it different than Description.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
</xs:schema>