package user_admin

import (
	"context"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"

	"git.noahlan.cn/n-admin/n-admin-server/api/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/api/internal/types"

	"net/http"
)

type UpdateUserAdminLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

func NewUpdateUserAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserAdminLogic {
	return &UpdateUserAdminLogic{
		r:      r,
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateUserAdminLogic) UpdateUserAdmin(req *types.UserInfo) error {
	_, err := l.svcCtx.CoreRpc.UpdateUser(l.ctx, &core.UserInfo{
		ID:       req.ID,
		Nickname: req.Nickname,
		Metas:    req.Metas,
	})
	if err != nil {
		return err
	}
	return nil
}
