package main

import (
	"log"
	"os"

	baseCnf "git.pbiernat.dev/egommerce/identity-service/pkg/config"

	cnf "git.pbiernat.dev/egommerce/identity-service/internal/config"
	svr "git.pbiernat.dev/egommerce/identity-service/internal/server"
)

func main() {
	if baseCnf.ErrLoadingEnvs != nil {
		log.Panicln("Error loading .env file", baseCnf.ErrLoadingEnvs)
	}

	c := cnf.NewConfig("identity-server")
	srv := svr.New(
		c,
		svr.WithCache(c),
		svr.WithDatabase(c),
		svr.WithLogger(c),
		svr.WithRegistry(c),
	)

	while := make(chan struct{})
	err := srv.Base.Start(while, srv.Shutdown())
	<-while

	if err != nil {
		log.Fatalf("Failed to start server. Reason: %v\n", err)
		os.Exit(1)
	}

	os.Exit(0)
}
