package users

import (
	"context"
	"net/http"

	"fr.latosa-escrima/core"
	"fr.latosa-escrima/core/models"
)

func HandleDelete(w http.ResponseWriter, r *http.Request) {
	uuid := r.PathValue("user_uuid")
	_, err := core.DB.NewDelete().
		Model((*models.User)(nil)).
		Where("user_id = ?", uuid).
		Exec(context.Background())

	if err != nil {
		core.JSONError{
			Status:  core.Error,
			Message: err.Error(),
		}.Respond(w, http.StatusInternalServerError)
		return
	}

	// TODO : Remove password
	core.JSONSuccess{
		Status:  core.Success,
		Message: "User deleted.",
		Data:    nil,
	}.Respond(w, http.StatusOK)
}
