var Schema = require('mongoose').Schema;

const userSchema = new Schema({
  nickname: { type: String, desc: '昵称', listing: false, },
  disabled: { type: Boolean, default: false, index: true, desc: '禁用' },
  name: { type: String, index: true, desc: '姓名', listing: true, searchable: true, },
  username: { type: String, index: true, unique: true, required: true, desc: '用户名', searchable: true, orderable: true, },
  password: { type: String, required: true, desc: '密码', listing: false, },
  phone: { type: String, default: null, index: true, desc: '手机号', searchable: true, orderable: true, },
  email: { type: String, index: true, desc: 'Email', searchable: true, orderable: true, },
  createBy: { type: Schema.Types.ObjectId, ref: 'User', index: true, desc: '创建者', },

  roles: { type: [{ type: Schema.Types.ObjectId, ref: 'Role', }], listing: true, desc: '角色', },

  epgs: { type: [String], index: true, trim: true, desc : 'Epg', searchable: true },  // 绑定的epg列表

  administrator: { type: Boolean, default: false, listing: false, desc: '是否管理员(已废弃)', },
  emailVerified: { type: Boolean, required: true, default: false, desc: 'Email是否验证', listing: false, },
  dateSignup: { type: Date, required: true, default: Date.now, index: true, desc: '创建时间', },
  dateLastSignin: { type: Date, default: Date.now, index: true, desc: '最后登录时间', },
  ipLastSignin: { type: String, default: null, index: true, desc: '最后登录ip', },


}, {
  toJSON: {
    virtuals: true,
  },
  toObject: {
    virtuals: true,
  }
});

module.exports = userSchema;


