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/advertisement"
	"campaign-pool-be/app/module/ai_chat"
	"campaign-pool-be/app/module/article_approvals"
	"campaign-pool-be/app/module/article_categories"
	"campaign-pool-be/app/module/article_category_details"
	"campaign-pool-be/app/module/article_comments"
	"campaign-pool-be/app/module/article_files"
	"campaign-pool-be/app/module/articles"
	"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/chat"
	"campaign-pool-be/app/module/cities"
	"campaign-pool-be/app/module/custom_static_pages"
	"campaign-pool-be/app/module/districts"
	"campaign-pool-be/app/module/ebooks"
	"campaign-pool-be/app/module/education_history"
	"campaign-pool-be/app/module/feedbacks"
	"campaign-pool-be/app/module/magazine_files"
	"campaign-pool-be/app/module/magazines"
	"campaign-pool-be/app/module/master_menus"
	"campaign-pool-be/app/module/master_modules"
	"campaign-pool-be/app/module/provinces"
	"campaign-pool-be/app/module/research_journals"
	"campaign-pool-be/app/module/subscription"
	"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/module/work_history"
	"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,
		advertisement.NewAdvertisementModule,
		ai_chat.NewAIChatModule,
		article_categories.NewArticleCategoriesModule,
		article_category_details.NewArticleCategoryDetailsModule,
		article_files.NewArticleFilesModule,
		article_approvals.NewArticleApprovalsModule,
		articles.NewArticlesModule,
		article_comments.NewArticleCommentsModule,
		chat.NewChatModule,
		cities.NewCitiesModule,
		custom_static_pages.NewCustomStaticPagesModule,
		districts.NewDistrictsModule,
		ebooks.NewEbooksModule,
		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,
		education_history.NewEducationHistoryModule,
		work_history.NewWorkHistoryModule,
		research_journals.NewResearchJournalsModule,

		// 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()
}
