text: 'use strict';
  
  /**
   * Module dependencies.
   */
  var mongoose = require('mongoose'),
    validator = require('validator'),
    Schema = mongoose.Schema;
  
    /**
   * A Validation function for local strategy properties
   */
  var validateLocalStrategyProperty = function (property) {
    return ((this.provider !== 'local' && !this.updated) || property.length);
  };
  
  /**
   * A Validation function for local strategy email
   */
  var validateLocalStrategyEmail = function (email) {
    return ((this.provider !== 'local' && !this.updated) || validator.isEmail(email, { require_tld: false }));
  };
  
  
  /**
   * Invitation Schema
   */
  var InvitationSchema = new Schema({
    email: {
       type: String,
      index: {
        unique: true,
        sparse: true // For this to work on a previously indexed field, the index must be dropped & the application restarted.
      },
      lowercase: true,
      trim: true,
      default: '',
      validate: [validateLocalStrategyEmail, 'Please fill a valid email address']
    },
  
    name: {
      type: String,
      trim: true,
      default: '',
      validate: [validateLocalStrategyProperty, 'Please fill in name']
    },
  
    number: {
      type: Number,
      trim: true
    },
  
    organization: {
      type: Schema.ObjectId,
      ref: 'Organization'
    },
  
    invitedBy: {
      type: Schema.ObjectId,
      ref: 'User'
    },
  
    status: {
      type: String,
      default: 'Pending'
    },
  
    created: {
      type: Date,
      default: Date.now
    },
  
    updated: {
      type: Date,
      default: Date.now
    }
  
  });
  
  mongoose.model('Invitation', InvitationSchema);
  