package routes

import (
	"gifuu/tools"
	"net/http"
)

func DELETE_Moderation_Art_ID(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	paramID := tools.ParseSnowflake(r.PathValue("id"))
	if paramID == 0 {
		tools.SendClientError(w, r, tools.ERROR_BODY_INVALID_FIELD)
		return
	}

	// Delete Art
	tag, err := tools.Database.Exec(ctx,
		`DELETE FROM gifuu.upload WHERE id = $1`,
		paramID,
	)
	if err != nil {
		tools.SendServerError(w, r, err)
		return
	}
	if tag.RowsAffected() == 0 {
		tools.SendClientError(w, r, tools.ERROR_GENERIC_UNAUTHORIZED)
		return
	}

	go RemoveFilesForArt(paramID)

	w.WriteHeader(http.StatusNoContent)
}
