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

/**
  * 个推推送消息记录 
*/
@index({ roleId: 1 })

export default class Getui_Messages extends BaseModel {
  @prop({ required: true })
  requestId: string;			// 消息标识,唯一
  @prop({ required: false })
  taskId: string;			    // 群发消息id
  @prop({ required: true })
  body: string;				// 消息内容
  @prop({ required: true })
  des: string;			// 描述
  @prop({ required: true })
  isPush: boolean;			// 是否推送出去

  //推送消息成功
  public static async pushMessageSuccess(taskId: string, isPush: boolean) {
    await GetuiMessagesModel.findOneAndUpdate({ taskId }, { $set: { isPush } }, { new: true }).lean(true);
  }

  //添加个人信息
  public static async insertSingleMessage(requestId: string, body: string, des: string, isPush: boolean) {
    let data = { requestId, body, des, isPush };
    await GetuiMessagesModel.insertMany(data);
  }

  //添加群信息
  public static async insertListMessage(requestId: string, taskId: string, body: string, des: string, isPush: boolean) {
    let data = { requestId, taskId, body, des, isPush };
    await GetuiMessagesModel.insertMany(data);
  }

}

export const GetuiMessagesModel = getModelForClass(Getui_Messages);

export interface GetuiMessagesModelType extends Pick<DocumentType<Getui_Messages>, keyof Getui_Messages> { }
export type GetuiMessagesModelTypeParam = Partial<GetuiMessagesModelType>; // 将所有字段变成可选项