<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    >
  <!-- More accurate information - 
       https://wiki.galaxyproject.org/ToolDependenciesTagSets

       TODO: fill in a lot more information - everything below package,
       set environment things, etc...
  -->
  <xs:annotation>
    <xs:appinfo>Tool Shed tool_dependencies.xml Schema</xs:appinfo>
    <xs:documentation xml:lang="en">Describes dependencies for a tool shed repository.</xs:documentation>
  </xs:annotation>

  <xs:complexType name="ToolDependency">
    <xs:annotation>
      <xs:documentation xml:lang="en">Collection of package definitions. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="package" type="Package"/>
        <xs:element name="set_environment" type="SetEnvironment" />
      </xs:choice>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Package">
    <xs:annotation>
      <xs:documentation xml:lang="en">A package is a type of tool dependency and the combination of the name and version provide a unique identifier for it. It can contain any number of &lt;repository&gt; tag.</xs:documentation>
    </xs:annotation>
    <xs:all>
      <xs:element name="install" type="Install" minOccurs="0" />
      <xs:element name="repository" type="Repository" minOccurs="0" />
      <xs:element name="readme" type="Readme" minOccurs="0" maxOccurs="1" />
    </xs:all>
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation xml:lang="en">Package name</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="version" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation xml:lang="en">Package version</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="Install">
    <xs:annotation>
      <xs:documentation xml:lang="en"></xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:choice>
        <xs:element name="actions_group" type="ActionGroup" maxOccurs="1" />
        <xs:element name="actions" type="Actions" maxOccurs="1" />
      </xs:choice>
    </xs:sequence>
    <!-- TODO: enforce version must be absent or 1.0 -->
    <xs:attribute name="version" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation xml:lang="en">Package version</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="ActionGroup">
    <xs:annotation>
      <xs:documentation xml:lang="en"></xs:documentation>
    </xs:annotation>
    <xs:choice minOccurs="1" maxOccurs="unbounded">
      <xs:element name="actions" type="ActionGroupActions"/>
      <xs:element name="action" type="Action" />
    </xs:choice>
  </xs:complexType>

  <!-- actions element within actions_group -->
  <xs:complexType name="ActionGroupActions">
    <xs:annotation>
      <xs:documentation xml:lang="en"></xs:documentation>
    </xs:annotation>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="action" type="Action"/>
      <xs:element name="package" type="Package"/>
    </xs:choice>
    <xs:attribute name="os" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation xml:lang="en"></xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="architecture" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation xml:lang="en"></xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <!-- actions element on its own -->
  <xs:complexType name="Actions">
    <xs:annotation>
      <xs:documentation xml:lang="en"></xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="action" type="Action" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Action" mixed="true">
    <xs:annotation>
      <xs:documentation xml:lang="en"></xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:anyAttribute processContents="lax" />
  </xs:complexType>

  <xs:complexType name="Repository">
    <xs:annotation>
      <xs:documentation xml:lang="en"></xs:documentation>
    </xs:annotation>
    <xs:sequence>
    </xs:sequence>
    <xs:attribute name="toolshed" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation xml:lang="en">ToolShed URL, leave empty in source control and ToolShd will populate this automatically.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation xml:lang="en">Name of repository</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="owner" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation xml:lang="en">Owner of repository</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <!-- TODO: probably can do stronger typing here... -->
    <xs:attribute name="changeset_revision" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation xml:lang="en">Changeset revision</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <!-- TODO: can do stronger typing here... -->
    <xs:attribute name="prior_installation_required" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation xml:lang="en">Changeset revision</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="Readme">
    <xs:annotation>
      <xs:documentation xml:lang="en"></xs:documentation>
    </xs:annotation>
    <xs:simpleContent>
      <xs:extension base="xs:string">
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:complexType name="SetEnvironment">
    <!-- TODO: enforce version must be absent or 1.0 -->
    <xs:sequence>
      <xs:element name="environment_variable" type="EnvironmentVariable" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="version" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation xml:lang="en">Implementation version (must be 1.0)</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="EnvironmentVariable">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="name" type="xs:string" use="required" />
        <xs:attribute name="action" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:element name="tool_dependency" type="ToolDependency" />
</xs:schema>