const mongoose = require('mongoose');
const  config  = require('../config/config.json');
//const { Ticket } = require('../models/ticket.model');
//const { Restaurant} = require('../models/restaurant.model');
// const { User } = require('../models/user.model');
 //const bcrypt = require('bcrypt');
// const Role = require('../lib/role');
//const db = config.url;

var db = 'mongodb://database_preprod:27017/mean-fatboar-db';
//var mongoURI = 'mongodb://localhost:27017/my-db';
//mongoose.set('useCreateIndex', true)
mongoose.connect(db, {useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
    console.log("Successfully connected to the database.");
}).catch(err => {
    console.log("Could not connect to the database.", err);
});


module.exports = mongoose.connection;

// let min = 999999999;
// let max = 10000000000;
// for (i = 0; i < 2; i++) {
//     let code = Math.floor(Math.random() * (max - min + 1)) + min;
     
//          const ticke = new Ticket({
//              code: code,
//              isUsed: false,
//              gains: "un menu du jour",
//              date_used: new Date(),
//              index: 'index',
//              isServed: true
//         });
        
//          ticke.save();
//      }
// const resto = new Restaurant({
//     "index": 5,
//     "name": "FatBoar 5",
//     "adress": "20 Rue Houdart, 95700 Roissy-en-France, France",
//     "longitude": 2.515081,
//     "latitude": 49.002317
//   });
//   resto.save();

// const salt = bcrypt.genSaltSync(12);
//  password = bcrypt.hashSync('Pass@123', 12);
//  console.log('fgfg', password);
// let date = new Date(1997, 1 , 12 , 20, 40);
 
//  const user = new User({
//                       firstname: " adrien",
//                       lastname: "xxxxxxx",
//                       email: "adrien@hotmail.fr",
//                       role: 'admin',
//                       birthday: date,
//                       phonenumber: '0680705876',
//                       isActive: true,
//                       password: password
//                   });
                  

//  user.save();