package models

import (
	"github.com/mhaya/game/game_cluster/internal/data"
)

// 离散规则信息
const (
	InitRoll             = 1
	InvitePlayer         = 2
	InviteVipPlayer      = 3
	InvitePlayerByLeader = 4
	RefreshRoll          = 5
	NewPlayerGuide       = 6
	ShareLottery         = 7
	FirstBindingTwitter  = 8
	InviteMaxExpireTime  = 9
	UCashOutConfig       = 10
	TonCashOutConfig     = 11
	NewPlayer10Draw      = 12
)

type AchieveTaskBase struct {
	ID        int               `json:"id" bson:"id"`               // #任务ID
	Order     int               `json:"order" bson:"order"`         //任务客户端排序
	Type      int               `json:"type" bson:"type"`           // 任务类型(1基本类型2邀请好友相关)
	Condition data.RangeInt32   `json:"condition" bson:"condition"` // 完成范围 RangeInt32               `json:"condition" bson:"condition"` // 完成条件
	Reward    []data.ItemReward `json:"reward" bson:"reward"`       // 奖励
	Url       string            `json:"url" bson:"url"`             // 链接
	Num       int               `json:"num" bson:"num"`             //已完成次数
	Icon      string            `json:"icon" bson:"icon"`           //Icon
	RewardNum int               `json:"rewardNum" bson:"rewardNum"` //可领奖次数
	Status    int               `json:"status" bson:"status"`       //完成状态0未完成  1已完成2已领取奖励
	Validate  int               `json:"validate" bson:"validate"`   //验证状态 0 未验证 1待验证 2验证成功
}

type AchieveTask map[int]*AchieveTaskBase

func NewAchieveTask() map[int]*AchieveTaskBase {
	return make(map[int]*AchieveTaskBase)
}

func (at AchieveTask) RefreshAchieveTask() {
	ret := data.AchieveTaskConfig.GetAll()

	for _, t := range at {
		if _, ok := ret[t.ID]; !ok {
			delete(at, t.ID)
		}
	}

	for _, d := range ret {
		if _, ok := at[d.ID]; !ok {
			at[d.ID] = &AchieveTaskBase{
				ID:        d.ID,
				Type:      d.Type,
				RewardNum: 0,
				Num:       0,
				Status:    0,
			}
		}
		at[d.ID].Condition = d.Condition
		at[d.ID].Order = d.Order
		at[d.ID].Url = d.Url
		at[d.ID].Icon = d.Icon
		at[d.ID].Reward = d.Reward
	}
}
