import { prop, DocumentType, } from '@typegoose/typegoose';
import { GM_MAIL_TYPE, MAIL_TIME_TYPE } from '../consts';

class Reward {
  @prop({ required: true })
  id: number;
  @prop({ required: true })
  count: number;
}

export class GMMail {

  @prop({ required: false})
  hasGoods: boolean;                 // 有效时间，单位小时

  @prop({ required: true, type: Reward, default: [], _id: false })
  goods: Reward[];

  @prop({ required: true, default: true })
  timeType: MAIL_TIME_TYPE;          // 邮件时间类型

  @prop({ required: false})
  expire: number;                    // 有效时间，单位小时

  @prop({ required: true })
  circleContinueDay: number;         // 循环邮件持续天数

  @prop({ required: true })
  circleDay: number;                 // 循环时间，每周几，0表示每天

  @prop({ required: true })
  circleHour: string;                // 几点发送

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

  @prop({ required: true })
  content: string;
  
  @prop({ required: true })
  sendName: string;
  
  @prop({ required: true })
  mailType: GM_MAIL_TYPE;         // 收件人类型

  @prop({ required: true })
  reason: string;                   // 原因

  @prop({ required: true, default: false })
  isSp: boolean;                   // 特殊邮件
}


export default class ServerStategy {

    @prop({ required: true, default: false })
    isOpen: boolean;			  // 是否开启

    @prop({ required: true, default: 0 })
    maxPlayerCnt: number;			  // 人数上限

    @prop({ required: true, default: 0, type: Number })
    timers: number[];			  // 开服时间点

    @prop({ required: true, type: Number })
    activityGroupId: number[];		   // 选择活动组

    @prop({ required: true, type: GMMail, _id: false })
    openMail: GMMail;

    @prop({ required: true, type: GMMail, _id: false })
    circleMail: GMMail;
    
    @prop({ required: true, default: 0 })
    stopRegisterTime: number;			  // 关闭注册时间

    constructor(stategy: ServerStategyUpdate & { hasOpenMail: boolean, hasCircleMail: boolean}) {
      this.isOpen = stategy.isOpen;
      this.maxPlayerCnt = stategy.maxPlayerCnt;
      this.timers = stategy.timers;
      this.activityGroupId = stategy.activityGroupId;
      this.stopRegisterTime = stategy.stopRegisterTime;
      if(stategy.hasCircleMail) {
        this.circleMail = stategy.circleMail;
      } else {
        this.circleMail = null;
      }
      if(stategy.hasOpenMail) {
        this.openMail = stategy.openMail;
      } else {
        this.openMail = null;
      }
    }
}
export interface ServerStategyType extends Pick<DocumentType<ServerStategy>, keyof ServerStategy> { };
export type ServerStategyUpdate = Partial<ServerStategyType>; // 将所有字段变成可选项
