{User, Post, Comment} = require './models'

Post.setClient 'localhost:27017/blog_example'

author = new User
  username  : 'humanchimp'
  fullName  : 'Chris Thorn'
  email     : "chris@koding.com"
  foo       : 'abcd'

commenter1 = new User
  username  : 'fooman'
  fullName  : 'Nroht Srihc'
  email     : 'nroht@jraphical.com'
  foo       : 'zyxw'
  
author.save (err)->
  throw err if err
  # make a new blog post
  post = new Post
    author  : author._id
    title   : "zO hai!"
    body    : "Welcome to my hella coole new Blog!!!"
  
  post.on 'error', console.log
  
  post.on 'save', (step)-> 
    switch step
      when 0
        console.log post
      when 1
        console.log 'saved'
  
  post.save (err)->
    throw err if err
    
    commenter1.on 'error', console.log
    
    commenter1.save (err)->
      throw err if err
      comment1 = new Comment
        author  : commenter1._id
        body    : 'This blog is teh kule!'
      
      # save a comment to the blog post
      post.addComment comment1
      post.save()
