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

package player

import (
	"context"
	"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 GetServiceLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取服务详情
func NewGetServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetServiceLogic {
	return &GetServiceLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetServiceLogic) GetService(req *types.GetServiceReq) (resp *types.PlayerService, err error) {
	s, err := l.svcCtx.PlayerRpc.GetPlayerServicesById(l.ctx, &playerservice.GetPlayerServicesByIdReq{
		Id: req.Id,
	})
	if err != nil {
		logx.Errorf("GetServiceLogic.GetService err: %v", err)
		return nil, err
	}

	resp = &types.PlayerService{}
	err = copier.Copy(resp, s.PlayerServices)
	if err != nil {
		logx.Errorf("GetServiceLogic.GetService err: %v", err)
		return nil, err
	}
	return
}
