package logshttp

import (
	authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
	logssvc "legalgo-BE-go/internal/services/logs"
	"legalgo-BE-go/internal/utilities/response"
	"legalgo-BE-go/internal/utilities/utils"
	"net/http"

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

func GetUserAds(
	router chi.Router,
	logSvc logssvc.Log,
) {
	router.With(authmiddleware.Authorize()).Get("/logs/ads", func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

		userDetail, err := utils.GetTokenDetail(r)

		subsPlan, err := logSvc.GetAllLogAds(userDetail.ID)
		if err != nil {
			response.ResponseWithErrorCode(
				ctx,
				w,
				err,
				response.ErrBadRequest.Code,
				response.ErrBadRequest.HttpCode,
				err.Error(),
			)
			return
		}

		response.RespondJsonSuccess(ctx, w, subsPlan)
	})
}
