package user_role

import (
	"context"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/user"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
	"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
	"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"

	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
)

type UserClearRoleLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserClearRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserClearRoleLogic {
	return &UserClearRoleLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// UserClearRole 用户清理角色
func (l *UserClearRoleLogic) UserClearRole(in *core.IDReq) (*core.BaseResp, error) {
	err := l.svcCtx.DB.User.Update().
		Where(user.IDEQ(in.ID)).
		ClearRoles().
		Exec(l.ctx)
	if err != nil {
		return nil, hander.HandleEntErr(err, in)
	}
	return &core.BaseResp{
		Code: code.StatusOK,
		Msg:  msg.UpdateSuccess,
	}, nil
}
