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

class SearchTask {
  @prop({ required: true })
  id: number; // 任务表中的唯一 Id
  @prop({ required: true })
  taskCode: string; // 服务器生成的任务唯一标识
  @prop({ required: true })
  startTime: Date; // 任务派遣开始时间
  @prop({ required: true })
  status: number; // 派遣任务当前状态，0-可派遣，1-已派遣，2-已完成，3-已领取
  @prop({ required: true, default: [] })
  heroes: Array<number> // 派遣武将 hid
}

/**
  * 派遣任务记录表
  */
@index({ roleId: 1, type: 1 })

export default class SearchRecord extends BaseModel {
  @prop({ required: true })
  roleId: string;					// 角色 id
  @prop({ required: true })
  batchCode: string; // 本批派遣任务唯一标识
  @prop({ required: true, default: [], _id: false })
  tasks: Array<SearchTask>;


  public static async deleteAccount(roleId: string) {
    let result = await SearchRecordModel.deleteMany({roleId});
    return result;
  }
}

export const SearchRecordModel = getModelForClass(SearchRecord);

export interface SearchRecordType extends Pick<DocumentType<SearchRecord>, keyof SearchRecord>{};