const mongoose = require('mongoose')

function cover(img) {
   return '/uploads/images/blog/' + img
}

const BlogPostSchema = mongoose.Schema({
   cover: {type: String, get: cover},
   published: {type: Boolean, default: true},
   category: String,
   post_details: {
      fa: {
         title: String,
         description: String,
         short_description: String
      },
      en: {
         title: String,
         description: String,
         short_description: String
      }
   },
   created_at: String,
   updated_at: String
}, {
   toObject: {getters: true},
   toJSON: {getters: true}
})

BlogPostSchema.virtual('thumb').get(function () {
   return '/uploads/images/blog/thumb_' + this.cover.split('blog/')[1]
})

module.exports = mongoose.model('BlogPost', BlogPostSchema)
