module ShoppingCart
  class Address < ActiveRecord::Base
	  belongs_to :addressable, polymorphic: true
	  
	  INNER_TYPES = ['billing', 'shipping']
	  
	  validates :name, :last_name, :zip, :country, :city, :address, :inner_type, presence: true
	  validates :zip, length: { minimum: 2, maximum: 8 }
	  validates :name, :last_name, :country, :city, length: { minimum: 2, maximum: 25 }
	  validates :address, length: { minimum: 2, maximum: 60 }
	  validates :inner_type, inclusion: { in: INNER_TYPES }
	  
	  scope :billing, -> { where(inner_type: 'billing') }
	  scope :shipping, -> { where(inner_type: 'shipping') }
  end
end
