class Kap < ActiveRecord::Base
  belongs_to :p_customer
  belongs_to :kaps_cat
  
  validates :points, :presence => true
  validates :name, :presence => true
  validates :kaps_type_id, :presence => true
  
  has_many :kaps_rappels
  accepts_nested_attributes_for :kaps_rappels, :allow_destroy => true
  
  

  validates :start_at, :presence => true
  
  
  before_validation do 
    if self.pause_days.to_i < 1
      self.pause_days = nil
    end
    
    if self.active_days.to_i < 1
      self.active_days = nil
    end
    
    if self.active_days? and !self.pause_days?
      errors.add(:pause_days, 'doit être remplis si nombre de jours de pause indiqués')
    end
    
    if self.pause_days? and !self.active_days?
      errors.add(:active_days, 'doit être remplis si nombre de jours de pause indiqués')
    end
      
      
    
      
      
  end
  
  def kaps_type
    if self.kaps_type_id == 1
      "Journalier"
    elsif self.kaps_type_id == 2
      "Hebdomadaire"
    else
      "Mensuel"
    end
    
    
  end
  
  
  
  
end
