package wxuser

import (
	"common/remark"
	"common/resultStatus"
	"common/webServer"
	"goutil/logUtilPlus"
)

func init() {

	//注册接口
	webServer.RegisterFunction(new(WxuserApi))
}

func init() {
	moduleName := "WxuserApi"
	desc := "用户接口"
	author := "youjinlan"
	mendor := ""
	date := "2025-12-21 09:40:00"
	remark.RegisterModuleRemark(moduleName, desc, author, mendor, date)
}

// UserApi 用户接口
type WxuserApi struct {
}

// ---------------------------------------- 接口 --------------------------------------------------
func init() {
	moduleName := "WxuserApi"
	methodName := "LoginByWechat"
	skipVerifyTokenPage := true
	methodDesc := "微信登录"
	methodAuthor := "youjinlan"
	methodMendor := ""
	methodDate := "2025-01-21 09:40:00"
	methodInParam := []string{"string code int32 severId"}
	methodOutParam := `
	{
		"Code '类型:int'": "响应结果的状态值",
		"Message '类型:string'": "响应结果的状态值所对应的描述信息",
		"Data '类型:interface{}'": "响应结果的数据"
		{
			"Uid '类型:int64'": "用户对应区服的唯一Id",
		}
	}`
	remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
}
func (a *WxuserApi) LoginByWechat(code string, severId int32) (responseObj *webServer.ResponseObject) {
	responseObj = webServer.GetInitResponseObj()
	if code == "" {
		logUtilPlus.ErrorLog("Wrongcode,code为空")
		responseObj.SetResultStatus(resultStatus.APIDataError)
		return
	}
	res, uid := GetWechatsdkService().GetAccessToken(code, severId)
	if res != resultStatus.Success {
		responseObj.SetResultStatus(res)
	}
	if uid != 0 {
		resultMap := make(map[string]any)
		resultMap["Uid"] = uid
		responseObj.SetData(resultMap)
	}
	return
}

func init() {
	moduleName := "WxuserApi"
	methodName := "LoginOut"
	skipVerifyTokenPage := true
	methodDesc := "下线通知"
	methodAuthor := "youjinlan"
	methodMendor := ""
	methodDate := "2025-01-21 11:00:00"
	methodInParam := []string{"string openid,int32 severId"}
	methodOutParam := `
	{
		"Code '类型:int'": "响应结果的状态值",
		"Message '类型:string'": "响应结果的状态值所对应的描述信息",
		"Data '类型:interface{}'": "响应结果的数据"
		{
			
		}
	}`
	remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
}

func (a *WxuserApi) LoginOut(uid int64) (responseObj *webServer.ResponseObject) {
	responseObj = webServer.GetInitResponseObj()
	if uid == 0 {
		logUtilPlus.ErrorLog("uid=0")
		responseObj.SetResultStatus(resultStatus.APIDataError)
		return
	}
	RecordLoginOut(uid)
	return
}

func init() {
	moduleName := "WxuserApi"
	methodName := "SwitchSever"
	skipVerifyTokenPage := true
	methodDesc := "切服通知"
	methodAuthor := "youjinlan"
	methodMendor := ""
	methodDate := "2025-01-21 14:40:00"
	methodInParam := []string{"string openid,int32 oldseverId,int32 newseverId"}
	methodOutParam := `
	{
		"Code '类型:int'": "响应结果的状态值",
		"Message '类型:string'": "响应结果的状态值所对应的描述信息",
		"Data '类型:interface{}'": "响应结果的数据"
		{
			"Uid '类型:int64'": "切服后的区服的唯一Id",
		}
	}`
	remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
}

func (a *WxuserApi) SwitchSever(uid int64, oldseverId, newseverId int32) (responseObj *webServer.ResponseObject) {
	responseObj = webServer.GetInitResponseObj()
	if uid == 0 || oldseverId == 0 || newseverId == 0 {
		logUtilPlus.ErrorLog("WxuserApi.SwitchSever参数不正确")
		responseObj.SetResultStatus(resultStatus.APIDataError)
		return
	}
	if oldseverId == newseverId {
		logUtilPlus.ErrorLog("WxuserApi.SwitchSever参数不正确")
		responseObj.SetResultStatus(resultStatus.APIDataError)
		return
	}
	SwitchSever(uid, oldseverId, newseverId)
	return
}

func init() {
	moduleName := "WxuserApi"
	methodName := "WatchAD"
	skipVerifyTokenPage := true
	methodDesc := "看广告通知"
	methodAuthor := "youjinlan"
	methodMendor := ""
	methodDate := "2025-01-22 10:40:00"
	methodInParam := []string{"int64 uid"}
	methodOutParam := `
	{
		"Code '类型:int'": "响应结果的状态值",
		"Message '类型:string'": "响应结果的状态值所对应的描述信息",
		"Data '类型:interface{}'": "响应结果的数据"
		{
			
		}
	}`
	remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
}

func (a *WxuserApi) WatchAD(uid int64) (responseObj *webServer.ResponseObject) {
	responseObj = webServer.GetInitResponseObj()
	if uid == 0 {
		logUtilPlus.ErrorLog("uid=0")
		responseObj.SetResultStatus(resultStatus.APIDataError)
		return
	}
	RecordWatchAD(uid)
	return
}
