module Edools
  class User < Edools::Base
    # Basic
    attr_accessor :id, :guid, :first_name, :last_name, :born_at

    # Extra
    attr_accessor :cpf, :rg

    # Contact
    attr_accessor :email, :phone

    # Social
    attr_accessor :skype, :twitter, :facebook

    # Company
    attr_accessor :company_name, :company_position

    # Addresses
    attr_reader :addresses

    def initialize json
      @json = json

      [:id, :guid, :first_name, :last_name, :born_at, :cpf, :rg, :email, :phone, :skype, :twitter, :facebook, :company_name, :company_position, :addresses].each do |attr|
        self.send("#{attr}=".to_sym, json[attr.to_s])
      end
    end

    def addresses= value
      return if value.blank?

      @addresses = []
      value.each do |a|
        @addresses.push Edools::Address.new(a)
      end
    end

    def self.path
      "users"
    end

  end
end
