class Contact < ActiveRecord::Base


 
  has_many :data_files, :through => :document_orders
  
 

  validates :name, :presence => true
  validates :firstname, :presence => true

  
#  validates :address, :presence => true, :if => :postal_need
#  validates :cp, :presence => true, :if => :postal_need
#  validates :city, :presence => true, :if => :postal_need
#  validates :country, :presence => true, :if => :postal_need
  
  
  validates :email, :presence => true,  :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :if => :email_need
  validates :message, :presence => true, :if => :message_need
  
  #raison_id 
  # 1 => contact classique
  
  
  def message_need
    true if raison_id != 3
  end
  
  def email_need
    if raison_id == 1
      true
    else
      false
    end
  end
  
  def postal_need
    if raison_id == 2 or raison_id == 3
      true
    else
      false
    end
  end
  
  


end
