package main

import (
	"fmt"
	"os"
)

func main() {
	if len(os.Args) < 2 {
		printUsage()
		os.Exit(1)
	}
	switch os.Args[1] {
	case "play":
		PlayVsComputer()
	case "connect":
		if len(os.Args) < 3 {
			fmt.Println("Usage: chess connect <host:port>")
			os.Exit(1)
		}
		PlayMultiplayer(os.Args[2])
	case "server":
		addr := ":8080"
		if len(os.Args) >= 3 {
			addr = os.Args[2]
		}
		srv := NewServer()
		if err := srv.Start(addr); err != nil {
			fmt.Printf("Error: %v\n", err)
			os.Exit(1)
		}
	case "help", "--help", "-h":
		printUsage()
	default:
		fmt.Printf("Unknown command: %s\n\n", os.Args[1])
		printUsage()
		os.Exit(1)
	}
}

func printUsage() {
	fmt.Println(`
  CHESS - Go CLI Chess
  =====================
  chess play              Play against the computer
  chess server [addr]     Start multiplayer server (default :8080)
  chess connect <addr>    Connect and play vs another person
  chess help              Show this help
`)
}

