import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { Document } from 'mongoose'

export type UserDocument = User & Document

@Schema({ timestamps: true })
export class User {
  @Prop({ sparse: true })
  phone?: string

  @Prop({ sparse: true })
  wxOpenid?: string

  @Prop({ default: '' })
  nickname?: string

  @Prop({ default: '' })
  avatar?: string

  @Prop({ default: 0 })
  interviewCount: number

  @Prop({ default: 3 })
  remaining: number

  @Prop({ default: 'free' })
  plan: string

  @Prop()
  vipExpireAt?: Date

  @Prop({ default: 'user' })
  role: string       // 'user' | 'admin'

  @Prop({ default: false })
  isSystemAdmin: boolean

  @Prop({ sparse: true })
  email?: string

  @Prop({ default: '' })
  password?: string
}

export const UserSchema = SchemaFactory.createForClass(User)