// Command control-plane is the SDP brain. It owns the metadata DB, the
// WebSocket hub, and the HTTP API. Agents and the dashboard talk to it;
// it never SSHes, never builds, never touches git directly.
package main

import (
	"log"
	"net/http"

	"github.com/sdp/control-plane/internal/api"
	"github.com/sdp/control-plane/internal/config"
	"github.com/sdp/control-plane/internal/store"
	"github.com/sdp/control-plane/internal/ws"
)

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

	st, err := store.Open(cfg.DataDir)
	if err != nil {
		log.Fatalf("store: %v", err)
	}
	defer st.Close()

	hub := ws.New()
	srv := api.New(st, hub)

	log.Printf("control-plane listening on %s (data=%s)", cfg.Addr, cfg.DataDir)
	log.Fatal(http.ListenAndServe(cfg.Addr, srv.Routes()))
}
