package game

import (
	"reflect"
	"server/game/internal"
	"server/pkg/github.com/name5566/leaf/gate"
	"sort"
)

const (
	PLAYER_BASE_DATA = "PlayerBaseData"
	BASE_MODULE      = "base"
	CHESS_MODULE     = "chess"
)

const (
	onehour   = 3600
	oneday    = 24 * onehour
	sevendays = 7 * oneday
)

// 解析参数
func ParseArgs(args []interface{}) (gate.Agent, *Player, []byte) {
	a := args[0].(gate.Agent)
	p, _ := internal.Agents.Load(a)
	return a, p.(*Player), args[1].([]byte)
}

// 解析管理员参数
func ParseAdminArgs(args []interface{}) (gate.Agent, []byte) {
	a := args[0].(gate.Agent)
	buf := args[1].([]byte)
	return a, buf
}

// 获取结构体名称
func GetStructName(v interface{}) string {
	t := reflect.TypeOf(v)
	if t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	if t.Kind() == reflect.Struct {
		return t.Name()
	}
	return ""
}

// 判断两个切片的元素是否一致（忽略顺序）
func SlicesEqual(a, b []int) bool {
	if len(a) != len(b) {
		return false
	}
	// 创建副本以避免修改原始切片
	aCopy := make([]int, len(a))
	bCopy := make([]int, len(b))
	copy(aCopy, a)
	copy(bCopy, b)
	sort.Ints(aCopy)
	sort.Ints(bCopy)
	for i := range aCopy {
		if aCopy[i] != bCopy[i] {
			return false
		}
	}
	return true
}
