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

package user

import (
	"context"

	"sundynix-micro-go/app/system/api/internal/svc"
	"sundynix-micro-go/app/system/api/internal/types"
	"sundynix-micro-go/app/system/rpc/system"

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

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

// 用户详情（含角色信息）
func NewGetUserDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserDetailLogic {
	return &GetUserDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetUserDetailLogic) GetUserDetail(req *types.IdQueryReq) (resp *types.UserDetailResp, err error) {
	rpcResp, err := l.svcCtx.SystemRpc.GetUserDetail(l.ctx, &system.GetUserDetailReq{
		Id: req.Id,
	})
	if err != nil {
		return nil, err
	}

	return &types.UserDetailResp{
		Id:       rpcResp.Id,
		Name:     rpcResp.Name,
		Account:  rpcResp.Account,
		NickName: rpcResp.NickName,
		Phone:    rpcResp.Phone,
		RoleIds:  rpcResp.RoleIds,
	}, nil
}
