package sysUser

import (
	"context"

	v1 "kami/api/sysUser/v1"
	"kami/internal/errHandler"
	"kami/internal/service"
	"kami/utility/token"

	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"
)

func (c *ControllerV1) UserDelete(ctx context.Context, req *v1.UserDeleteReq) (res *v1.UserDeleteRes, err error) {
	if !token.IsFromIframe(ctx) {
		err = gerror.NewCode(gcode.CodeNotAuthorized)
		return
	}
	sysUserService := service.SysUser()
	err = sysUserService.DeleteById(ctx, req.ID)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "用户删除失败")
	}
	return
}
