package Var

import "fmt"

const (
	// 每日刷新变量
	DAILY_CARD_GIVE = 0 // 每日请求卡牌次数
)

type Var struct {
	DailyVar        map[int]interface{}
	WeeklyVar       map[int]interface{}
	MonthVar        map[int]interface{}
	Var             map[int]interface{}
	DailyResetTime  int64
	WeeklyResetTime int64
	MonthResetTime  int64
	NoonResetTime   int64
}

func (v *Var) InitData() {
	if v.DailyVar == nil {
		v.DailyVar = make(map[int]interface{})
		v.WeeklyVar = make(map[int]interface{})
		v.MonthVar = make(map[int]interface{})
	}
	if v.Var == nil {
		v.Var = make(map[int]interface{})
	}
}

func (v *Var) SetDailyVar(key int, value interface{}) {
	v.DailyVar[key] = value
}

func (v *Var) GetDailyVar(key int) (interface{}, error) {
	val, ok := v.DailyVar[key]
	if !ok {
		return nil, fmt.Errorf("key %d not exist", key)
	}
	return val, nil
}

func (v *Var) SetWeeklyVar(key int, value interface{}) {
	v.WeeklyVar[key] = value
}

func (v *Var) GetWeeklyVar(key int) (interface{}, error) {
	val, ok := v.WeeklyVar[key]
	if !ok {
		return nil, fmt.Errorf("key %d not exist", key)
	}
	return val, nil
}

func (v *Var) SetMonthVar(key int, value interface{}) {
	v.MonthVar[key] = value
}

func (v *Var) GetMonthVar(key int) (interface{}, error) {
	val, ok := v.MonthVar[key]
	if !ok {
		return nil, fmt.Errorf("key %d not exist", key)
	}
	return val, nil
}

func (v *Var) SetVar(key int, value interface{}) {
	v.Var[key] = value
}

func (v *Var) GetVar(key int) (interface{}, error) {
	val, ok := v.Var[key]
	if !ok {
		return nil, fmt.Errorf("key %d not exist", key)
	}
	return val, nil
}
