package main

import (
	"bordro-esleme/api"
	"git.makki.io/makki/libgo/dbu"
	"git.makki.io/makki/libgo/mlog"
	"git.makki.io/makki/libgo/svc"
	"git.notitek.com.tr/common/notgo/nauth"
	"time"
)

func main() {
	// init base service
	s := svc.Init("bordro-esleme", "bordroesleme", 40300, 40301)

	// init logger
	mlog.InitLogger(s.DevMode())

	// connnect to db
	dbConnectionString := s.DBConnectionString()
	err := dbu.Connect(s.Ctx, dbConnectionString, s.SqlsDir(), s.DevMode())
	if err != nil {
		mlog.Fatal(err)
	}

	//kv table adını atayalım
	dbu.DB.SetTableNameKV("sykv")

	err = dbu.DB.Ping(s.Ctx)
	if err != nil {
		mlog.Fatal(err)
	}

	//subscribe to auth server
	expire := time.Hour * 1
	if svc.S.DevMode() {
		expire = time.Hour * 48
	}
	err = nauth.SubscribeToAuthServer(s.Ctx, expire)
	if err != nil {
		mlog.Fatal(err)
	}

	// Init appplication service
	s.StartHttp(api.HttpHandler(s.RunEnv()))
}
