package newsign

import (
	"active/tools"
	"fmt"
	"sync"
)

var (
	NewSignconf   = &NewSignConfig{}
	NewSignconfv3 = &NewSignConfig{}
	SignConfPool  = sync.Pool{
		New: func() interface{} {
			temp := &NewSignConfig{}
			for _, config := range NewSignconf.Config {
				temp.Config = append(temp.Config, config)
			}
			return temp
		},
	}
	SignConfPoolv3 = sync.Pool{
		New: func() interface{} {
			temp := &NewSignConfig{}
			for _, config := range NewSignconfv3.Config {
				t := config
				temp.Config = append(temp.Config, t)
			}
			return temp
		},
	}
)

type NewSignConfig struct {
	Config []struct {
		Index      int       `json:"index" yaml:"index"`
		BasicBean  int64     `json:"basic_bean" yaml:"basic_bean" `
		Multi      int64     `json:"multi" yaml:"multi" `
		RealBean   int64     `json:"real_bean" yaml:"real_bean" `
		Awards     [][]int64 `json:"awards" yaml:"awards" `
		IsUp       bool      `json:"is_up" yaml:"is_up" `
		TimeStamp  int64     `json:"time_stamp" yaml:"time_stamp" `
		CanUpgrade bool      `json:"can_upgrade" yaml:"can_upgrade"`
		CanReceive bool      `json:"can_receive" yaml:"can_receive"`
		AdReceive  bool      `json:"ad_receive" yaml:"ad_receive"`
		Date       string    `json:"date" yaml:"date"`
		IsAd       bool      `json:"is_ad" yaml:"is_ad"`
	} `json:"config"`
	NewTime int64 `json:"-" yaml:"new_time"`
}

func NewSignConfigPreload() {
	tools.ReloadYaml("newsign.yaml", NewSignconf)
	for i := range NewSignconf.Config {
		NewSignconf.Config[i].Index = i + 1
		NewSignconf.Config[i].RealBean = NewSignconf.Config[i].BasicBean * NewSignconf.Config[i].Multi
		NewSignconf.Config[i].Awards = append(NewSignconf.Config[i].Awards, []int64{15, NewSignconf.Config[i].RealBean})
	}

	tools.ReloadYaml("newsign3.yaml", NewSignconfv3)
	for i := range NewSignconfv3.Config {
		NewSignconfv3.Config[i].Index = i + 1
		NewSignconfv3.Config[i].RealBean = NewSignconfv3.Config[i].BasicBean * NewSignconfv3.Config[i].Multi
		NewSignconfv3.Config[i].Awards = append(NewSignconfv3.Config[i].Awards, []int64{15, NewSignconfv3.Config[i].RealBean})
	}
	fmt.Printf("处理后 NewSignconf: %+v \n", NewSignconf)
	fmt.Printf("处理后 NewSignconfv3: %+v \n", NewSignconfv3)
}
