class EmployeeDecorator < ApplicationDecorator
  delegate :name, to: :position, prefix: true, allow_nil: true
  delegate :full_name, to: :manager, prefix: true, allow_nil: true
  delegate :name, to: :location, prefix: true, allow_nil: true
  delegate :name, to: :building, prefix: true, allow_nil: true
  delegate :name, to: :title, prefix: true, allow_nil: true
  delegate :name, to: :type, prefix: true, allow_nil: true
  delegate :name, to: :race, prefix: true, allow_nil: true
  delegate :ethnicity, :ncea_status, :hispanic?, to: :detail, allow_nil: true
  delegate :number, to: :state_id, allow_nil: true
  delegate :address, to: :primary_email_address, allow_nil: true, prefix: true
  delegate :street, :street_ext, :city, :state, :zip, to: :billing_address, allow_nil: true,
    prefix: true
  delegate :street, :street_ext, :city, :state, :zip, to: :employers_address, allow_nil: true,
    prefix: true
  delegate :street, :street_ext, :city, :state, :zip, to: :employment_address, allow_nil: true,
    prefix: true
  delegate :street, :street_ext, :city, :state, :zip, to: :mailing_address, allow_nil: true,
    prefix: true
  delegate :street, :street_ext, :city, :state, :zip, to: :other_home_address, allow_nil: true,
    prefix: true
  delegate :street, :street_ext, :city, :state, :zip, to: :physical_address, allow_nil: true,
    prefix: true
  delegate :number, to: :fax_phone, allow_nil: true, prefix: true
  delegate :number, to: :home_phone, allow_nil: true, prefix: true
  delegate :number, to: :mobile_phone, allow_nil: true, prefix: true
  delegate :number, to: :other_phone, allow_nil: true, prefix: true
  delegate :number, to: :work_phone, allow_nil: true, prefix: true
  delegate :first_name, :middle_name, :last_name, :suffix, to: :other_name, allow_nil: true,
    prefix: true
  delegate :number, to: :school_number, prefix: true, allow_nil: true
  delegate :number, to: :state_id, prefix: true, allow_nil: true
  delegate :number, to: :social_security_number, prefix: true, allow_nil: true

  def birth_date
    l(date_of_birth) if date_of_birth
  end

  def gender_label
    return if no_gender?

    gender.titleize
  end

  def ethnicity_label
    return 'Unspecified' if detail.nil?

    ethnicity.titleize
  end

  def external_id_number
    school_number&.number
  end

  def department_names
    departments.map(&:name).join(', ')
  end

  def is_substitute?
    substitute.present?
  end
end
