﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ProductIntegration"
    targetNamespace="http://www.hubsta.co.nz/schemas/xmlproductfeed"
    elementFormDefault="qualified"
    xmlns="http://www.hubsta.co.nz/schemas/xmlproductfeed"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>


  <xs:element name="ProductImportBatch" type="ProductImportBatch">
  </xs:element>

  <!-- Root Element - Contains meta info regarding feed -->
  <xs:complexType name="ProductImportBatch">
    <xs:sequence>
      <xs:element name="Products" type="ProductList" minOccurs="1" maxOccurs="1" />
      <xs:element name="Skus" type="SkuList" minOccurs="0" maxOccurs="1"/>
      <xs:element name="Images" type="ImageList" minOccurs="1" maxOccurs="1" />
    </xs:sequence>
    <xs:attribute name="SupplierID" type="xs:int" use="required" />
    <xs:attribute name="DateGenerated" type="xs:dateTime" use="required" />
  </xs:complexType>

  <xs:complexType name="ProductList">
    <xs:sequence>
      <xs:element name="Product" type="Product" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <!-- Product element - contains product-level information. Each product is unique via its Sku -->
  <xs:complexType name="Product">
    <xs:attribute name="Name" type="ProductName" use="required"></xs:attribute>
    <xs:attribute name="Sku" type="SkuCode" use="required"></xs:attribute>
    <xs:attribute name="Description" type="xs:string" use="required" />
    <xs:attribute name="QuantityOnHand" type="Quantity" use="required" />
    <xs:attribute name="RRP" type="Price" use="required" />
    <xs:attribute name="SalePrice" type="Price" use="optional" />
    <xs:attribute name="DailyDealsPrice" type="Price" use="optional" />    
    <xs:attribute name="Category1" type="xs:string" use="required"  />
    <xs:attribute name="Category2" type="xs:string" use="optional"  />
    <xs:attribute name="Category3" type="xs:string" use="optional"  />
    <xs:attribute name="Category4" type="xs:string" use="optional"  />
    <xs:attribute name="Category5" type="xs:string" use="optional"  />
    <xs:attribute name="Category6" type="xs:string" use="optional"  />
    <xs:attribute name="Brand" type="xs:string" use="optional"/>
    <xs:attribute name="FreightAuckland" type="Freight" use="required" />
    <xs:attribute name="FreightUpperNorthIsland" type="Freight" use="required" />
    <xs:attribute name="FreightCentralNorthIsland" type="Freight" use="required" />
    <xs:attribute name="FreightSouthofTaupoToWellington" type="Freight" use="required" />
    <xs:attribute name="FreightUpperSouthIsland" type="Freight" use="required" />
    <xs:attribute name="FreightChristchurch" type="Freight" use="required" />
    <xs:attribute name="FreightSouthofChristchurch" type="Freight" use="required" />
    <xs:attribute name="FreightSurchargeAuckland" type="Freight" use="optional" />
    <xs:attribute name="FreightSurchargeUpperNorthIsland" type="Freight" use="optional" />
    <xs:attribute name="FreightSurchargeCentralNorthIsland" type="Freight" use="optional" />
    <xs:attribute name="FreightSurchargeSouthofTaupoToWellington" type="Freight" use="optional" />
    <xs:attribute name="FreightSurchargeUpperSouthIsland" type="Freight" use="optional" />
    <xs:attribute name="FreightSurchargeChristchurch" type="Freight" use="optional" />
    <xs:attribute name="FreightSurchargeSouthofChristchurch" type="Freight" use="optional" />

    <xs:attribute name="DeliveryTimeFrame" type="xs:string" use="optional"></xs:attribute>
    <xs:attribute name="AllowCombinedFreight" type="xs:boolean" use="optional"></xs:attribute>
    <xs:attribute name="MaxSelectableQuantity" type="Quantity" use="optional"></xs:attribute>
    <xs:attribute name="ShowOnClearanceSite" type="xs:boolean" use="optional"></xs:attribute>
    <xs:attribute name="ShowOnAuctionSite" type="xs:boolean" use="optional"></xs:attribute>
    <xs:attribute name="ShowOnMediaPartnerSite" type="xs:boolean" use="optional"></xs:attribute>
    <xs:attribute name="ShortName" type="ShortProductName" use="optional"></xs:attribute>
    <xs:attribute name="ShortDescription" type="ShortDescription" use="optional"></xs:attribute>
  </xs:complexType>


  <xs:complexType name="SkuList">
    <xs:sequence>
      <xs:element name="Sku" type="Sku" minOccurs="0" maxOccurs="unbounded"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- Sku element - represent variations (Size and/or Colour) on a product -->
  <!-- Links to the product via the ProductSku attribute -->
  <!-- Each sku has its own unique Sku, Quantity and Size/Colour combinations -->
  <!-- Each sku can have a price override if it wants -->
  <xs:complexType name="Sku">
    <xs:attribute name="ProductSku" type="SkuCode" use="required" />
    <xs:attribute name="Code" type="SkuCode" use="required" />
    <xs:attribute name="QuantityOnHand" type="Quantity" use="required" />
    <xs:attribute name="RRPOverride" type="Price" use="optional" />
    <xs:attribute name="SalePriceOverride" type="Price" use="optional" />
    <xs:attribute name="DailyDealsPriceOverride" type="Price" use="optional" />
    <xs:anyAttribute namespace="##local" processContents="skip"></xs:anyAttribute>
  </xs:complexType>

  <xs:complexType name="ImageList">
    <xs:sequence>
      <xs:element name="Image" type="Image" minOccurs="0" maxOccurs="unbounded"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- Image element - represents a product image -->
  <!-- Linked to a product via the Sku -->
  <!-- Each product can have multiple images, however only one imge can be the default for a product -->
  <xs:complexType name="Image">
    <xs:attribute name="Sku" type="SkuCode" use="required"></xs:attribute>
    <xs:attribute name="Url" type="xs:string" use="required"></xs:attribute>
    <xs:attribute name="IsDefault" type="xs:boolean" use="optional"></xs:attribute>
    <!-- Only required if there is more than one image for a product -->
  </xs:complexType>


  <!-- Attribute Restrictions -->
  <xs:simpleType name="SkuCode">
    <xs:restriction base="xs:string">
      <xs:maxLength value="50"></xs:maxLength>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ProductName">
    <xs:restriction base="xs:string">
      <xs:maxLength value="250"></xs:maxLength>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ShortProductName">
    <xs:restriction base="xs:string">
      <xs:maxLength value="50"></xs:maxLength>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ShortDescription">
    <xs:restriction base="xs:string">
      <xs:maxLength value="1500"></xs:maxLength>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="Quantity">
    <xs:restriction base="xs:int">
      <xs:minInclusive value="0"></xs:minInclusive>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="Price">
    <xs:restriction base="xs:decimal">
      <xs:minInclusive value="0.00"></xs:minInclusive>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="Freight">
    <xs:restriction base="xs:decimal">
      <xs:minInclusive value="0.00"></xs:minInclusive>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
