class CalendarEvent < ActiveRecord::Base
  # Accessibles
  attr_accessible :institution_calendar_id, :kind, :name, :description, :start_at, :end_at, :repetitive, :user_id

  # Associations
  belongs_to :institution_calendar

  # Validations
  validates :institution_calendar_id, :kind, :name, :start_at, presence: true

  # Callbacks
  before_validation :ensure_kind

  # Enumerated attributes
  enumerated_attribute :kind, %w(^holiday work) do
    label holiday: I18n.t('enum.calendar_event.kind.holiday')
    label work: I18n.t('enum.calendar_event.kind.work')
  end

  def ensure_kind
    self.kind = 'holiday' unless kind.present?
  end
end
