<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2012 Social History Services
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this stagingfile except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions aNnd
  ~ limitations under the License.

  This file does not contain system entities. Hence it is suitable for external use for those who need a schema
  for their instruction.
  -->

<xs:schema
        attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://objectrepository.org/instruction/1.0/"
        xmlns:tns="http://objectrepository.org/instruction/1.0/">

    <xs:element name="instruction" type="tns:InstructionType">
        <xs:annotation>
            <xs:documentation xml:lang="en">The document main element. It contains global attributes that apply to the
                declared stagingfiles. A similar setting in a stagingfile, overrules a global setting.
            </xs:documentation>
        </xs:annotation>
    </xs:element>

    <xs:complexType name="InstructionType">
        <xs:sequence>
            <xs:element name="stagingfile" type="tns:stagingfileType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="plan">
            <xs:annotation>
                <xs:documentation xml:lang="en">plan : A list of comma separated services that are to be invoked. These
                    are: StagingfileIngestMaster, StagingFileBindPIDs, StagingfileIngestLevel1, StagingfileIngestLevel2,
                    StagingfileIngestLevel3
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="label">
            <xs:annotation>
                <xs:documentation xml:lang="en">label : An alias for the root folder's name.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="autoGeneratePIDs">
            <xs:annotation>
                <xs:documentation xml:lang="en">autoGeneratePIDs : used for creation of PIDs in an automatic instruction
                    build. 'none' will apply no policy. 'uuid' will add
                    persistent identifier values to an
                    empty pid element using UUID. 'filename' will substitute an empty PID element with the filename
                    without suffix.
                    A 'lid' value will ignore an empty PID setting.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="autoIngestValidInstruction" type="xs:boolean">
            <xs:annotation>
                <xs:documentation xml:lang="en">autoIngestValidInstruction : This will trigger
                    the automatic ingest of a valid instruction
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="resolverBaseUrl">
            <xs:annotation>
                <xs:documentation xml:lang="en">resolverBaseUrl : The base URL of the resolver. At the OR jump
                    off page this is prefixed to the PID.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="contentType">
            <xs:annotation>
                <xs:documentation xml:lang="en">contentType : mimetype</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="access">
            <xs:annotation>
                <xs:documentation xml:lang="en">access : determines which access policy to apply
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="action">
            <xs:annotation>
                <xs:documentation xml:lang="en">action : how to treat the file.
                </xs:documentation>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="add"/>
                    <xs:enumeration value="update"/>
                    <xs:enumeration value="upsert"/>
                    <xs:enumeration value="delete"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute type="xs:string" name="pidwebserviceEndpoint">
            <xs:annotation>
                <xs:documentation xml:lang="en">pidwebserviceEndpoint : pid webservice endpoint or url
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute type="xs:string" name="pidwebserviceKey">
            <xs:annotation>
                <xs:documentation xml:lang="en">pidwebserviceKey : pid webservice key (36 size UUID)</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute type="xs:string" name="objid">
            <xs:annotation>
                <xs:documentation xml:lang="en">objid: the METS object identifier where this file and it's
                    derivatives will belong to. It must be a persistent identifier without the resolve URL.
                    For example: prefix/identifier like 12345/my.mets.pid
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute type="xs:string" name="deleteCompletedInstruction">
            <xs:annotation>
                <xs:documentation xml:lang="en">deleteCompletedInstruction: true or false. Removes the instruction
                    if it completed without errors.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute type="xs:string" name="replaceExistingDerivatives">
            <xs:annotation>
                <xs:documentation xml:lang="en">replaceExistingDerivatives: true or false. If the plan is set to
                    create derivatives, the value true will replace any preexisting derivatives. If false any
                    preexisting derivatives will not be replaced.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute type="xs:string" name="pdfLevel">
            <xs:annotation>
                <xs:documentation xml:lang="en">pdfLevel: true or false. De derivative level to be used when rendering a
                    pdf.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="stagingfileType">
        <xs:all>
            <xs:element name="action" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">action : See the access element description.
                    </xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="add"/>
                        <xs:enumeration value="update"/>
                        <xs:enumeration value="upsert"/>
                        <xs:enumeration value="delete"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element type="xs:string" name="pid" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">pid : the persistent identifier without the resolver
                        server Url.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:string" name="lid" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">lid : the local identifier of the stagingfile.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:string" name="location" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">location : The stagingfile's name; or the absolute path and
                        stagingfile's name.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:string" name="md5" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">md5 : MD5 checksum of the stagingfile specified in the location
                        element. Left trailing zero's may be skipped.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:string" name="contentType" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">contentType : The content type of the filestream.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:string" name="access" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">access : Indicates if the resource is available
                        to the public.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:string" name="embargo" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">embargo : embargo: The embargo date (YYYY-MM-DD).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:string" name="embargoAccess" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">embargoAccess: The embargoAccess to be applied then the embargo date
                        is in effect.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:string" name="objid" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">objid: the METS object identifier where this file and it's
                        derivatives will belong to. It must be a persistent identifier without the resolve URL.
                        For example: prefix/identifier like 12345/my.file.pid
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="xs:int" name="seq" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">seq: the physical order of this file in a collection of files.
                        For example where the file is part of a book. When omitted the seq value will be that of the
                        position of the file in the instruction.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:all>
    </xs:complexType>

</xs:schema>