// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2

package player

import (
	"context"
	"errors"
	"juwan-backend/app/player/rpc/playerservice"

	"juwan-backend/app/player/api/internal/svc"
	"juwan-backend/app/player/api/internal/types"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type GetPlayerLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取打手详情
func NewGetPlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlayerLogic {
	return &GetPlayerLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetPlayerLogic) GetPlayer(req *types.GetPlayerReq) (resp *types.PlayerProfile, err error) {
	player, err := l.svcCtx.PlayerRpc.GetPlayersById(l.ctx, &playerservice.GetPlayersByIdReq{
		Id: req.Id,
	})
	if err != nil {
		logx.Errorf("GetPlayerLogic.GetPlayers err: %v", err)
		return nil, errors.New("failed to get player details")
	}
	resp = &types.PlayerProfile{}
	err = copier.Copy(resp, &player)
	if err != nil {
		logx.Errorf("copier.Copy err: %v", err)
		return nil, errors.New("copier.Copy err")
	}
	return
}
