<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.HopAndVineHull.co.uk/DynamicData"
           xmlns:dd="http://www.HopAndVineHull.co.uk/DynamicData" 
           attributeFormDefault="unqualified" 
           elementFormDefault="qualified">
           
  <!-- Root Element -->
  <xs:element name="HopAndVine" type="dd:HopAndVineType">
    <xs:unique name="ProductId">
      <xs:selector xpath="dd:Cellar/dd:Beer|dd:Cellar/dd:Cider"/>
      <xs:field xpath="@Id"/>
    </xs:unique>
  </xs:element>
  
	
  <!-- Complex Type Definitions -->
	<xs:complexType name="HopAndVineType">
		<xs:sequence>
      
      <!-- C E L L A R -->
      <xs:element name="Cellar"   type="dd:CellarType"  minOccurs="1" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>
            Lists the products (beers and ciders) that are on sale now and those that are
            in the cellar waiting to go on sale.
          </xs:documentation>
        </xs:annotation>
      </xs:element>

      <!-- K I T C H E N -->
      <xs:element name="Kitchen"  type="dd:KitchenType" minOccurs="1" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>
            Lists the daily specials from the kitchen, the soup(s) of the day and what breads 
            are available.
          </xs:documentation>
        </xs:annotation>
      </xs:element>

      <!-- H I S T O R Y -->
      <xs:element name="History"  type="dd:HistoryType" minOccurs="0" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>
            Each beer or cider that has been on sale (including those currently on sale)
            grouped by the brewery (or farm) that nakes them.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      
		</xs:sequence>
	</xs:complexType>
	

	<!-- C E L L A R -->
	<xs:complexType name="CellarType">
		<xs:choice minOccurs="0" maxOccurs="unbounded">
			<xs:element name="Beer" type="dd:ProductType"/>
      <xs:element name="Cider" type="dd:ProductType"/>
    </xs:choice>
    <xs:attribute name="DifferentBeersCount"  type="xs:nonNegativeInteger" use="optional"/>
    <xs:attribute name="DifferentCidersCount" type="xs:nonNegativeInteger" use="optional"/>
  </xs:complexType>

	<xs:complexType name="ProductType">
		<xs:sequence>
			<xs:element name="Brewery"  type="dd:BreweryType"/>
			<xs:element name="Beer"     type="xs:string"/>
			<xs:element name="ABV"      type="dd:ABVType" />
			<xs:element name="Price"    type="dd:PriceType" />
		</xs:sequence>
    
    <xs:attribute name="Status" type="dd:StatusType" use="required" >
      <xs:annotation>
        <xs:documentation>
          The possible statuses are "On Tap", "On Next" and "In The Cellar". On next
          is a beer that is in the cellar but will be the next to go on sale. The
          "Run Out" status will not be seen (it is used by the Data Update Application
          to let the site know that a product has come off sale).
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>

    <xs:attribute name="Id" type="xs:nonNegativeInteger" use="optional">
      <xs:annotation>
        <xs:documentation>
          Internal unique identifier for each product that has gone on sale, products
          with statuses "In The Cellar" and "On Next" do not have an Id attribute 
          applied.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>

    <xs:attribute name="Seen" type="dd:StatusType" use="optional">
      <xs:annotation>
        <xs:documentation>
          This attribute is for internal use. It will always have the same value as
          the Status attribute. It is used by the Data Update Application to signify
          the original status of the product before the update.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>

  </xs:complexType>

  <xs:complexType name="BreweryType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="Location"  type="xs:string" use="optional"/>
        <xs:attribute name="URL"  type="xs:anyURI" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  
  <!-- K I T C H E N -->
	<xs:complexType name="KitchenType">
		<xs:sequence>
			<xs:element name="Soups"     minOccurs="0" type="dd:SoupsType"    />
      <xs:element name="Specials"  minOccurs="0" type="dd:SpecialsType" />
			<xs:element name="Breads"    minOccurs="0" type="dd:BreadsType"   />
		</xs:sequence>
	</xs:complexType>

	<!-- Soups -->
  <xs:complexType name="SoupsType">
    <xs:sequence>
      <xs:element name="Soup" type="dd:SoupType" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="SoupType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="Title" type="xs:string" use="required"/>
        <xs:attribute name="Price" type="dd:PriceType" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <!-- Specials -->
  <xs:complexType name="SpecialsType">
    <xs:sequence>
      <xs:element name="Special" type="dd:SpecialType" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="SpecialType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="Title" type="xs:string" use="optional"/>
        <xs:attribute name="Price" type="dd:PriceType" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <!-- Breads -->
  <xs:complexType name="BreadsType">
		<xs:sequence>
			<xs:element name="Bread" type="dd:BreadType" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

  <xs:complexType name="BreadType">
		<xs:simpleContent>
			<xs:extension base="xs:string">
        <xs:attribute name="Availability" use="optional">
          <xs:annotation>
            <xs:documentation>
              All bread recipies are listed, only those breads that are currently
              on sale have the Availability="Available" attribute applied.
            </xs:documentation>
          </xs:annotation>
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="Available"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  
  <!-- H I S T O R Y -->
  <xs:complexType name="HistoryType">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="Maker" minOccurs="0" type="dd:MakerType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="MakerType">
    <xs:sequence>
      <xs:element name="Product" maxOccurs="unbounded" type="dd:HistoryProductType"/>
    </xs:sequence>
    <xs:attribute name="Name"     type="xs:string" />
    <xs:attribute name="Location" type="xs:string" />
    <xs:attribute name="URL"      type="xs:string" />
  </xs:complexType>

  <xs:complexType name="HistoryProductType">
    <xs:attribute name="Name"  type="xs:string"    use="required"/>
    <xs:attribute name="ABV"   type="dd:ABVType"   use="optional"/>
    <xs:attribute name="Price" type="dd:PriceType" use="optional"/>
  </xs:complexType>

  
  <!-- Simple Type Definitions -->

  <xs:simpleType name="ABVType">
    <xs:restriction base="xs:decimal">
      <xs:fractionDigits value="2"/>
      <xs:maxInclusive value="9.9"/>
      <xs:minExclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="PriceType">
    <xs:restriction base="xs:decimal">
      <xs:fractionDigits value="2"/>
      <xs:maxInclusive value="99.99"/>
      <xs:minExclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="StatusType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="In The Cellar"/>
      <xs:enumeration value="On Next"/>
      <xs:enumeration value="On Tap"/>
      <xs:enumeration value="Run Out"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>