package internalhttp

import (
	adshttp "legalgo-BE-go/internal/api/http/ads"
	categoryhttp "legalgo-BE-go/internal/api/http/category"
	logshttp "legalgo-BE-go/internal/api/http/logs"
	newshttp "legalgo-BE-go/internal/api/http/news"
	osshttp "legalgo-BE-go/internal/api/http/oss"
	staffhttp "legalgo-BE-go/internal/api/http/staff"
	subscribehttp "legalgo-BE-go/internal/api/http/subscribe"
	subscribeplanhttp "legalgo-BE-go/internal/api/http/subscribe_plan"
	taghttp "legalgo-BE-go/internal/api/http/tag"
	userhttp "legalgo-BE-go/internal/api/http/user"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/cors"
	"github.com/go-playground/validator/v10"
	"go.uber.org/fx"

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

var Module = fx.Module("router",
	fx.Provide(
		initRouter,
		validator.New,
	),
	staffhttp.Module,
	subscribeplanhttp.Module,
	taghttp.Module,
	categoryhttp.Module,
	newshttp.Module,
	osshttp.Module,
	userhttp.Module,
	subscribehttp.Module,
	adshttp.Module,
	logshttp.Module,
)

func initRouter() chi.Router {
	router := chi.NewRouter()
	localCors := cors.New(cors.Options{
		AllowedOrigins:   []string{"*"},
		AllowedMethods:   []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
		AllowedHeaders:   []string{"Accept", "Content-Type", "Authorization", "X-Device", "X-Client-Ip"},
		AllowCredentials: true,
		Debug:            true,
	})

	router.Use(
		localCors.Handler,
		chimware.RequestID,
	)

	return router
}
