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) itemWeekRecord(c *mhayaGin.Context) {
	token, err := p.Auth(c)
	if code.IsFail(err) {
		mhayaLogger.Warnf("if itemWeekRecord token err {. params=%s", c.GetHeader(constant.Token))
		code.RenderResult(c, code.AccountTokenValidateFail)
		return
	}

	ctl, ok := p.GetChildActor(token.PlayerID)
	if !ok {
		code.RenderResult(c, code.Error)
		return
	}

	var pa param.ItemRecordReq
	if err := c.BindJSON(&pa); err != nil {
		mhayaLogger.Warnf("if guide err {. params=%s", pa)
		code.RenderResult(c, code.Error)
		return
	}
	var resp = &param.ItemRecordResp{}
	errCode := ctl.CallWait(token.TargetPath, "itemWeekRecord", &pa, resp)
	if code.IsFail(errCode) {
		mhayaLogger.Warnf("[itemWeekRecord] param = %v, errCode = %v", errCode)
		code.RenderResult(c, errCode)
		return
	}
	code.RenderResult(c, code.OK, resp)
}

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

	ctl, ok := p.GetChildActor(token.PlayerID)
	if !ok {
		code.RenderResult(c, code.Error)
		return
	}

	var resp = &param.InviteRatioResp{}
	errCode := ctl.CallWait(token.TargetPath, "inviteRewardRatioHistory", nil, resp)
	if code.IsFail(errCode) {
		mhayaLogger.Warnf("[inviteRewardRatioHistory] param = %v, errCode = %v", errCode)
		code.RenderResult(c, errCode)
		return
	}
	code.RenderResult(c, code.OK, resp)
}
