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

package game

import (
	"context"
	"juwan-backend/app/game/api/internal/svc"
	"juwan-backend/app/game/api/internal/types"
	"juwan-backend/app/game/rpc/pb"

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

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

// 获取游戏详情
func NewGetGameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGameLogic {
	return &GetGameLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetGameLogic) GetGame(req *types.GetGameReq) (resp *types.Game, err error) {
	// todo: add your logic here and delete this line
	game, err := l.svcCtx.GameRpc.GetGamesById(l.ctx, &pb.GetGamesByIdReq{Id: req.Id})
	if err != nil {
		return nil, err
	}
	return &types.Game{
		Id:       game.Games.Id,
		Name:     game.Games.Name,
		Icon:     game.Games.Icon,
		Category: game.Games.Category,
	}, nil
}
