// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

{namespace domain.registry.tools}
/**
 * Update domain
 */
{template .domainupdate stricthtml="false"}
  {@param domain: string}
  {@param add: bool}
  {@param addNameservers: list<string>}
  {@param addAdmins: list<string>}
  {@param addTechs: list<string>}
  {@param addStatuses: list<string>}
  {@param remove: bool}
  {@param removeNameservers: list<string>}
  {@param removeAdmins: list<string>}
  {@param removeTechs: list<string>}
  {@param removeStatuses: list<string>}
  {@param change: bool}
  {@param? registrant: string}
  {@param? password: string}
  {@param secdns: bool}
  {@param addDsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
  {@param removeDsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
  {@param removeAllDsRecords: bool}
  {@param? autorenews: string}
  {@param? reason: string}
  {@param? requestedByRegistrar: string}

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
    <command>
      <update>
        <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
          <domain:name>{$domain}</domain:name>
          {if $add}
            <domain:add>
              {if length($addNameservers) > 0}
                <domain:ns>
                  {for $s in $addNameservers}
                    <domain:hostObj>{$s}</domain:hostObj>
                  {/for}
                </domain:ns>
              {/if}
              {for $admin in $addAdmins}
                <domain:contact type="admin">{$admin}</domain:contact>
              {/for}
              {for $tech in $addTechs}
                <domain:contact type="tech">{$tech}</domain:contact>
              {/for}
              {for $status in $addStatuses}
                <domain:status s="{$status}"/>
              {/for}
            </domain:add>
          {/if}
          {if $remove}
            <domain:rem>
              {if length($removeNameservers) > 0}
                <domain:ns>
                  {for $s in $removeNameservers}
                    <domain:hostObj>{$s}</domain:hostObj>
                  {/for}
                </domain:ns>
              {/if}
              {for $admin in $removeAdmins}
                <domain:contact type="admin">{$admin}</domain:contact>
              {/for}
              {for $tech in $removeTechs}
                <domain:contact type="tech">{$tech}</domain:contact>
              {/for}
              {for $status in $removeStatuses}
                <domain:status s="{$status}"/>
              {/for}
            </domain:rem>
          {/if}
          {if $change}
            <domain:chg>
              {if $registrant}
                <domain:registrant>{$registrant}</domain:registrant>
              {/if}
              {if $password}
                <domain:authInfo>
                    <domain:pw>{$password}</domain:pw>
                </domain:authInfo>
              {/if}
            </domain:chg>
          {/if}
        </domain:update>
      </update>
      {if $secdns or $autorenews or $reason or $requestedByRegistrar}
        <extension>
          {if $secdns}
            <secDNS:update xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
              {if $removeAllDsRecords}
                <secDNS:rem>
                  <secDNS:all>true</secDNS:all>
                </secDNS:rem>
              {/if}
              {if length($removeDsRecords) > 0}
                <secDNS:rem>
                  {for $dsRecord in $removeDsRecords}
                    <secDNS:dsData>
                      <secDNS:keyTag>{$dsRecord.keyTag}</secDNS:keyTag>
                      <secDNS:alg>{$dsRecord.alg}</secDNS:alg>
                      <secDNS:digestType>{$dsRecord.digestType}</secDNS:digestType>
                      <secDNS:digest>{$dsRecord.digest}</secDNS:digest>
                    </secDNS:dsData>
                  {/for}
                </secDNS:rem>
              {/if}
              {if length($addDsRecords) > 0}
                <secDNS:add>
                  {for $dsRecord in $addDsRecords}
                    <secDNS:dsData>
                      <secDNS:keyTag>{$dsRecord.keyTag}</secDNS:keyTag>
                      <secDNS:alg>{$dsRecord.alg}</secDNS:alg>
                      <secDNS:digestType>{$dsRecord.digestType}</secDNS:digestType>
                      <secDNS:digest>{$dsRecord.digest}</secDNS:digest>
                    </secDNS:dsData>
                  {/for}
                </secDNS:add>
              {/if}
            </secDNS:update>
          {/if}
          {if $autorenews}
            <superuser:domainUpdate xmlns:superuser="urn:google:params:xml:ns:superuser-1.0">
              <superuser:autorenews>{$autorenews}</superuser:autorenews>
            </superuser:domainUpdate>
          {/if}
          {if $reason or $requestedByRegistrar}
            <metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
            {if $reason}
              <metadata:reason>{$reason}</metadata:reason>
            {/if}
            {if $requestedByRegistrar}
              <metadata:requestedByRegistrar>{$requestedByRegistrar}</metadata:requestedByRegistrar>
            {/if}
            </metadata:metadata>
          {/if}
        </extension>
      {/if}
      <clTRID>RegistryTool</clTRID>
    </command>
  </epp>
{/template}
