/**
 * 秘境首通
 */
 import BaseModel from './BaseModel';
 import { getModelForClass, prop, DocumentType, index } from '@typegoose/typegoose';
 import { RankParam, GuildRankParam } from '../domain/rank';
 
@index({ id: 1 })
 export default class RankFirst extends BaseModel {
     
     @prop({ required: true })
     serverId: number;                    // 服务器id

     @prop({ required: true })
     id: number;                         // 奖励表id
 
     @prop({ required: true })
     type: number;                        // 排行榜id
  
     @prop({ required: true, type: () => RankParam, _id: false })
     userInfo: RankParam;                        // 玩家信息

     @prop({ required: true, type: () => GuildRankParam, _id: false })
     guildInfo: GuildRankParam;                   // 军团信息

     public static async createRankFirst(serverId: number, id: number, type: number, update: RankFirstUpdateParam) {
         const rec: RankFirstType = await RankFirstModel.findOneAndUpdate({ serverId, id, type, }, { $setOnInsert: update }, { new: true, upsert: true }).lean();
         return rec;
     }

     public static async findAllRankRewards() {
         let rewards: RankFirstType[] = await RankFirstModel.find({}, { _id: false }).select('serverId id type userInfo guildInfo').lean();
         return rewards;
     }
 }
 
 export const RankFirstModel = getModelForClass(RankFirst);
 
 export interface RankFirstType extends Pick<DocumentType<RankFirst>, keyof RankFirst>{}
 export type RankFirstUpdateParam = Partial<RankFirstType>; // 将所有字段变成可选项
 