FactoryGirl.define do
  factory :user, :class => JamRuby::User do
    sequence(:email) { |n| "person_#{n}@example.com"}
    sequence(:first_name)  { |n| "Person" }
    sequence(:last_name)  { |n| "#{n}" }
    password "foobar"
    password_confirmation "foobar"
    email_confirmed true
    city "Apex"
    state "NC"
    country "USA"
    musician true
    terms_of_service true

    #u.association :musician_instrument, factory: :musician_instrument, user: u

    before(:create) do |user|
      user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user)
    end

    factory :admin do
      admin true
    end
  end

  factory :music_session, :class => JamRuby::MusicSession do
    sequence(:description) { |n| "Music Session #{n}" }
    fan_chat true
    fan_access true
    approval_required false
    musician_access true
    legal_terms true
    association :creator, :factory => :user
  end

  factory :music_session_history, :class => JamRuby::MusicSessionHistory do
    ignore do
      music_session nil
    end

    music_session_id { music_session.id }
    description { music_session.description }
    user_id { music_session.user_id }
    band_id { music_session.band_id }
  end

  factory :music_session_user_history, :class => JamRuby::MusicSessionUserHistory do
    ignore do
      history nil
      user nil
    end

    music_session_id { history.music_session_id }
    user_id { user.id }
    sequence(:client_id) { |n| "Connection #{n}" }
  end

  factory :connection, :class => JamRuby::Connection do
    sequence(:client_id) { |n| "Client#{n}" }
    as_musician true
  end

  factory :invitation, :class => JamRuby::Invitation do
    
  end

  factory :friendship, :class => JamRuby::Friendship do

  end

  factory :band_musician, :class => JamRuby::BandMusician do

  end

  factory :band, :class => JamRuby::Band do
    sequence(:name)  { |n| "Band" }
    biography "My Biography"
    city "Apex"
    state "NC"
    country "USA"
  end
  
  factory :genre, :class => JamRuby::Genre do
    description { |n| "Genre #{n}" }
  end

  factory :join_request, :class => JamRuby::JoinRequest do
    text 'let me in to the session!'
  end

  factory :track, :class => JamRuby::Track do
    sound "mono"

  end

  factory :recorded_track, :class => JamRuby::RecordedTrack do
  end

  factory :instrument, :class => JamRuby::Instrument do

  end
  
  factory :recording, :class => JamRuby::Recording do

  end

  factory :musician_instrument, :class => JamRuby::MusicianInstrument do
    instrument { Instrument.find('electric guitar') }
    proficiency_level 1
    priority 0
  end

  factory :invited_user, :class => JamRuby::InvitedUser do
    sequence(:email) { |n| "user#{n}@someservice.com" }
    autofriend false
  end

  factory :music_session_perf_data, :class => JamRuby::MusicSessionPerfData do
    association :music_session => :music_session
  end

  factory :crash_dump, :class => JamRuby::CrashDump do
  end
end
