const mongoose = require('mongoose');
const util = require('util');
const debug = require('debug')('express-mongoose-es6-rest-api:index');

const config = require('../server/config/config');

const Anime = require('../server/models/anime.model');

// connect to mongo db
const mongoUri = config.mongo.host;
mongoose.connect(mongoUri, { keepAlive: 1 });
mongoose.connection.on('error', () => {
  throw new Error(`unable to connect to database: ${mongoUri}`);
});


const animes = [
  { animename: "dragoball",   animetype: 'Fighting', animedetail: 'เลิศล้ำ' ,animeimage: src="" },
  { animename: "one piece",   animetype: 'Fighting', animedetail: 'เลิศล้ำ' },
  { animename: "naruto",      animetype: 'Fighting', animedetail: 'เลิศล้ำ' },
  { animename: "fairy tail",  animetype: 'Magic', animedetail: 'เลิศล้ำ' },
  { animename: "Log Horizon", animetype: 'Magic', animedetail: 'เลิศล้ำ' },
];

Anime.insertMany(animes, (error, docs) => {
  if (error) {
    console.error(error);
  } else {
    console.log(docs);
  }
  mongoose.connection.close();
});
