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

<schema
    xmlns="http://www.w3.org/2001/XMLSchema"
    xml:lang="EN"
    targetNamespace="http://msqr.us/xsd/ieat"
    xmlns:eat="http://msqr.us/xsd/ieat"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">
    
    <include schemaLocation="core.xsd"/>
    
	<element name="ui" type="eat:ui-data"/>
	
	<element name="edit" type="eat:ui-edit"/>
	
	<element name="search-results" type="eat:ui-search-results"/>
	
	<element name="session-data" type="eat:ui-session-data"/>
	
	<complexType name="ui-base">
		<attribute name="mode" type="xs:string" use="optional"/>
	</complexType>
	
	<complexType name="ui-data">
		<complexContent>
			<extension base="eat:ui-base">
				<sequence>
					<element name="search-results" type="eat:ui-search-results" minOccurs="0"/>
					<element name="meta-support" type="eat:ui-meta-support" minOccurs="0"/>
					<element name="base" type="eat:base" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="course" type="eat:course" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="difficulty" type="eat:difficulty" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="ethnicity" type="eat:ethnicity" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="ingredient" type="eat:ingredient" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="prep-time" type="eat:prep-time" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="recipe" type="eat:recipe" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="system" type="eat:system"
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="unit" type="eat:unit"
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="meal" type="eat:meal"
						minOccurs="0" maxOccurs="unbounded"/>
				</sequence>			
			</extension>
		</complexContent>
	</complexType>
	
	<complexType name="ui-edit">
		<complexContent>
			<extension base="eat:ui-base">
				<sequence>
					<element name="ingredient" type="eat:ingredient" minOccurs="0"/>
					<element name="recipe" type="eat:recipe" minOccurs="0"/>
					<element name="user" type="eat:user" minOccurs="0"/>
					<element name="meal" type="eat:meal" minOccurs="0"/>
					<element name="meal-recipe" type="eat:meal-recipe" minOccurs="0"/>
					<element name="search-results" type="eat:ui-search-results" minOccurs="0"/>
				</sequence>
				<attribute name="ignoreWarnings" type="xs:boolean" use="optional" default="false"/>
				<attribute name="refresh" type="xs:boolean" use="optional" default="false"/>
			</extension>
		</complexContent>
	</complexType>
	
	<complexType name="ui-index">
		<sequence>
			<element name="index-section" minOccurs="0" maxOccurs="unbounded">
				<complexType>
					<attribute name="index-key" type="xs:string" use="required"/>
					<attribute name="count" type="xs:int" use="optional" default="0"/>
					<attribute name="selected" type="xs:boolean" use="optional" default="false"/>
				</complexType>
			</element>
		</sequence>
	</complexType>
	
	<complexType name="recipe-search-criteria">
		<sequence>
			<element name="name" type="string" minOccurs="0"/>
			<element name="simpleQuery" type="string" minOccurs="0"/>
			<element name="ingredient" type="eat:recipe-ingredient" 
				minOccurs="0" maxOccurs="unbounded">
				<annotation><documentation>
					To search for recipes containing sets of ingredients.
				</documentation></annotation>
			</element>
			<element name="advanced" type="eat:advanced-search-criteria" 
				minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
		<attribute name="mode" type="xs:string"/>
	</complexType>
	
	<complexType name="advanced-search-criteria">
		<sequence>
			<element name="query" type="xs:string" minOccurs="0"/>
		</sequence>
		<attribute name="type" type="xs:string" use="required"/>
		<attribute name="op" type="xs:short" use="required"/>
		<attribute name="choice" type="xs:string" use="optional"/>
		<attribute name="required" type="xs:boolean" use="optional" default="false"/>
	</complexType>
	
	<complexType name="ui-search-results">
		<complexContent>
			<extension base="eat:ui-base">
				<sequence>
					<element name="ui-index" type="eat:ui-index" minOccurs="0"/>
					<element name="pagination" type="eat:ui-pagination-support" minOccurs="0"/>
					<element name="recipe-criteria" type="eat:recipe-search-criteria"
						minOccurs="0"/>
					<element name="recipe" type="eat:ui-recipe-match" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="ingredient" type="eat:ui-ingredient-match" 
						minOccurs="0" maxOccurs="unbounded"/>
					<element name="user" type="eat:ui-user-match"
						minOccurs="0" maxOccurs="unbounded"/>
				</sequence>
				<attribute name="totalResults" type="xs:int" use="required"/>
				<attribute name="pageSize" type="xs:int" use="optional"/>
				<attribute name="pageStart" type="xs:int" use="required"/>
			</extension>
		</complexContent>
	</complexType>
	
	<complexType name="ui-recipe-match" >
		<complexContent>
			<extension base="eat:recipe"/>
		</complexContent>
	</complexType>
	
	<complexType name="ui-ingredient-match" >
		<complexContent>
			<extension base="eat:ingredient"/>
		</complexContent>
	</complexType>
	
	<complexType name="ui-user-match" >
		<complexContent>
			<extension base="eat:user"/>
		</complexContent>
	</complexType>
	
	<complexType name="ui-session-data">
		<sequence>
			<element name="acting-user" type="eat:user" minOccurs="0"/>
		</sequence>
		<attribute name="admin" type="xs:boolean"/>
	</complexType>
	
	<complexType name="ui-pagination-support">
		<sequence>
			<element name="allowablePageSize" type="xs:int" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
		<attribute name="defaultPageSize" type="xs:int" use="required"/>
		<attribute name="allowUnlimited" type="xs:boolean" use="optional" default="false"/>
	</complexType>
	
	<!-- 
		A generic meta data support object for passing configuration 
		settings from the application to the front end.
	-->
	<complexType name="ui-meta-support">
		<sequence>
			<element name="meta" type="eat:ui-parameter" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<xs:complexType name="ui-parameter">
		<xs:simpleContent>
			<xs:extension base="xs:string">
				<xs:attribute name="key" type="xs:string" use="required"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>

</schema>
