//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
//

package user

import (
	"github.com/veypi/vbase/cfg"
	"github.com/veypi/vbase/models"
	"github.com/veypi/vigo"
)

// DeleteRequest 删除用户请求
type DeleteRequest struct {
	UserID string `src:"path@user_id" desc:"用户ID"`
}

// del 删除用户
func del(x *vigo.X, req *DeleteRequest) error {
	var user models.User
	if err := cfg.DB().First(&user, "id = ?", req.UserID).Error; err != nil {
		return vigo.ErrNotFound
	}

	// 软删除
	if err := cfg.DB().Delete(&user).Error; err != nil {
		return vigo.ErrInternalServer.WithError(err)
	}

	return nil
}
