//go:build wireinject
// +build wireinject

package wire

import (
	"github.com/go-nunu/nunu-layout-advanced/internal/handler"
	"github.com/go-nunu/nunu-layout-advanced/internal/middleware"
	"github.com/go-nunu/nunu-layout-advanced/internal/repository"
	"github.com/go-nunu/nunu-layout-advanced/internal/server"
	"github.com/go-nunu/nunu-layout-advanced/internal/service"
	"github.com/go-nunu/nunu-layout-advanced/pkg/app"
	"github.com/go-nunu/nunu-layout-advanced/pkg/jwt"
	"github.com/go-nunu/nunu-layout-advanced/pkg/limiter"
	"github.com/go-nunu/nunu-layout-advanced/pkg/log"
	"github.com/go-nunu/nunu-layout-advanced/pkg/server/http"
	"github.com/go-nunu/nunu-layout-advanced/pkg/sid"
	"github.com/google/wire"
	"github.com/spf13/viper"
)

var repositorySet = wire.NewSet(
	repository.NewDB,
	repository.NewRedis,
	repository.NewCasbinEnforcer,
	repository.NewMongoClient,
	repository.NewMongoDB,
	repository.NewRabbitMQ,
	repository.NewRepository,
	repository.NewTransaction,
	repository.NewAdminRepository,
	repository.NewUserRepository,
	repository.NewGameShieldRepository,
	repository.NewGameShieldPublicIpRepository,
	repository.NewWebForwardingRepository,
	repository.NewTcpforwardingRepository,
	repository.NewUdpForWardingRepository,
	repository.NewGameShieldUserIpRepository,
	repository.NewWebLimitRepository,
	repository.NewTcpLimitRepository,
	repository.NewUdpLimitRepository,
	repository.NewGameShieldBackendRepository,
	repository.NewGameShieldSdkIpRepository,
	repository.NewHostRepository,
	repository.NewGlobalLimitRepository,
	repository.NewGatewayGroupRepository,
	repository.NewGateWayGroupIpRepository,
	repository.NewCdnRepository,

)

var serviceSet = wire.NewSet(
	service.NewService,
	service.NewAoDunService,
	service.NewUserService,
	service.NewAdminService,
	service.NewGameShieldService,
	
	service.NewGameShieldPublicIpService,
	service.NewDuedateService,
	service.NewFormatterService,
	service.NewParserService,
	service.NewRequiredService,
	service.NewCrawlerService,
	service.NewWebForwardingService,
	service.NewTcpforwardingService,
	service.NewUdpForWardingService,
	service.NewGameShieldUserIpService,
	service.NewWebLimitService,
	service.NewTcpLimitService,
	service.NewUdpLimitService,
	service.NewGameShieldBackendService,
	service.NewGameShieldSdkIpService,
	service.NewHostService,
	service.NewGlobalLimitService,
	service.NewGatewayGroupService,
	service.NewWafFormatterService,
	service.NewGateWayGroupIpService,
	service.NewRequestService,
	service.NewCdnService,
)

var handlerSet = wire.NewSet(
	handler.NewHandler,
	handler.NewUserHandler,
	handler.NewAdminHandler,
	handler.NewGameShieldHandler,
	handler.NewGameShieldPublicIpHandler,
	handler.NewWebForwardingHandler,
	handler.NewTcpforwardingHandler,
	handler.NewUdpForWardingHandler,
	handler.NewGameShieldUserIpHandler,
	handler.NewWebLimitHandler,
	handler.NewTcpLimitHandler,
	handler.NewUdpLimitHandler,
	handler.NewGameShieldBackendHandler,
	handler.NewGameShieldSdkIpHandler,
	handler.NewHostHandler,
	handler.NewGlobalLimitHandler,
	handler.NewGatewayGroupHandler,
	handler.NewGateWayGroupIpHandler,
)



// 限流器依赖集
var limiterSet = wire.NewSet(
	limiter.NewLimiter,
	middleware.NewRateLimitMiddleware,
)

var serverSet = wire.NewSet(
	server.NewHTTPServer,
	
)

// build App
func newApp(
	httpServer *http.Server,
) *app.App {
	return app.NewApp(
		app.WithServer(httpServer),
		app.WithName("demo-server"),
	)
}

func NewWire(*viper.Viper, *log.Logger) (*app.App, func(), error) {
	panic(wire.Build(
		repositorySet,
		serviceSet,
		handlerSet,

		serverSet,
		limiterSet,
		sid.NewSid,
		jwt.NewJwt,
		newApp,
	))
}
