package main

import (
	"jaecoo-be/app/database"
	"jaecoo-be/app/middleware"
	"jaecoo-be/app/module/activity_logs"
	"jaecoo-be/app/module/article_approvals"
	"jaecoo-be/app/module/article_categories"
	"jaecoo-be/app/module/article_category_details"
	"jaecoo-be/app/module/article_comments"
	"jaecoo-be/app/module/article_files"
	"jaecoo-be/app/module/articles"
	"jaecoo-be/app/module/banners"
	"jaecoo-be/app/module/cities"
	"jaecoo-be/app/module/custom_static_pages"
	"jaecoo-be/app/module/districts"
	"jaecoo-be/app/module/feedbacks"
	"jaecoo-be/app/module/galleries"
	"jaecoo-be/app/module/gallery_files"
	"jaecoo-be/app/module/product_specifications"
	"jaecoo-be/app/module/products"
	"jaecoo-be/app/module/promotions"
	"jaecoo-be/app/module/provinces"
	"jaecoo-be/app/module/sales_agents"
	"jaecoo-be/app/module/user_levels"
	"jaecoo-be/app/module/user_role_accesses"
	"jaecoo-be/app/module/user_role_level_details"
	"jaecoo-be/app/module/user_roles"
	"jaecoo-be/app/module/users"
	"jaecoo-be/app/router"
	"jaecoo-be/config/config"
	"jaecoo-be/config/logger"
	"jaecoo-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,
		article_categories.NewArticleCategoriesModule,
		article_category_details.NewArticleCategoryDetailsModule,
		article_files.NewArticleFilesModule,
		article_approvals.NewArticleApprovalsModule,
		articles.NewArticlesModule,
		article_comments.NewArticleCommentsModule,
		banners.NewBannersModule,
		cities.NewCitiesModule,
		custom_static_pages.NewCustomStaticPagesModule,
		districts.NewDistrictsModule,
		feedbacks.NewFeedbacksModule,
		galleries.NewGalleriesModule,
		gallery_files.NewGalleryFilesModule,
		product_specifications.NewProductSpecificationsModule,
		products.NewProductsModule,
		promotions.NewPromotionsModule,
		provinces.NewProvincesModule,
		sales_agents.NewSalesAgentsModule,
		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()
}
