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) invite(c *mhayaGin.Context) {

	var pa param.InviteReq
	if err := c.BindJSON(&pa); err != nil {
		mhayaLogger.Warnf("if guide err {. params=%s", pa)
		code.RenderResult(c, code.Error)
		return
	}
	if pa.ParentName == "" {
		code.RenderResult(c, code.Error)
		return
	}

	_, err := p.Auth(c)
	if code.IsFail(err) {
		mhayaLogger.Warnf("if invite token err {. params=%s", c.GetHeader(constant.Token))
		code.RenderResult(c, code.AccountTokenValidateFail)
		return
	}

	code.RenderResult(c, code.OK)
}
