package wxbroadcastv2

import "sync"

var (
	confv2     Configv2
	upListConf UpListConf
	poolConfv2 = sync.Pool{
		New: newConfigV2,
	}
)

func newConfigV2() interface{} {
	temp := &Configv2{}
	for _, award := range confv2.AwardList {
		temp.AwardList = append(temp.AwardList, &Award{
			TaskId:       award.TaskId,
			AwardTitle:   award.AwardTitle,
			Bean:         award.Bean,
			AwardType:    award.AwardType,
			Type:         award.Type,
			TotalProcess: award.TotalProcess,
			Rate:         award.Rate,
			BeanList:     award.BeanList,
		})
	}
	for _, award := range confv2.AwardListV1 {
		temp.AwardListV1 = append(temp.AwardListV1, &Award{
			TaskId:       award.TaskId,
			AwardTitle:   award.AwardTitle,
			Bean:         award.Bean,
			AwardType:    award.AwardType,
			Type:         award.Type,
			TotalProcess: award.TotalProcess,
			Rate:         award.Rate,
			BeanList:     award.BeanList,
		})
	}
	return temp
}

type Configv2 struct {
	AwardList   []*Award `yaml:"award_list" json:"award_list"`
	AwardListV1 []*Award `yaml:"award_listv1" json:"award_listv1"`
	Time        int64    `json:"time"`
	GameNumber  int64    `json:"game_number"`
}

type Award struct {
	TaskId       int64     `json:"task_id" yaml:"task_id"`
	AwardTitle   string    `json:"award_title" yaml:"award_title"`
	Bean         int64     `json:"bean" yaml:"bean"`
	Rate         []int64   `json:"-" yaml:"rate"`
	BeanList     [][]int64 `json:"-" yaml:"bean_list"`
	AwardType    int64     `json:"award_type" yaml:"award_type"` // 0表示豆豆，1表示宝箱1， 2表示宝箱2， 3表示宝箱3， 4表示宝箱4
	Type         int64     `json:"type" yaml:"type"`             //0 首次 1 是局数 2 时间 3是 连续3天数 4 是连续4天数
	Status       int64     `json:"status" yaml:"status"`
	PreProcess   int64     `json:"pre_process" yaml:"pre_process"`
	TotalProcess int64     `json:"total_process" yaml:"total_process"`
}

func Instancev2() *sync.Pool {
	return &poolConfv2
}

func GetUpAwardListConf() (temp []*UpAward) {
	det := make([]UpAward, len(upListConf.UpawardList))
	copy(det, upListConf.UpawardList)
	for i := range det {
		temp = append(temp, &det[i])
	}
	return temp
}
