package main

import (
	"context"
	"fmt"
	"gitea.pena/PenaSide/heruvym/internal/app"
	"gitea.pena/PenaSide/heruvym/internal/initialize"
	_ "gitea.pena/PenaSide/linters-golang/pkg/dummy"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"
)

var (
	commit    string = os.Getenv("COMMIT")
	buildTime string = os.Getenv("BUILD_TIME")
	version   string = os.Getenv("VERSION")
)

// $env:COMMIT=$(git rev-parse --short HEAD); $env:BUILD_TIME=$(Get-Date -UFormat "%Y-%m-%dT%H:%M:%SZ"); $env:VERSION=$(git describe --tags); go run cmd/main.go

func main() {

	ptime, err := time.Parse(time.RFC3339, buildTime)
	if err != nil {
		fmt.Println("Error parsing build time:")
		ptime = time.Now()
	}

	config, err := initialize.LoadConfig()
	if err != nil {
		log.Fatal("Failed loaded config:", err)
	}

	ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
	defer stop()

	if err = app.Run(ctx, *config, app.Build{
		Commit:    commit,
		Version:   version,
		BuildTime: ptime.Unix(),
	}); err != nil {
		log.Fatal("App exited with error:", err.Error())
	}
}
