// 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}
/**
 * Create domain
 */
{template .domaincreate stricthtml="false"}
  {@param domain: string}
  {@param period: int}
  {@param nameservers: list<string>}
  {@param registrant: string}
  {@param admins: list<string>}
  {@param techs: list<string>}
  {@param password: string}
  {@param? currency: string}
  {@param? price: string}
  {@param dsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
  {@param? reason: string}
  {@param? requestedByRegistrar: string}
  {@param? allocationToken: string}

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
    <command>
      <create>
        <domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
          <domain:name>{$domain}</domain:name>
          <domain:period unit="y">{$period}</domain:period>
          {if length($nameservers) > 0}
            <domain:ns>
              {for $s in $nameservers}
                <domain:hostObj>{$s}</domain:hostObj>
              {/for}
            </domain:ns>
          {/if}
          <domain:registrant>{$registrant}</domain:registrant>
          {for $admin in $admins}
            <domain:contact type="admin">{$admin}</domain:contact>
          {/for}
          {for $tech in $techs}
            <domain:contact type="tech">{$tech}</domain:contact>
          {/for}
          <domain:authInfo>
            <domain:pw>{$password}</domain:pw>
          </domain:authInfo>
        </domain:create>
      </create>
      {if length($dsRecords) > 0 or $price != null or $reason or $requestedByRegistrar or $allocationToken}
        <extension>
          {if $price != null}
            <fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.12">
              <fee:currency>{$currency}</fee:currency>
              <fee:fee>{$price}</fee:fee>
            </fee:create>
          {/if}
          {if length($dsRecords) > 0}
            <secDNS:create xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
              {for $dsRecord in $dsRecords}
                <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:create>
          {/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}
          {if $allocationToken}
            <allocationToken:allocationToken
                xmlns:allocationToken=
                    "urn:ietf:params:xml:ns:allocationToken-1.0">
              {$allocationToken}
            </allocationToken:allocationToken>
          {/if}
        </extension>
      {/if}
      <clTRID>RegistryTool</clTRID>
    </command>
  </epp>
{/template}
