package main

import (
	"log/slog"

	"go.dev.pztrn.name/featurer/server/internal/application"
	"go.dev.pztrn.name/featurer/server/internal/services/core/datastore"
	"go.dev.pztrn.name/featurer/server/internal/services/core/http"
)

func main() {
	_ = slog.SetLogLoggerLevel(slog.LevelDebug)

	app := application.New()

	slog.Info(
		"Launching Featurer server...",
		"version", application.Version,
		"build", application.Build,
		"branch", application.Branch,
		"commit", application.Commit,
		"build date", application.BuildDate,
	)

	// Initializing core services first.
	checkError(datastore.Initialize(app))
	checkError(http.Initialize(app))

	// Then - features services.

	// Start application.
	checkError(app.Start())

	<-app.GetShutdownDoneChannel()
	slog.Info("Featurer stopped.")
}

func checkError(err error) {
	if err == nil {
		return
	}

	panic(err)
}
