package main

import (
	"log"
	"os"

	"igit.com/xbase/raft"
	"igit.com/xbase/raft/example/basic/common"
)

func main() {
	// Configuration
	nodeID := "node4"
	addr := "127.0.0.1:9004"
	dataDir := "../data/node4"

	// Standalone configuration
	clusterNodes := map[string]string{
		"node4": "127.0.0.1:9004",
	}

	config := raft.DefaultConfig()
	config.NodeID = nodeID
	config.ListenAddr = addr
	config.DataDir = dataDir
	config.ClusterNodes = clusterNodes
	config.LogCompactionEnabled = false
	
	config.Logger = raft.NewConsoleLogger(nodeID, 1)

	if err := os.MkdirAll(dataDir, 0755); err != nil {
		log.Fatalf("Failed to create data directory: %v", err)
	}

	server, err := raft.NewKVServer(config)
	if err != nil {
		log.Fatalf("Failed to create server: %v", err)
	}

	// Register demo commands
	common.RegisterDemoCommands(server.CLI)

	if err := server.Start(); err != nil {
		log.Fatalf("Failed to start server: %v", err)
	}
	defer server.Stop()

	// Keep main thread running
	select {}
}

