text: const Promise = require('bluebird');
  const mongoose = require('mongoose');
  const httpStatus = require('http-status');
  const APIError = require('../helpers/APIError');
  
  /**
   * User Schema
   */
  const UserSchema = new mongoose.Schema({
    username: {
      type: String,
      required: true
    },
    email: {
      type: String,
      required: true,
      // eslint-disable-next-line no-useless-escape
      match: [/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, 'The value of path {PATH} ({VALUE}) is not a valid email.']
    },
    password: {
      type: String,
      required: true,
    },
    files: [new mongoose.Schema({
      filename: {
        type: String,
        required: true,
      },
    })],
  }, {
    timestamps: true,
  });
  
  /**
   * Add your
   * - pre-save hooks
   * - validations
   * - virtuals
   */
  
  /**
   * Methods
   */
  UserSchema.method({
  });
  
  /**
   * Statics
   */
  UserSchema.statics = {
    /**
     * Get user
     * @param {ObjectId} id - The objectId of user.
     * @returns {Promise<User, APIError>}
     */
    get(id) {
      return this.findById(id)
        .exec()
        .then((user) => {
          if (user) {
            return user;
          }
          const err = new APIError('No such user exists!', httpStatus.NOT_FOUND);
          return Promise.reject(err);
        });
    },
  
    /**
     * List users in descending order of 'createdAt' timestamp.
     * @param {number} skip - Number of users to be skipped.
     * @param {number} limit - Limit number of users to be returned.
     * @returns {Promise<User[]>}
     */
    list({ skip = 0, limit = 50 } = {}) {
      return this.find()
        .sort({ createdAt: -1 })
        .skip(+skip)
        .limit(+limit)
        .exec();
    }
  };
  
  /**
   * @typedef User
   */
  module.exports = mongoose.model('User', UserSchema);
  