require 'securerandom'

module JamRuby
  class MusicSessionPerfData < ActiveRecord::Base

    self.primary_key = 'id'

    attr_accessible :uri

    belongs_to(:music_session_history, 
               :class_name => "JamRuby::MusicSessionHistory", 
               :foreign_key => :music_session_id)

    # mount_uploader :uri, PerfDataUploader

    validates :music_session_history, :presence => true
    validates :client_id, :presence => true
    validates :uri, :presence => true

    before_validation(:on => :create) do
      self.created_at ||= Time.now
      self.id = SecureRandom.uuid
      self.uri = "perf_data/#{self.music_session_id}/#{self.client_id}-#{self.created_at.to_i}"
    end
  end

  def music_session_user_history
    @msuh ||= JamRuby::MusicSessionUserHistory.find_by_client_id(self.client_id)
  end

end
