package grpcrun

import (
	"fmt"
	"net"

	"mengyamonitor-backend-server/internal/gen/mengyav1"
	"mengyamonitor-backend-server/internal/ingest"

	"google.golang.org/grpc"
)

// Serve starts a blocking gRPC server for agent ingest.
func Serve(listenAddr string, srv *ingest.Server) error {
	lis, err := net.Listen("tcp", listenAddr)
	if err != nil {
		return fmt.Errorf("listen: %w", err)
	}
	g := grpc.NewServer()
	mengyav1.RegisterAgentIngestServer(g, srv)
	return g.Serve(lis)
}
