'use strict';

const Schema = require('warehouse').Schema;
const pathFn = require('path');
const Moment = require('./types/moment');
const moment = require('moment');

module.exports = ctx => {
  const Page = new Schema({
    title: {type: String, default: ''},
    date: {
      type: Moment,
      default: moment,
      language: ctx.config.languages,
      timezone: ctx.config.timezone
    },
    updated: {
      type: Moment,
      default: moment,
      language: ctx.config.languages,
      timezone: ctx.config.timezone
    },
    comments: {type: Boolean, default: true},
    layout: {type: String, default: 'page'},
    _content: {type: String, default: ''},
    source: {type: String, required: true},
    path: {type: String, required: true},
    raw: {type: String, default: ''},
    content: {type: String},
    excerpt: {type: String},
    more: {type: String}
  });

  Page.virtual('permalink').get(function() {
    return `${ctx.config.url}/${this.path}`;
  });

  Page.virtual('full_source').get(function() {
    return pathFn.join(ctx.source_dir, this.source || '');
  });

  return Page;
};
