// filler.js

// si l'admin n'a pas été créé, on éxécute le filler!!
if( Meteor.users.find({'username' : 'admin'}).fetch().length == 0 )
{
    console.log('--------------------------------------');

    // on clear
    Meteor.users.remove({});
    Events.remove({});

    console.log('filler.js : clear de la bdd');

    // puis on populate
    var Users = [
        {email:'admin@gmail.com',pseudo:"admin",password:"rookie", role:'Admin'},
        {email:'babault1@gmail.com',pseudo:"babault1",password:"rookie", role:'Babault'},
        {email:'babault2@gmail.com',pseudo:"babault2",password:"rookie", role:'Babault'},
        {email:'guest1@gmail.com',pseudo:"guest1",password:"rookie", role:'Guest'},
        {email:'guest2@gmail.com',pseudo:"guest2",password:"rookie", role:'Guest'},
        {email:'guest3@gmail.com',pseudo:"guest3",password:"rookie", role:'Guest'}
    ];

    _.each(Users, function(user) {
        Accounts.createUser({
            email : user.email,
            password : user.password,
            username : user.pseudo,
        });

        // on ajoute les infos supplémentaires
        Meteor.users.update(
            {'username' : user.pseudo},
            {$set:{
                'role' : user.role
              }
            }
        );
    });

    console.log('filler.js : utilisateurs ajoutés');

    //Users
    user1 = Meteor.users.findOne({username:'admin'});
    user2 = Meteor.users.findOne({username:'babault1'});
    user3 = Meteor.users.findOne({username:'babault2'});
    user4 = Meteor.users.findOne({username:'guest1'});
    user5 = Meteor.users.findOne({username:'guest2'});
    user6 = Meteor.users.findOne({username:'guest3'});

    var events = [
        {title : 'babault1', start : '2017-06-02', end : '2017-06-04', type : 'Babault', guests : 2, comment : 'filler.js event', author : user2._id},
        {title : 'babault2', start : '2017-06-09', end : '2017-06-12', type : 'Babault', guests : 0, comment : 'filler.js event', author : user3._id},
        {title : 'guest2', start : '2017-06-14', end : '2017-06-14', type : 'Guest', guests : 0, comment : 'filler.js event', author : user5._id},
        {title : 'guest3', start : '2017-06-21', end : '2017-06-24', type : 'Guest', guests : 5, comment : 'filler.js event', author : user6._id}
    ];

    _.each(events, function(event) {
        Events.insert(event);
    });

    console.log('filler.js : events ajoutés');

    console.log('--------------------------------------');

}
