package main

import (
	fxzerolog "github.com/efectn/fx-zerolog"
	"go.uber.org/fx"
	"time"
	"web-medols-be/app/database"
	"web-medols-be/app/middleware"
	"web-medols-be/app/module/activity_logs"
	"web-medols-be/app/module/advertisement"
	"web-medols-be/app/module/article_approvals"
	"web-medols-be/app/module/article_categories"
	"web-medols-be/app/module/article_category_details"
	"web-medols-be/app/module/article_comments"
	"web-medols-be/app/module/article_files"
	"web-medols-be/app/module/article_nulis_ai"
	"web-medols-be/app/module/articles"
	"web-medols-be/app/module/cities"
	"web-medols-be/app/module/clients"
	"web-medols-be/app/module/custom_static_pages"
	"web-medols-be/app/module/districts"
	"web-medols-be/app/module/feedbacks"
	"web-medols-be/app/module/magazine_files"
	"web-medols-be/app/module/magazines"
	"web-medols-be/app/module/master_menus"
	"web-medols-be/app/module/master_modules"
	"web-medols-be/app/module/provinces"
	"web-medols-be/app/module/subscription"
	"web-medols-be/app/module/user_levels"
	"web-medols-be/app/module/user_role_accesses"
	"web-medols-be/app/module/user_role_level_details"
	"web-medols-be/app/module/user_roles"
	"web-medols-be/app/module/users"
	"web-medols-be/app/router"
	"web-medols-be/config/config"
	"web-medols-be/config/logger"
	"web-medols-be/config/webserver"
)

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,
		advertisement.NewAdvertisementModule,
		article_categories.NewArticleCategoriesModule,
		article_category_details.NewArticleCategoryDetailsModule,
		article_files.NewArticleFilesModule,
		article_approvals.NewArticleApprovalsModule,
		articles.NewArticlesModule,
		article_comments.NewArticleCommentsModule,
		article_nulis_ai.NewArticleNulisAIModule,
		cities.NewCitiesModule,
		clients.NewClientsModule,
		custom_static_pages.NewCustomStaticPagesModule,
		districts.NewDistrictsModule,
		feedbacks.NewFeedbacksModule,
		magazines.NewMagazinesModule,
		magazine_files.NewMagazineFilesModule,
		master_menus.NewMasterMenusModule,
		master_modules.NewMasterModulesModule,
		provinces.NewProvincesModule,
		subscription.NewSubscriptionModule,
		user_levels.NewUserLevelsModule,
		user_roles.NewUserRolesModule,
		user_role_accesses.NewUserRoleAccessesModule,
		users.NewUsersModule,
		user_role_level_details.NewUserRoleLevelDetailsModule,

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

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

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

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