class ContactFamilyDecorator < ApplicationDecorator
  delegate :full_name, :first_name, :last_name, :home_phone, :work_phone,
    :cell_phone, :email, :email2, to: :contact
  delegate :name, to: :relationship, prefix: true, allow_nil: true
  delegate :name, to: :family, prefix: true

  def primary
    !object.primary.zero?
  end

  def emergency
    !object.emergency.zero?
  end

  def pickup
    !object.pickup.zero?
  end

  def formatted_home_phone
    formatted_phone(home_phone)
  end

  def formatted_work_phone
    formatted_phone(work_phone)
  end

  def formatted_cell_phone
    formatted_phone(cell_phone)
  end

  private
    def formatted_phone(phone)
      area_code = phone.tr('^0-9', '')
      h.number_to_phone(phone, area_code: area_code)
    end
end
