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




/**
  * 活动系统 - 寻宝骑兵-首页奖励
*/
@index({ roleId: 1, activityId: 1 })

export default class Activity_Treasure_Hunt_First_Page {
  @prop({ required: true })
  serverId: number;				// 区Id
  @prop({ required: true })
  activityId: number;				// 活动Id
  @prop({ required: true })
  roleId: string;			        // 用户Id
  @prop({ required: true })
  roundIndex: number;			        // 回合数
  @prop({ required: true })
  isReceive: boolean;			        // 是否领取

  //根据活动id查询活动数据
  public static async findData(serverId: number, activityId: number, roleId: string, roundIndex: number) {
    let result: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findOne({ serverId, roleId, activityId, roundIndex }).lean(true);
    return result;
  }

  //领取奖励的记录
  public static async receiveReward(serverId: number, activityId: number, roleId: string, roundIndex: number,) {
    let result: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex },
      { $set: { isReceive: true } }, { upsert: true, new: true }).lean(true);
    return result;
  }
}

export const ActivityTreasureHuntFirstPageModel = getModelForClass(Activity_Treasure_Hunt_First_Page);

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