var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/comments');
require('./models/comments_model.js');
require('./models/photo_model.js');
require('./models/page_model.js');
var CommentThread = mongoose.model('CommentThread');
var Reply = mongoose.model('Reply');
var Photo = mongoose.model('Photo');
var Page = mongoose.model('Page');
function addPhoto(title, filename){
  var comment = new CommentThread({title: "Komentarze dla: " + title});
  comment.save(function(err, comment){
    var photo = new Photo({title:title, filename:filename});
    photo.commentId = comment.id;
    photo.save(function(){
      console.log("Zapisano: " + title);
    });
  });
}
CommentThread.remove().exec(function(){
  Photo.remove().exec(function(){
    Page.remove().exec(function(){
      var comment = new CommentThread({title:"Komentarze strony ze zdjęciami"});
      comment.save(function(err, comment){
        var page = new Page({name:"Strona ze zdjęciami"});
        page.commentId = comment.id;
        page.save();
      });
      addPhoto('Wytrzymałość', 'arch.jpg');
      addPhoto('Siła', 'pyramid.jpg');
      addPhoto('Piękno', 'flower.jpg');  
      addPhoto('Zamyślony', 'lake.jpg');   
      addPhoto('Letnia zabawa', 'volcano.jpg');   
      addPhoto('Zachody słońca', 'jump.jpg');      
    });
  });
});;
