package main

import (
	"campaign-pool-be/app/database"
	"campaign-pool-be/app/middleware"
	"campaign-pool-be/app/module/activity_logs"
	"campaign-pool-be/app/module/campaign_destinations"
	"campaign-pool-be/app/module/campaign_files"
	"campaign-pool-be/app/module/campaign_types"
	"campaign-pool-be/app/module/campaigns"
	"campaign-pool-be/app/module/custom_static_pages"
	"campaign-pool-be/app/module/user_levels"
	"campaign-pool-be/app/module/user_role_accesses"
	"campaign-pool-be/app/module/user_role_level_details"
	"campaign-pool-be/app/module/user_roles"
	"campaign-pool-be/app/module/users"
	"campaign-pool-be/app/router"
	"campaign-pool-be/config/config"
	"campaign-pool-be/config/logger"
	"campaign-pool-be/config/webserver"
	"time"

	fxzerolog "github.com/efectn/fx-zerolog"
	"go.uber.org/fx"
)

func main() {

	fx.New(
		/* provide patterns */
		// config
		fx.Provide(config.NewConfig),
		// logging
		fx.Provide(logger.NewLogger),
		// fiber
		fx.Provide(webserver.NewFiber),
		// database
		fx.Provide(database.NewDatabase),
		// middleware
		fx.Provide(middleware.NewMiddleware),
		// data storage
		fx.Provide(config.NewMinio),
		// user management
		fx.Provide(config.NewKeycloakConfig),
		// router
		fx.Provide(router.NewRouter),
		// smtp config
		fx.Provide(config.NewSmtpConfig),

		// provide modules
		activity_logs.NewActivityLogsModule,
		custom_static_pages.NewCustomStaticPagesModule,
		user_levels.NewUserLevelsModule,
		user_roles.NewUserRolesModule,
		user_role_accesses.NewUserRoleAccessesModule,
		users.NewUsersModule,
		user_role_level_details.NewUserRoleLevelDetailsModule,

		// Campaign modules
		campaign_types.NewCampaignTypesModule,
		campaign_destinations.NewCampaignDestinationsModule,
		campaigns.NewCampaignsModule,
		campaign_files.NewCampaignFilesModule,

		// start aplication
		fx.Invoke(webserver.Start),

		// start scheduling
		fx.Invoke(webserver.RunScheduling),

		// define logger
		fx.WithLogger(fxzerolog.Init()),

		fx.StartTimeout(600*time.Second),
	).Run()
}
