package comcode

import (
	"active/tools"
	"fmt"
)

var conf = &Config{}

type Config struct {
	AwardMap      map[string][][]int64 `json:"award_map" yaml:"award_map"`
	LimitMap      map[string]int       `json:"limit_map" yaml:"limit_map"`
	DailyLimitMap map[string]int       `json:"daily_limit_map" yaml:"daily_limit_map"`
	NameMap       map[string]string    `json:"name_map" yaml:"name_map"`
	ChannelAPPMap map[string][][]int32 `json:"channel_app_map" yaml:"channel_app_map"`
	ErrMap        map[string]string    `json:"err_map" yaml:"err_map"`
	TotalNumber   map[string]int       `json:"total_number" yaml:"total_number"`
	OpenTime      map[string]int64     `json:"open_time" yaml:"open_time"`
	EndTime       map[string]int64     `json:"end_time" yaml:"end_time"`
	KbljVip888    map[string]int64     `json:"kblj_vip888" yaml:"kblj_vip888"`
	KbljOpentime  int64                `json:"kblj_opentime" yaml:"kblj_opentime"`
	KbljEndtime   int64                `json:"kblj_endtime" yaml:"kblj_endtime"`
	CommonCode    map[string]int       `json:"commoncode" yaml:"commoncode"`
	ZBCode        ZBCodeConfig         `json:"zb_code" yaml:"zb_code"` // zb类型兑换码
	FLCode        ZBCodeConfig         `json:"fl_code" yaml:"fl_code"` // fl类型兑换码
	WeileCode     WeileCodeConfig      `json:"weile888" yaml:"weile888"`
	Weile666Code  WeileCodeConfig      `json:"weile666" yaml:"weile666"`
	WL777Code     WeileCodeConfig      `json:"wl777" yaml:"wl777"`
	WLCJ666Code   WeileCodeConfig      `json:"wlcj666" yaml:"wlcj666"`
	Vip9999       WeileCodeConfig      `json:"vip9999" yaml:"vip9999"` //【ID1024244】【web】提供通码,斗地主直播研究院用
	Vip666        WeileCodeConfig      `json:"vip666" yaml:"vip666"`   // 【ID1013546】【web】生成一个通用兑换码vip666
	WL1001        WeileCodeConfig      `json:"wl1001" yaml:"wl1001"`   // 【ID1013546】【web】生成一个通用兑换码vip666
	Common8       Common8CodeConfig    `json:"common8" yaml:"common8"` // 【ID1025900】【活动】通用兑换码需求
}

// ZB类型兑换码
type ZBCodeConfig struct {
	Code     []string  `yaml:"code"`      //兑换码
	Prob     []int     `yaml:"prob"`      //概率
	Award    [][]int64 `yaml:"award"`     //豆豆奖励范围
	OpenTime int       `yaml:"open_time"` //开始时间
	EndTime  int       `yaml:"end_time"`  //结束时间
}

// weile类型兑换码
type WeileCodeConfig struct {
	Code     string    `yaml:"code"`      //兑换码
	Award    [][]int64 `yaml:"award"`     //豆豆奖励
	OpenTime int       `yaml:"open_time"` //开始时间
	EndTime  int       `yaml:"end_time"`  //结束时间
	AppId    []int     `yaml:"appid"`     //appid
	Channel  []int     `yaml:"channel"`   //渠道
}
type Common8CodeConfig struct {
	Code     []string  `yaml:"code"`      //兑换码
	Award    [][]int64 `yaml:"award"`     //豆豆奖励
	OpenTime int       `yaml:"open_time"` //开始时间
	EndTime  int       `yaml:"end_time"`  //结束时间
	AppId    []int     `yaml:"appid"`     //appid
	Channel  []int     `yaml:"channel"`   //渠道
}

func Init() {
	tools.ReloadYaml("comcode.yaml", conf)
}

func ConfInstance() *Config {
	return conf
}

func (this *Config) GetAwardList(activeId string, awardId int64) [][]int64 {
	awardList, result := this.AwardMap[fmt.Sprintf("%v_%v", activeId, awardId)]
	if !result {
		return [][]int64{}
	}
	tmp := make([][]int64, len(awardList))
	copy(tmp, awardList)
	return tmp
}
