package taghttp

import (
	"fmt"
	authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
	tagsvc "legalgo-BE-go/internal/services/tag"
	"legalgo-BE-go/internal/utilities/response"
	"net/http"

	"github.com/go-chi/chi/v5"
)

func Delete(
	router chi.Router,
	tagSvc tagsvc.Tag,
) {
	router.
		With(authmiddleware.Authorize()).
		Delete("/tag/{category_id}/delete", func(w http.ResponseWriter, r *http.Request) {
			ctx := r.Context()
			categoryID := chi.URLParam(r, "category_id")

			if categoryID == "" {
				response.RespondJsonErrorWithCode(
					ctx,
					w,
					fmt.Errorf("category id is not provided"),
					response.ErrBadRequest.Code,
					response.ErrBadRequest.HttpCode,
					"category id is not provided",
				)
				return
			}

			if err := tagSvc.Delete(categoryID); err != nil {
				response.RespondJsonErrorWithCode(
					ctx,
					w,
					err,
					response.ErrBadRequest.Code,
					response.ErrBadRequest.HttpCode,
					err.Error(),
				)
				return
			}

			response.RespondJsonSuccess(ctx, w, struct {
				Message string
			}{
				Message: "tag has been deleted",
			})
		})
}
