package main

import (
	"fmt"
	"log"
	"os"

	"git.wntrmute.dev/mc/mcp/internal/agent"
	"git.wntrmute.dev/mc/mcp/internal/config"
	"github.com/spf13/cobra"
)

var (
	version = "dev"
	cfgPath string
)

func main() {
	root := &cobra.Command{
		Use:   "mcp-agent",
		Short: "Metacircular Control Plane agent",
	}
	root.PersistentFlags().StringVarP(&cfgPath, "config", "c", "", "config file path")

	root.AddCommand(&cobra.Command{
		Use:   "version",
		Short: "Print version",
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Println(version)
		},
	})

	root.AddCommand(&cobra.Command{
		Use:   "server",
		Short: "Start the agent server",
		RunE: func(cmd *cobra.Command, args []string) error {
			cfg, err := config.LoadAgentConfig(cfgPath)
			if err != nil {
				return fmt.Errorf("load config: %w", err)
			}
			return agent.Run(cfg)
		},
	})

	root.AddCommand(snapshotCmd())

	if err := root.Execute(); err != nil {
		log.Fatal(err)
		os.Exit(1)
	}
}
