_ = require 'lodash'

module.exports = _.template """
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
       xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
       xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2013" />
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>AllProperties</t:BaseShape>
        <% if (!_.isEmpty(extendedProperties)) { %>
        <t:AdditionalProperties>
          <% _.each(extendedProperties, function(value, key) { %>
            <t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders"
                                PropertyName="X-<%= key %>"
                                PropertyType="String" />
          <% }) %>
        </t:AdditionalProperties>
        <% } %>
      </m:ItemShape>
      <m:Restriction>
        <t:IsEqualTo>
          <t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders"
              PropertyName="X-<%= key %>" PropertyType="String" />
          <t:FieldURIOrConstant>
            <t:Constant Value="<%= value %>" />
          </t:FieldURIOrConstant>
        </t:IsEqualTo>
      </m:Restriction>
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id="<%= Id %>" />
      </m:ParentFolderIds>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>
"""
