package gameServerMgr

import (
	"time"

	. "Framework/managecenterModel"
	"goutil/timeUtil"
	"goutil/typeUtil"
)

var (
	mServerGroupObj *ServerGroup
)

//解析服务器组信息
func ParseServerGroupInfo(serverGroupObj *ServerGroup) {
	mServerGroupObj = serverGroupObj
}

//获取服务器组对象
func GetServerGroup() (serverGroupObj *ServerGroup) {
	serverGroupObj = mServerGroupObj

	return
}

//检查服务器是否在维护
func CheckMaintainStatus() (maintainMessage string, isMaintaining bool) {
	serverGroupObj := GetServerGroup()
	nowTick := time.Now().Unix()
	if serverGroupObj.GroupState == int32(Con_GroupState_Maintain) || (serverGroupObj.MaintainBeginTimeTick <= nowTick && nowTick <= serverGroupObj.MaintainBeginTimeTick+int64(60*serverGroupObj.MaintainMinutes)) {
		maintainMessage = serverGroupObj.MaintainMessage
		isMaintaining = true

		return
	}

	return
}

//获取服务器维护开始时间时间戳
func GetMaintainBeginTime() (maintainBeginTimeTick int64) {
	serverGroupObj := GetServerGroup()
	maintainBeginTimeTick = serverGroupObj.MaintainBeginTimeTick

	return
}

//获取服务器维护持续时间 单位分钟
func GetMaintainMinutes() (maintainMinutes int32) {
	serverGroupObj := GetServerGroup()
	maintainMinutes = serverGroupObj.MaintainMinutes

	return
}

//获取服务器开服日期 时间戳
func GetServerOpenDate() (openTimeTick int64) {
	serverGroupObj := GetServerGroup()
	openTimeTick = serverGroupObj.OpenTimeTick

	return
}

//当前服务器已开服天数(开服第几天)
//当前开服天数 计算公式:(当前日期 - 开服日期)的总天数 + 1
func ServerOpenDays() (days int32) {
	serverGroupObj := GetServerGroup()
	if serverGroupObj.IsOpen() == false {
		return 0
	}

	//(当前日期 - 开服日期)的总天数 + 1
	openTimeTick := serverGroupObj.OpenTimeTick
	openDate, _ := typeUtil.DateTime(openTimeTick)
	days = int32(timeUtil.SubDay(time.Now(), openDate) + 1)

	return
}
