<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://namespace.openaire.eu/oaf"
  targetNamespace="http://namespace.openaire.eu/oaf" elementFormDefault="unqualified">

  <xs:annotation>
    <xs:documentation>This schema describes elements and properties of OpenAIRE+ entities of type
      project</xs:documentation>
  </xs:annotation>

  <xs:include schemaLocation="oaf-common-0.1.xsd"/>

  <xs:element name="project">
    <xs:complexType>
      <xs:choice maxOccurs="unbounded">
        <xs:element name="code" type="xs:string">
          <xs:annotation>
            <xs:documentation>Project code. In case of EC funded project, it contains the grant
              agreement identifier.</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element name="acronym" type="xs:string"/>
        <xs:element name="title" type="xs:string"/>
        <xs:element name="startdate" type="xs:string"/>
        <xs:element name="enddate" type="xs:string"/>
        <xs:element name="callidentifier" type="xs:string"/>
        <xs:element name="ecsc39" type="xs:boolean">
          <xs:annotation>
            <xs:documentation>True if the project has the special clause 39.</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element name="contracttype" type="optionalClassedSchemedElement"/>

        <xs:element name="fundingtree" type="fundingTreeType">
          <xs:annotation>
            <xs:documentation>The funding tree contains information about the funding of this
              project. For EC funded projects the tree has the following form: Scientific Area --
              Funding Stream -- Funder. For UK funded projects the tree has the following form:
              Funder -- Funding Stream. </xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element name="websiteurl" type="xs:string"/>
        <xs:element name="keywords" type="xs:string"/>
        <xs:element name="duration" type="xs:string"/>

        <xs:element name="originalId" type="xs:string"/>
        <xs:element name="collectedfrom" type="namedIdElement">
          <xs:annotation>
            <xs:documentation>Identifier and name of the datasource from which this project has been
              collected from.</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element name="pid" type="xs:string"/>
        <xs:element name="datainfo" type="datainfoType"/>
        <xs:element name="rels" type="relsType">
          <xs:annotation>
            <xs:documentation>Relationships to other entities.</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element name="children">
          <xs:complexType mixed="true"/>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>

  <!-- to be removed, and replaced by ContextType -->
  <xs:complexType name="fundingTreeType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="funding_level_2" type="fundingType" minOccurs="0" maxOccurs="unbounded">
        <xs:annotation>
          <xs:documentation>Leaf of the funding tree for FP7 projects. This element does not exist
            for WT funded projects.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <!-- WT hierarchy starts from funding_level_1, not 2 -->
      <xs:element name="funding_level_1" type="fundingType" minOccurs="0" maxOccurs="unbounded">
        <xs:annotation>
          <xs:documentation>Leaf of the funding tree for WT projects.</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="fundingType">
    <xs:sequence>
      <xs:element name="id" type="xs:string"/>
      <xs:element name="description" type="xs:string"/>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="parent" type="fundingParentType">
        <xs:annotation>
          <xs:documentation>Parent funding. If the current funding is a Scientific Area, then the
            parent is a Funding Stream. If the current funding is a Funding Stream, then the parent
            is the Funder. </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="class" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="fundingParentType">
    <xs:choice minOccurs="0">
      <xs:element name="funding_level_1" type="fundingType"/>
      <xs:element name="funding_level_0" type="fundingType"/>
    </xs:choice>
  </xs:complexType>

</xs:schema>
