<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="http://buildservice.org/api" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

  <include href="obs.rng" />

  <start>
    <ref name="request-element"/>
  </start>

  <define ns="" name="request-states">
    <choice>
      <value>review</value>
      <value>new</value>
      <value>accepted</value>
      <value>declined</value>
      <value>revoked</value>
      <value>superseded</value>
      <value>deleted</value>
    </choice>
  </define>

  <define ns="" name="request-state-element">
    <element name="state">
      <attribute name="name">
        <ref name="request-states" />
      </attribute>
      <optional>
	<attribute name="who">
          <data type="string" />
	</attribute>
      </optional>
      <optional>
	<attribute name="when">
          <data type="string" />
	</attribute>
      </optional>
      <optional>
	<attribute name="superseded_by">
          <data type="integer" />
	</attribute>
      </optional>
      <optional>
        <element name="comment">
          <text/>
        </element>
      </optional>
      <empty/>
    </element>
  </define>

  <define ns="" name="request-action-element">
    <element name="action">
      <attribute name="type">
        <choice>
          <value>submit</value>
          <value>delete</value>
          <value>change_devel</value>
          <value>add_role</value>
          <value>set_bugowner</value>
          <value>maintenance_incident</value>
          <value>maintenance_release</value>
          <value>group</value>
        </choice>
      </attribute>
      <interleave>
	<optional>
          <element name="source">
            <attribute name="project">
              <data type="string" />
            </attribute>
            <optional>
              <attribute name="package">
		<data type="string" />
              </attribute>
            </optional>
            <optional>
              <attribute name="rev">
		<data type="string" />
              </attribute>
            </optional>
            <empty/>
          </element>
	</optional>
	<optional>
          <element name="target">
            <attribute name="project">
              <data type="string" />
            </attribute>
            <optional>
              <attribute name="package">
		<data type="string" />
              </attribute>
            </optional>
            <optional>
              <attribute name="releaseproject">
		<data type="string" />
              </attribute>
            </optional>
            <optional>
              <attribute name="repository">
		<data type="string" />
              </attribute>
            </optional>
            <empty/>
          </element>
	</optional>
	<optional>
          <element name="person">
            <attribute name="name">
              <data type="string" />
            </attribute>
            <optional>
              <attribute name="role">
		<data type="string" />
              </attribute>
            </optional>
            <empty/>
          </element>
	</optional>
	<optional>
          <element name="group">       <!-- this refers to the user groups -->
            <attribute name="name">
              <data type="string" />
            </attribute>
            <optional>
              <attribute name="role">
		<data type="string" />
              </attribute>
            </optional>
            <empty/>
          </element>
	</optional>
	<optional>
          <oneOrMore>
            <element name="grouped">      <!-- and this refers to the famous request groups -->
              <attribute name="id">
		<data type="string" />
              </attribute>
              <empty/>
            </element>
          </oneOrMore>
	</optional>
        <optional>
          <element name="options">
            <optional>
              <element name="sourceupdate">
                <choice>
                  <value>update</value>
                  <value>noupdate</value>
                  <value>cleanup</value>
                </choice>
              </element>
            </optional>
            <optional>
              <element name="updatelink"> <!-- obsolete? -->
                <choice>
                  <value>true</value>
                  <value>false</value>
                </choice>
              </element>
            </optional>
            <optional>
              <element name="makeoriginolder">
                <choice>
                  <value>true</value>
                  <value>false</value>
                </choice>
              </element>
            </optional>
            <empty/>
          </element>
        </optional>
	<optional>
	  <element name="acceptinfo">
	    <attribute name="rev"/>
	    <attribute name="srcmd5"/>
	    <attribute name="osrcmd5"/>
	    <optional>
	      <attribute name="oproject"/>
	    </optional>
	    <optional>
	      <attribute name="opackage"/>
	    </optional>
	    <optional>
	      <attribute name="xsrcmd5"/>
	    </optional>
	    <optional>
	      <attribute name="oxsrcmd5"/>
	    </optional>
	    <empty/>
	  </element>
	</optional>
      </interleave>
      <empty/>
    </element>
  </define>

  <define ns="" name="request-element">
    <element name="request">
      <optional>
        <attribute name="id">
          <data type="string" />
        </attribute>
      </optional>
      <optional>
        <attribute name="creator">
          <data type="string" />
        </attribute>
      </optional>
      <interleave>
        <oneOrMore>
          <ref name="request-action-element" />
        </oneOrMore>
        <optional>
          <ref name="request-state-element" />
        </optional>
        <optional>
          <element name="description">
            <optional>
              <text/>
            </optional>
          </element>
        </optional>
        <optional>
          <element name="priority">
            <ref name="obs-ratings" />
          </element>
        </optional>
       <zeroOrMore>
          <element name="review">
            <attribute name="state">
              <ref name="request-states" />
            </attribute>
            <optional>
              <attribute name="by_user">
                <data type="string" />
              </attribute>
            </optional>
            <optional>
              <attribute name="by_group">
                <data type="string" />
              </attribute>
            </optional>
            <optional>
              <attribute name="by_project">
                <data type="string" />
              </attribute>
            </optional>
            <optional>
              <attribute name="by_package">
                <data type="string" />
              </attribute>
            </optional>
            <optional>
              <attribute name="who">
                <data type="string" />
              </attribute>
            </optional>
            <optional>
              <attribute name="when">
                <data type="string" />
              </attribute>
            </optional>
            <optional>
              <element name="comment">
                <text/>
              </element>
            </optional>
            <zeroOrMore>
              <element name="history">
                <attribute name="who">
                  <data type="string" />
                </attribute>
                <attribute name="when">
                  <data type="string" />
                </attribute>
                <element name="description">
                  <text/>
                </element>
                <optional>
                  <element name="comment">
                    <text/>
                  </element>
                </optional>
                <empty/>
              </element>
            </zeroOrMore>
            <empty/>
          </element>
        </zeroOrMore>
        <zeroOrMore>
          <element name="history">
            <attribute name="who">
              <data type="string" />
            </attribute>
            <attribute name="when">
              <data type="string" />
            </attribute>
            <element name="description">
              <text/>
            </element>
            <optional>
              <element name="comment">
                <text/>
              </element>
            </optional>
            <empty/>
          </element>
        </zeroOrMore>
        <optional>
          <element name="title">
            <text/>
          </element>
        </optional>
        <optional>
          <element name="accept_at">
            <text/>
          </element>
        </optional>
      </interleave>
    </element>
  </define>

</grammar>
