package subscribeplanhttp

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

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

func Delete(
	router chi.Router,
	subscribePlanSvc subscribeplansvc.SubscribePlan,
) {
	router.
		With(authmiddleware.Authorize()).
		Delete("/subscribe-plan/{subsplan_id}/delete", func(w http.ResponseWriter, r *http.Request) {
			ctx := r.Context()
			subsPlanID := chi.URLParam(r, "subsplan_id")

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

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

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