package stat

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
	"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
	"time"
)

type SetUserNewGameAuthReq struct {
	*requests.RpcRequest
}

type SetUserNewGameAuthResp struct {
	*responses.BaseResponse
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data Data   `json:"data"`
}

type Data struct {
	Result string `json:"result"`
}

const key = "gr_new_game"

// CreateSetUserNewGameAuthReq 设置用户新游戏授权
func CreateSetUserNewGameAuthReq(data map[string]string) *SetUserNewGameAuthReq {
	req := &SetUserNewGameAuthReq{
		&requests.RpcRequest{},
	}

	ts := time.Now().Unix()
	hash := md5.New()
	hash.Write([]byte(fmt.Sprintf("%v%v", ts, key)))
	hashBytes := hash.Sum(nil)

	token := hex.EncodeToString(hashBytes)

	req.InitWithApiInfo(HOST, VERSION, "/user/setUserNewGameAuth")
	req.Method = requests.POST

	req.FormParams = data
	if req.FormParams == nil {
		req.FormParams = make(map[string]string)
	}
	req.FormParams["sign"] = token
	req.FormParams["time"] = fmt.Sprintf("%v", ts)
	return req
}

// CreateSetUserNewGameAuthResp 创建设置用户新游戏授权响应
func CreateSetUserNewGameAuthResp() *SetUserNewGameAuthResp {
	return &SetUserNewGameAuthResp{
		BaseResponse: &responses.BaseResponse{},
	}
}

// ------------------------------------

// UserRoleReg 玩家汇总角色创建记录
type UserRoleReg struct {
	UserName  string `json:"user_name"`
	Uid       string `json:"uid"`
	RoleId    string `json:"role_id"`
	RoleName  string `json:"role_name"`
	GameSign  string `json:"game_sign"`
	Id        string `json:"id"`
	CreatedAt string `json:"created_at"`
}
type UserRoleRegPage struct {
	Page       int           `json:"page"`
	TotalCount int           `json:"total_count"`
	PageSize   int           `json:"page_size"`
	Data       []UserRoleReg `json:"data"`
}

type UserRoleRegParam struct {
	Page     int    `json:"page"`
	PageSize int    `json:"page_size"`
	RoleId   string `json:"role_id"`
	RoleName string `json:"role_name"`
}
type UserRoleRegReq struct {
	*requests.RpcRequest
}
type UserRoleRegResp struct {
	*responses.BaseResponse
	Code int             `json:"code"`
	Msg  string          `json:"msg"`
	Data UserRoleRegPage `json:"data"`
}

func CreateUserRoleRegPageReq(param UserRoleRegParam) *UserRoleRegReq {
	req := &UserRoleRegReq{
		&requests.RpcRequest{},
	}
	req.InitWithApiInfo(HOST, VERSION, "/user/getRoleRegPage")
	req.Method = requests.POST
	req.FormParams = map[string]string{
		"page":      fmt.Sprintf("%v", param.Page),
		"page_size": fmt.Sprintf("%v", param.PageSize),
		"role_id":   param.RoleId,
		"role_name": param.RoleName,
	}

	return req
}
func CreateUserRoleRegPageResp() *UserRoleRegResp {
	return &UserRoleRegResp{
		BaseResponse: &responses.BaseResponse{},
	}
}