import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util'

/**
  * 自增 ID
*/
@index({ name: 1 })
export default class ErrLog extends BaseModel {

  @prop({ required: true })
  code: string;

  @prop({ required: true, default: "" })
  desc: string;

  public static async create(desc: string) {
      let code = genCode(12);
      await ErrLogModel.insertMany({ code, desc });
  }

}

export const ErrLogModel = getModelForClass(ErrLog);

export interface ErrLogType extends Pick<DocumentType<ErrLog>, keyof ErrLog>{};