package main

import (
	"flag"
	"fmt"
	"log"
	"os"

	"github.com/duffy/usb-server/internal/relay"
)

func main() {
	port := flag.Int("port", 8443, "listen port")
	addr := flag.String("addr", "0.0.0.0", "listen address")
	flag.Parse()

	// Also check environment variables (for Docker)
	if envPort := os.Getenv("RELAY_PORT"); envPort != "" {
		fmt.Sscanf(envPort, "%d", port)
	}
	if envAddr := os.Getenv("RELAY_ADDR"); envAddr != "" {
		*addr = envAddr
	}

	listenAddr := fmt.Sprintf("%s:%d", *addr, *port)

	log.SetFlags(log.LstdFlags | log.Lshortfile)
	log.Printf("USB Relay Server starting on %s", listenAddr)

	server := relay.NewServer(listenAddr)
	if err := server.Run(); err != nil {
		log.Fatalf("server error: %v", err)
	}
}
