package scraper

import (
	"fmt"

	"github.com/iancoleman/strcase"
	"github.com/logrusorgru/aurora/v4"
	"github.com/spf13/viper"
	"golang.org/x/exp/slices"

	"git.amok.space/yevhen/resource-scraper/internal/db"
	"git.amok.space/yevhen/resource-scraper/pkg/handler"
	"git.amok.space/yevhen/resource-scraper/pkg/repository"
	"git.amok.space/yevhen/resource-scraper/pkg/service"
	"git.amok.space/yevhen/resource-scraper/types/constant"
)

func isAllowScope() bool {
	scopesAllow := viper.GetStringSlice("scope.allow")
	scopeEnabled := viper.GetString(constant.FlagScopeEnable)

	return slices.Contains(scopesAllow, scopeEnabled)
}

func init() {
	strcase.ConfigureAcronym("stb", "STB")
}

func Bootstrap() {
	if !isAllowScope() {
		fmt.Printf("%s You are in not allowed scope, check %s config file\n", aurora.BgMagenta("[WARN]"), aurora.Magenta("default.yaml"))
		return
	}

	dbase := db.New()
	repos := repository.New(dbase)
	services := service.New(repos)
	handlers := handler.New(services)

	switch viper.GetString("role") {
	case constant.RoleConsole:
		fmt.Printf("init console console: %s\n", handlers.InitConsole())
	case constant.RoleWeb:
		fmt.Printf("who: %s\n", handlers.InitRoutes())
		///http.Run()
	}
}