namespace TM.TransSmart.Transforms {
    
    
    [Microsoft.XLANGs.BaseTypes.SchemaReference(@"TM.Shared.Schemas_v19A.OrderStatus", typeof(global::TM.Shared.Schemas_v19A.OrderStatus))]
    [Microsoft.XLANGs.BaseTypes.SchemaReference(@"TM.TransSmart.Schemas.nShift+root", typeof(global::TM.TransSmart.Schemas.nShift.root))]
    public sealed class TM_Shared_OrderStatus_to_TM_TransSmart_Status : global::Microsoft.XLANGs.BaseTypes.TransformBase {
        
        private const string _strMap = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0""
                xmlns:ScriptNS0=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS0""
                xmlns:ScriptNS1=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS1""
                
                xmlns:DateTime=""TM.Shared.Components.DateTime""
                xmlns:SSO=""TM.Shared.Components.SSO""
                xmlns:String=""TM.Shared.Components.String""
                
                xmlns:s0=""http://TM.KLG.com/KLG/OrderStatus/v19A""
                xmlns:ns0=""http://TM.nShift.messages""
                
                exclude-result-prefixes=""s0 ns0 ScriptNS0 ScriptNS1 DateTime SSO String"">

  <xsl:output omit-xml-declaration=""yes"" method=""xml"" version=""1.0"" indent=""yes"" />

  <!-- region global variable initialization -->

  <xsl:variable name=""connectionString"" select=""SSO:GetValue('TM.TransSmart', 'ESBLookupConnectionString')""/>
  
  <xsl:variable name =""sender"">
    <xsl:choose>
      <xsl:when test=""/s0:StatusReport/Sender='KLGEUEERSE01'"">KLE</xsl:when>
      <xsl:when test=""/s0:StatusReport/Sender='KLGEUVENLO01'"">KLG</xsl:when>
      <xsl:otherwise>KLG</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  
  <!-- end region -->

  <!-- region templates -->

  <xsl:template match=""/"">
    <xsl:apply-templates select=""/s0:StatusReport"" />
  </xsl:template>
  
  <xsl:template match=""/s0:StatusReport"">
    <xsl:variable name=""currentDateTime"" select=""DateTime:GetCurrentDateTime()"" />
    <xsl:variable name=""currentDate"" select=""DateTime:GetCurrentDate()"" />

    <ns0:root>
      <ns0:status>
        <xsl:attribute name=""carrier"">
          <xsl:value-of select=""$sender"" />
        </xsl:attribute>
        <xsl:for-each select=""Status"">
          <ns0:shipment>
            <ns0:lineNo>
              <xsl:number/>
            </ns0:lineNo>
            <ns0:statusTimeStamp>
              <xsl:value-of select=""DateTime:FormatDateTime(/s0:StatusReport/TimeStamp, 'yyyy-MM-ddTHH:mm:ss', 'yyyyMMddHHmmss', 'statusTimeStamp')""/>
            </ns0:statusTimeStamp>
            <ns0:reference>
              <xsl:value-of select=""ShipmentReference""/>
            </ns0:reference>
            <xsl:if test=""StatusCode='DELIVERED'"">
              <ns0:deliveryDate>
                <xsl:value-of select=""DateTime:FormatDateTime(StatusTimeStamp, 'yyyy-MM-ddTHH:mm:ss', 'yyyyMMdd', 'statusTimeStamp')""/>
              </ns0:deliveryDate>
              <ns0:deliveryTime>
                <xsl:value-of select=""DateTime:FormatDateTime(StatusTimeStamp, 'yyyy-MM-ddTHH:mm:ss', 'HHmmss', 'statusTimeStamp')""/>
              </ns0:deliveryTime>
            </xsl:if>
            <ns0:shipmentStatus>
              <xsl:choose>
                <xsl:when test=""StatusCode='DELIVERED'"">
                  <xsl:text>DONE</xsl:text>
                </xsl:when>
                <xsl:when test=""StatusCode='DELIVERY' and ReasonCode='TRANSIT'"">
                  <xsl:text>TRNS</xsl:text>
                </xsl:when>
                <xsl:otherwise>TRNS</xsl:otherwise>
              </xsl:choose>
            </ns0:shipmentStatus>
            <ns0:carrierStatusCode>
              <xsl:value-of select=""StatusCode""/>
              <xsl:text> </xsl:text>
              <xsl:value-of select=""ReasonCode""/>
            </ns0:carrierStatusCode>
          </ns0:shipment>
        </xsl:for-each>
      </ns0:status>
    </ns0:root>
  </xsl:template>
  <!-- end region -->

  <xsl:variable name=""dbClose"" select=""ScriptNS0:DBLookupShutdown()""/>

</xsl:stylesheet>";
        
        private const int _useXSLTransform = 0;
        
        private const string _strArgList = @"<ExtensionObjects>
  <ExtensionObject Namespace=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS0"" 
                   AssemblyName=""Microsoft.BizTalk.BaseFunctoids, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" 
                   ClassName=""Microsoft.BizTalk.BaseFunctoids.FunctoidScripts"" />
  <ExtensionObject Namespace=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS1"" 
                   AssemblyName=""Microsoft.BizTalk.CrossReferencing, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" 
                   ClassName=""Microsoft.BizTalk.CrossReferencing.CrossReferencing"" />
  <ExtensionObject Namespace=""TM.Shared.Components.DateTime""
                   AssemblyName=""TM.Shared.Components, Version=3.0.7.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.DateTimeFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.KeyList""
                   AssemblyName=""TM.Shared.Components, Version=3.0.7.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.KeyListFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.SSO""
                   AssemblyName=""TM.Shared.Components, Version=3.0.7.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.SSOFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.String""
                   AssemblyName=""TM.Shared.Components, Version=3.0.7.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.StringFunctions"" />
  <ExtensionObject Namespace=""TM.TransSmart.Components""
                 AssemblyName=""TM.TransSmart.Components, Version=3.0.1.0, Culture=neutral, PublicKeyToken=089e5464cda5fc95""
                 ClassName=""TM.TransSmart.Components.Helper"" />
</ExtensionObjects>";
        
        private const string _strSrcSchemasList0 = @"TM.Shared.Schemas_v19A.OrderStatus";
        
        private const global::TM.Shared.Schemas_v19A.OrderStatus _srcSchemaTypeReference0 = null;
        
        private const string _strTrgSchemasList0 = @"TM.TransSmart.Schemas.nShift+root";
        
        private const global::TM.TransSmart.Schemas.nShift.root _trgSchemaTypeReference0 = null;
        
        public override string XmlContent {
            get {
                return _strMap;
            }
        }
        
        public override int UseXSLTransform {
            get {
                return _useXSLTransform;
            }
        }
        
        public override string XsltArgumentListContent {
            get {
                return _strArgList;
            }
        }
        
        public override string[] SourceSchemas {
            get {
                string[] _SrcSchemas = new string [1];
                _SrcSchemas[0] = @"TM.Shared.Schemas_v19A.OrderStatus";
                return _SrcSchemas;
            }
        }
        
        public override string[] TargetSchemas {
            get {
                string[] _TrgSchemas = new string [1];
                _TrgSchemas[0] = @"TM.TransSmart.Schemas.nShift+root";
                return _TrgSchemas;
            }
        }
    }
}
