<rules>
    <!-- $Id$
         Let op: IIS detecteert wijzigingen in dit bestand pas
         als je /web.config 'touched' (opnieuw opslaat)
    -->
    <clear />
    <!-- /.LOGC/restvanurl wordt /restvanurl?fac_id=LOGC -->
    <rule name="FAC_ID">
        <match url="^\.([a-z0-9_]+)/(.+)/?" />
        <action type="Rewrite" url="{R:2}?fac_id={R:1}" />
    </rule>
    <rule name="Versienummer">
        <match url="appl/fac/fac_verify.asp" />
        <action type="Rewrite" url="appl/fac/fac_verify.asp?rewriterversion=1.00" />
    </rule>

    <!-- /api2/buildings/1/attachments/123/sample.doc?...                   /default.asp?api2=attachments&filename=sample.doc&... -->
    <rule name="attachments" stopProcessing="true">
        <match url="^api2/([a-z0-9_]+)/(\d+)/attachments/(.*)/(.*)/?" />
        <action type="Rewrite" url="default.asp?mode=attachment&amp;format=auto&amp;api2={R:1}&amp;id={R:2}&amp;subfolder={R:3}&amp;filename={UrlEncode:{R:4}}" appendQueryString="true" />
    </rule>

    <!-- Import/Export rules -->
    <!-- /api2/files/import/PRS/persons.csv -->
    <rule name="filesSingleIE" stopProcessing="true">
        <match url="^api2/files/(imports|exports)/([a-z0-9_]+)/(.+)/?" />
        <action type="Rewrite" url="default.asp?mode=files&amp;format=auto&amp;api2=files&amp;module={R:1}&amp;iecode={R:2}&amp;filename={UrlEncode:{R:3}}" appendQueryString="true" />
    </rule>
    <!-- /api2/files/export/fin -->
    <rule name="filesIE" stopProcessing="true">
        <match url="^api2/files/(imports|exports)/([a-z0-9_]+)\.(xml|json|html|api|doc|table|csv|xlsx)/?" />
        <action type="Rewrite" url="default.asp?mode=files&amp;format={R:3}&amp;api2=files&amp;module={R:1}&amp;iecode={R:2}" appendQueryString="true" />
    </rule>
    <rule name="filesAutoIE" stopProcessing="true">
        <match url="^api2/files/(imports|exports)/([a-z0-9_]+)/?" />
        <action type="Rewrite" url="default.asp?mode=files&amp;format=auto&amp;api2=files&amp;module={R:1}&amp;iecode={R:2}" appendQueryString="true" />
    </rule>

    <!-- Files rules -->
    <!-- /api2/files/menu/persons.csv -->
    <rule name="filesSingle" stopProcessing="true">
        <match url="^api2/files/([a-z0-9_]+)/(.+)/?" />
        <action type="Rewrite" url="default.asp?mode=files&amp;format=auto&amp;api2=files&amp;module={R:1}&amp;filename={UrlEncode:{R:2}}" appendQueryString="true" />
    </rule>
    <!-- /api2/files/menu -->
    <rule name="files" stopProcessing="true">
        <match url="^api2/files/([a-z0-9_]+)\.(xml|json|html|api|doc|table|csv|xlsx)/?" />
        <action type="Rewrite" url="default.asp?mode=files&amp;format={R:2}&amp;api2=files&amp;module={R:1}" appendQueryString="true" />
    </rule>
    <rule name="filesAuto" stopProcessing="true">
        <match url="^api2/files/([a-z0-9_]+)/?" />
        <action type="Rewrite" url="default.asp?mode=files&amp;format=auto&amp;api2=files&amp;module={R:1}" appendQueryString="true" />
    </rule>


    <!-- /api2/buildings/          /default.asp?api2=doc&format=doc -->
    <rule name="Add trailing slash" stopProcessing="true">
      <match url="^api2$" />
      <action type="Redirect" redirectType="Permanent" url="api2/" />
    </rule>
    <rule name="api2doc" stopProcessing="true">
        <match url="^api2/$" />
        <action type="Rewrite" url="default.asp?api2=doc&amp;format=doc" appendQueryString="true" />
    </rule>
    <!-- /api2/buildings/1234.xml?...          /default.asp?api2=buildings&format=xml&id=1234&... -->
    <rule name="api2SingleRecord" stopProcessing="true">
        <match url="^api2/([a-z0-9_]+)/(\d+)\.(xml|json|html|api|doc|table|csv|xlsx)/?" />
        <action type="Rewrite" url="default.asp?api2={R:1}&amp;format={R:3}&amp;id={R:2}" appendQueryString="true" />
    </rule>
    <rule name="api2SingleRecordAuto" stopProcessing="true">
        <match url="^api2/([a-z0-9_]+)/(\d+)/?" />
        <action type="Rewrite" url="default.asp?api2={R:1}&amp;format=auto&amp;id={R:2}" appendQueryString="true" />
    </rule>
     <!-- /api2/buildings.xml?...               /default.asp?api2=buildings&format=xml&... -->
    <rule name="api2List" stopProcessing="true">
    	<match url="^api2/([a-z0-9_]+)\.(xml|json|html|api|doc|table|csv|xlsx)/?" />
    	<action type="Rewrite" url="default.asp?api2={R:1}&amp;format={R:2}" appendQueryString="true" />
    </rule>
    <rule name="api2ListAuto" stopProcessing="true">
    	<match url="^api2/([a-z0-9_]+)/?" />
    	<action type="Rewrite" url="default.asp?api2={R:1}&amp;format=auto" appendQueryString="true" />
    </rule>

    <!-- SCIM/Users/ABCD_person_2122 -->
    <rule name="SCIMUser" stopProcessing="true">
    	<match url="^appl/SCIM/Users/.*_person_(\d+)" />
    	<action type="Rewrite" url="default.asp?api2=persons&amp;id={R:1}&amp;format=json&amp;plugin=scimusers&amp;include=lastchange,authorization" appendQueryString="true" />
    </rule>

    <rule name="SCIMUsers" stopProcessing="true">
    	<match url="^appl/SCIM/Users" />
    	<action type="Rewrite" url="default.asp?api2=persons&amp;format=json&amp;plugin=scimusers&amp;include=lastchange,authorization" appendQueryString="true" />
    </rule>

    <rule name="SCIMGroup" stopProcessing="true">
    	<match url="^appl/SCIM/Groups/.*_authorizationgroup_(\d+)" />
    	<action type="Rewrite" url="default.asp?api2=authorizationgroups&amp;id={R:1}&amp;format=json&amp;plugin=scimgroups&amp;include=users" appendQueryString="true" />
    </rule>

    <rule name="SCIMGroups" stopProcessing="true">
    	<match url="^appl/SCIM/Groups" />
    	<action type="Rewrite" url="default.asp?api2=authorizationgroups&amp;format=json&amp;plugin=scimgroups&amp;include=users" appendQueryString="true" />
    </rule>

    <rule name="SCIMOrgunit" stopProcessing="true">
    	<match url="^appl/SCIM/OrgUnits/.*_department_(\d+)" />
    	<action type="Rewrite" url="default.asp?api2=departments&amp;id={R:1}&amp;format=json&amp;plugin=scimorgunits" appendQueryString="true" />
    </rule>

    <rule name="SCIMOrgunits" stopProcessing="true">
    	<match url="^appl/SCIM/OrgUnits" />
    	<action type="Rewrite" url="default.asp?api2=departments&amp;format=json&amp;plugin=scimorgunits" appendQueryString="true" />
    </rule>

    <!-- Zonder de trailing '/' -->
    <rule name="SCIMSchema" stopProcessing="true">
    	<match url="^appl/SCIM/Schemas$" />
    	<action type="Rewrite" url="appl/SCIM/Schemas/" appendQueryString="true" />
    </rule>
    <rule name="SCIMServiceProviderConfig" stopProcessing="true">
    	<match url="^appl/SCIM/ServiceProviderConfig$" />
    	<action type="Rewrite" url="appl/SCIM/ServiceProviderConfig/" appendQueryString="true" />
    </rule>
    <rule name="SCIMResourceTypes" stopProcessing="true">
    	<match url="^appl/SCIM/ResourceTypes$" />
    	<action type="Rewrite" url="appl/SCIM/ResourceTypes/" appendQueryString="true" />
    </rule>
<!--
    <rule name="Check file exists">
        <match url="^([^.]+)\.([a-zA-Z]+)" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>
        <action type="Rewrite" url="/appl/shared/404_error.asp?url404={R:1}.{R:2}" appendQueryString="true" />
    </rule>
-->
</rules>
