package controller

import (
	mhayaGin "github.com/mhaya/components/gin"
	"github.com/mhaya/game/game_cluster/internal/code"
	"github.com/mhaya/game/game_cluster/internal/constant"
	"github.com/mhaya/game/game_cluster/internal/param"
	mhayaLogger "github.com/mhaya/logger"
)

func (p *Controller) signIn(c *mhayaGin.Context) {
	token, err := p.Auth(c)
	if code.IsFail(err) {
		mhayaLogger.Warnf("if signIn token err {. params=%s", c.GetHeader(constant.Token))
		code.RenderResult(c, code.AccountTokenValidateFail)
		return
	}

	resp := &param.ChangeData{}
	ctl, ok := p.GetChildActor(token.PlayerID)
	if !ok {
		code.RenderResult(c, code.Error)
		return
	}
	errCode := ctl.CallWait(token.TargetPath, "signIn", nil, resp)
	if code.IsFail(errCode) {
		mhayaLogger.Warnf("[signIn] param = nil, errCode = %v", errCode)
		code.RenderResult(c, errCode)
		return
	}
	code.RenderResult(c, code.OK, resp)
}
