package main

import (
	"netidhub-saas-be/app/database"
	"netidhub-saas-be/app/middleware"
	"netidhub-saas-be/app/module/activity_logs"
	"netidhub-saas-be/app/module/advertisement"
	"netidhub-saas-be/app/module/approval_workflow_steps"
	"netidhub-saas-be/app/module/approval_workflows"
	"netidhub-saas-be/app/module/article_approval_flows"
	"netidhub-saas-be/app/module/article_approval_step_logs"
	"netidhub-saas-be/app/module/article_approvals"
	"netidhub-saas-be/app/module/article_categories"
	"netidhub-saas-be/app/module/article_category_details"
	"netidhub-saas-be/app/module/article_comments"
	"netidhub-saas-be/app/module/article_files"
	"netidhub-saas-be/app/module/article_nulis_ai"
	"netidhub-saas-be/app/module/articles"
	"netidhub-saas-be/app/module/bookmarks"
	"netidhub-saas-be/app/module/cities"
	"netidhub-saas-be/app/module/client_approval_settings"
	"netidhub-saas-be/app/module/clients"
	"netidhub-saas-be/app/module/custom_static_pages"
	"netidhub-saas-be/app/module/districts"
	"netidhub-saas-be/app/module/feedbacks"
	"netidhub-saas-be/app/module/magazine_files"
	"netidhub-saas-be/app/module/magazines"
	"netidhub-saas-be/app/module/master_menus"
	"netidhub-saas-be/app/module/master_modules"
	"netidhub-saas-be/app/module/provinces"
	"netidhub-saas-be/app/module/schedules"
	"netidhub-saas-be/app/module/subscription"
	"netidhub-saas-be/app/module/user_levels"
	"netidhub-saas-be/app/module/user_role_accesses"
	"netidhub-saas-be/app/module/user_role_level_details"
	"netidhub-saas-be/app/module/user_roles"
	"netidhub-saas-be/app/module/users"
	"netidhub-saas-be/app/router"
	"netidhub-saas-be/config/config"
	"netidhub-saas-be/config/logger"
	"netidhub-saas-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,
		approval_workflows.NewApprovalWorkflowsModule,
		approval_workflow_steps.NewApprovalWorkflowStepsModule,
		article_approval_flows.NewArticleApprovalFlowsModule,
		article_approval_step_logs.NewArticleApprovalStepLogsModule,
		article_categories.NewArticleCategoriesModule,
		article_category_details.NewArticleCategoryDetailsModule,
		article_files.NewArticleFilesModule,
		article_approvals.NewArticleApprovalsModule,
		articles.NewArticlesModule,
		article_comments.NewArticleCommentsModule,
		article_nulis_ai.NewArticleNulisAIModule,
		bookmarks.NewBookmarksModule,
		cities.NewCitiesModule,
		client_approval_settings.NewClientApprovalSettingsModule,
		clients.NewClientsModule,
		custom_static_pages.NewCustomStaticPagesModule,
		districts.NewDistrictsModule,
		feedbacks.NewFeedbacksModule,
		magazines.NewMagazinesModule,
		magazine_files.NewMagazineFilesModule,
		master_menus.NewMasterMenusModule,
		master_modules.NewMasterModulesModule,
		provinces.NewProvincesModule,
		schedules.NewSchedulesModule,
		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()
}
