package user

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 DeleteUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *DeleteUserLogic) DeleteUser(in *core.IDsReq) (*core.BaseResp, error) {
	// TODO 级联删除?
	_, err := l.svcCtx.DB.User.Delete().Where(user.IDIn(in.Ids...)).Exec(l.ctx)
	if err != nil {
		return nil, hander.HandleEntErr(err, in)
	}
	return &core.BaseResp{
		Code: code.StatusOK,
		Msg:  msg.DeleteSuccess,
	}, nil
}
