package main

import (
	"log"
	"net"

	"scrum-solitare/src/config"
	"scrum-solitare/src/handlers"
	"scrum-solitare/src/server"
	"scrum-solitare/src/state"
)

func main() {
	cfg := config.Load()

	manager, err := state.NewManager(cfg.DataPath, state.ManagerOptions{
		MaxActivityLogEntries:   cfg.MaxActivityLogEntries,
		AdminLogBroadcastLimit:  cfg.AdminLogBroadcastLimit,
		StaleRoomCleanupInterval: cfg.StaleRoomCleanupInterval,
		StaleRoomTTL:             cfg.StaleRoomTTL,
	})
	if err != nil {
		log.Fatalf("failed to initialize state manager: %v", err)
	}

	pages := handlers.NewPageHandler()
	rooms := handlers.NewRoomAPIHandler(manager)
	router := server.NewRouter(pages, rooms)

	if err := router.Run(net.JoinHostPort(cfg.Host, cfg.Port)); err != nil {
		log.Fatalf("server failed to start: %v", err)
	}
}
