<?xml version="1.0" encoding="utf-8"?>

<workflow xmlns="http://eprints.org/ep3/workflow" xmlns:epc="http://eprints.org/ep3/control">
  <flow>
    <stage ref="type"/>
    <stage ref="files"/>
    <stage ref="core"/>
    <stage ref="subjects"/>
  </flow>


  <stage name="type">
    <component><field ref="type" required="yes" /></component>
  </stage>

  <stage name="files">
    <component type="XHTML"><epc:phrase ref="Plugin/InputForm/Component/Upload:help" /></component>
    <component type="Upload">
      <field ref="format" />
      <field ref="formatdesc" />
      <field ref="security" />
      <field ref="license" />
      <field ref="date_embargo" />
<!--  <field ref="language" /> --> 
    </component>
  </stage>


  <stage name="core">

    <component><field ref="title" required="yes" input_lookup_url="{$config{perl_url}}/users/lookup/title_duplicates" input_lookup_params="eprintid={eprintid}" /></component>
    <component><field ref="abstract"/></component>

    <epc:if test="type = 'monograph'">
      <component><field ref="monograph_type" required="yes" /></component>
    </epc:if>
    <epc:if test="type = 'thesis'">
      <component><field ref="thesis_type" required="yes" /></component>
    </epc:if>
    <epc:if test="type = 'conference_item'">
      <component><field ref="pres_type" required="yes" /></component>
    </epc:if>
    <epc:if test="type = 'composition'">
      <component><field ref="composition_type" required="yes" /></component>
    </epc:if>
    <epc:if test="type = 'dataset'">
      <component><field ref="data_type" required="yes" /></component>
    </epc:if>

    <epc:choose>
      <epc:when test="type.one_of('book','book_section')">
        <component><field ref="creators" input_lookup_url="{$config{perl_url}}/users/lookup/name" /></component>
        <component><field ref="corp_creators"/></component>
        <component><field ref="editors" input_lookup_url="{$config{perl_url}}/users/lookup/name" /></component>
      </epc:when>
      <epc:otherwise>
        <component><field ref="creators" required="yes" input_lookup_url="{$config{perl_url}}/users/lookup/name" /></component>
        <component><field ref="corp_creators"/></component>
      </epc:otherwise>
    </epc:choose>

    <epc:if test="type = 'exhibition'">
      <component collapse="yes"><field ref="exhibitors"/></component>
      <component><field ref="num_pieces"/></component>
    </epc:if>

    <epc:if test="type = 'composition'">
      <component collapse="yes"><field ref="producers"/></component>
      <component collapse="yes"><field ref="conductors"/></component>
      <component collapse="yes"><field ref="accompaniment"/></component>
      <component collapse="yes"><field ref="lyricists"/></component>
    </epc:if>

    <epc:if test="type = 'performance'">
      <component collapse="yes"><field ref="producers"/></component>
      <component collapse="yes"><field ref="conductors"/></component>
      <component collapse="yes"><field ref="accompaniment"/></component>
    </epc:if>

    <component><field ref="divisions" /></component>

    <component type="Field::Multi">
      <title>Publication Details</title>
      <epc:if test="type != 'patent' ">
        <epc:if test="type.one_of('book_section', 'book', 'article', 'conference_item')">
          <field ref="refereed" required="yes" />
        </epc:if>
        <epc:if test="type != 'artefact' and type != 'exhibition'">
          <field ref="ispublished" required="yes" />
        </epc:if>
      </epc:if>

      <epc:if test='type = "patent"'>
        <field ref="date" required="yes" />
        <field ref="date_type" required="yes" />
        <field ref="official_url"/>
        <field ref="patent_applicant" required="yes" />
        <field ref="id_number" required="yes" />
        <field ref="pages"/>
      </epc:if>
      <epc:if test="type = 'monograph'">
        <field ref="institution"/>
        <field ref="department"/>
        <field ref="place_of_pub"/>
        <field ref="publisher" required="yes" />
        <field ref="id_number"/>
        <field ref="pages"/>
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'book'">
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="place_of_pub"/>
        <field ref="publisher" required="yes" />
        <field ref="pages"/>
        <field ref="series"/>
        <field ref="volume"/>
        <field ref="number"/>
        <field ref="isbn"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'other'">
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
        <field ref="place_of_pub"/>
        <field ref="publisher" required="yes" />
        <field ref="id_number"/>
      </epc:if>
      <epc:if test="type = 'book_section'">
        <field ref="pagerange"/>
        <field ref="book_title" required="yes" />
        <field ref="volume"/>
        <field ref="place_of_pub"/>
        <field ref="publisher" required="yes" />
        <field ref="pages"/>
        <field ref="id_number"/>
        <field ref="series"/>
        <field ref="number"/>
        <field ref="isbn"/>
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'thesis'">
        <field ref="date" required="yes" />
        <field ref="date_type" required="yes" />
        <field ref="official_url"/>
        <field ref="institution" required="yes" />
        <field ref="department" required="yes" />
        <field ref="pages"/>
      </epc:if>
      <epc:if test="type = 'conference_item'">
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="pagerange"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'article'">
        <field ref="publication" required="yes" input_lookup_url="{$config{perl_url}}/users/lookup/journal_by_name" />
        <field ref="issn" input_lookup_url="{$config{perl_url}}/users/lookup/journal_by_issn" />
        <field ref="publisher" />
        <field ref="official_url"/>
        <field ref="volume"/>
        <field ref="number"/>
        <field ref="pagerange"/>
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="id_number"/>
      </epc:if>
      <epc:if test="type = 'artefact'">
        <field ref="output_media"/>
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'exhibition'">
        <field ref="output_media"/>
        <field ref="isbn"/>
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'composition'">
        <field ref="output_media"/>
        <field ref="publisher" />
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'performance'">
        <field ref="output_media"/>
        <field ref="publisher" />
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'image'">
        <field ref="output_media"/>
        <field ref="publisher" />
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'video'">
        <field ref="output_media"/>
        <field ref="publisher" />
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'audio'">
        <field ref="output_media"/>
        <field ref="publisher" />
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'dataset'">
        <field ref="output_media"/>
        <field ref="publisher"/>
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'experiment'">
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <epc:if test="type = 'teaching_resource'">
        <field ref="copyright_holders"/>
        <field ref="publisher"/>
        <field ref="date"/>
        <field ref="date_type"/>
        <field ref="official_url"/>
      </epc:if>
      <field ref="related_url" />
    </component>

    <component><field ref="funders" /></component>
    <component><field ref="projects" /></component>

    <epc:if test="type = 'teaching_resource'">
      <component type="Field::Multi">
        <title>Pedagogic Details</title>
        <field ref="pedagogic_type"/>
        <field ref="completion_time"/>
        <field ref="task_purpose"/>
        <field ref="skill_areas"/>
        <field ref="learning_level"/>
      </component>
    </epc:if>

    <epc:if test="type.one_of( 'exhibition', 'performance' )">
      <component type="Field::Multi">
        <title>Venue Details</title>
        <field ref="event_title" />
        <field ref="event_location"/>
        <field ref="event_dates"/>
      </component>
    </epc:if>

    <epc:if test="type = 'conference_item'">
      <component type="Field::Multi">
        <title>Event Details</title>
        <field ref="event_title" input_lookup_url="{$config{perl_url}}/users/lookup/event_by_name" required="yes" />
        <field ref="event_type" required="yes" />
        <field ref="event_location"/>
        <field ref="event_dates"/>
      </component>
    </epc:if>

    <component collapse="yes"><field ref="contact_email"/></component>
    <component collapse="yes"><field ref="referencetext"/></component>
    <component collapse="yes"><field ref="keywords"/></component>
    <component collapse="yes"><field ref="note"/></component>
    <component collapse="yes"><field ref="suggestions"/></component>

  </stage>

  <stage name="subjects">
    <component type="Field::Subject"><field ref="subjects" required="yes" /></component>
  </stage>

</workflow>
