package main

import (
	"context"
	"log/slog"
	"os"

	"github.com/hexahost/gamecloud/node-agent/internal/agent"
	"github.com/hexahost/gamecloud/node-agent/internal/config"
)

func main() {
	log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
		Level: slog.LevelInfo,
	}))

	cfg, err := config.Load()
	if err != nil {
		log.Error("configuration error", "error", err)
		os.Exit(1)
	}

	log = log.With("node_id", cfg.NodeID, "component", "node-agent")

	a, err := agent.New(cfg, log)
	if err != nil {
		log.Error("agent init error", "error", err)
		os.Exit(1)
	}

	if err := a.Run(context.Background()); err != nil {
		log.Error("agent exited with error", "error", err)
		os.Exit(1)
	}
}
