#--
# Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
# Copyright (c) 2009-2018 Simone Carletti <weppos@weppos.net>
#++


require_relative 'base_shared2'


module Whois
  class Parsers

    # Parser for the whois.nic.us server.
    #
    # @see Whois::Parsers::Example
    #   The Example parser for the list of all available methods.
    #
    class WhoisNicSite < BaseShared2
      
      property_supported :domain_id do
        node("Registry Domain ID")
      end

      property_supported :created_on do
        node("Creation Date") { |value| parse_time(value) }
      end

      property_supported :updated_on do
        node("Updated Date") { |value| parse_time(value) }
      end

      property_supported :expires_on do
        node("Registry Expiry Date") { |value| parse_time(value) }
      end

      property_supported :registrar do
        node("Registrar") do |str|
          Parser::Registrar.new(
            :id           => node("Registrar IANA ID"),
            :name         => node("Registrar"),
          )
        end
      end

      property_supported :registrant_contacts do
        build_contact("Registrant", Parser::Contact::TYPE_REGISTRANT)
      end

      property_supported :admin_contacts do
        build_contact("Admin", Parser::Contact::TYPE_ADMINISTRATIVE)
      end

      property_supported :technical_contacts do
        build_contact("Tech", Parser::Contact::TYPE_TECHNICAL)
      end


      property_supported :nameservers do
        Array.wrap(node("Name Server")).map do |name|
          Parser::Nameserver.new(:name => name.downcase)
        end
      end


      private

      def build_contact(element, type)
        node("#{element} Email") do |str|
          Parser::Contact.new(
            :type         => type,
            :id           => node("#{element} ID"),
            :name         => node("#{element} Name"),
            :organization => node("#{element} Organization"),
            :address      => node("#{element} Street"),
            :city         => node("#{element} City"),
            :zip          => node("#{element} Postal Code"),
            :state        => node("#{element} State/Province"),
            :country      => node("#{element} Country"),
            
            :phone        => node("#{element} Phone"),
            :fax          => node("#{element} Facsimile Number"),
            :email        => node("#{element} Email")
          )
        end
      end
    end

  end
end
