module Wimdu
  module Partner
    module HolidayHome
      class Customer < Wimdu::Partner::Customer
      include ::Wimdu::Webservice::Param

        # Holiday Home specific customer fields
        attr_accessor :document_language, :address_comments, :birthday, :request, :fax

        param :title, name: 'CustomerTitle'
        param :salutation, name: 'CustomerSalutation', convertor: Proc.new{|value| value == 1 ? 'D' : 'H'}
        param :firstname, name: 'CustomerFirstName'
        param :lastname, name: 'CustomerName'
        param :street, name: 'CustomerStreetNumber'
        param :postcode, name: 'CustomerPostCode'
        param :city, name: 'CustomerCity'
        param :country, name: 'CustomerCountry'
        param :birthday, name: 'CustomerBirthday'
        param :email, name: 'CustomerEmail'
        param :tel_private, name: 'CustomerPhone'
        param :tel_mobile, name: 'CustomerMobile'
        param :fax, name: 'CustomerFax'
        param :language, name: 'CustomerLanguage', convertor: Proc.new{|value| value.to_s.downcase}
        param :document_language, name: 'CustomerDocumentLanguage', convertor: Proc.new{|value| value.to_s.downcase}
        param :comments, name: 'BookingDescription'
        param :address_comments, name: 'CustomerAddressAdditional'
        param :request, name: 'CustomerRequest'

        def initialize(args={})
          super
          self.language = args[:language]
          self.document_language = args[:language]
          self.address_comments = args[:address_comments]
          self.title = args[:title] || ''
          self.birthday = args[:birthday]
          self.comments = ''
          self.address_comments = ''
          self.request = ''
          self.fax = ''
        end

        def self.from_wimdu_booking(wimdu_booking)
          customer_attributes = customer_attributes_from_wimdu_booking(wimdu_booking)
          customer_attributes.merge!(salutation: wimdu_booking.user.salutation == 1 ? 'D' : 'H')
          customer_attributes.merge!(birthday: wimdu_booking.agency_booking_data.extra_data[:birthday])
          new customer_attributes
        end

      end

    end
  end
end
