class EventOutboxEvent < ActiveRecord::Base
  validates :event_type, :source_type, :source_id, :occurred_at, :payload, :presence => true

  scope :pending, lambda { where(:processed_at => nil).order(:id) }

  def payload_data
    ActiveSupport::JSON.decode(payload)
  rescue
    {}
  end

  def payload_data=(data)
    self.payload = ActiveSupport::JSON.encode(data)
  end
end
