package grpc

import (
	"github.com/pocketbase/pocketbase"
	"log"
	"net"

	"google.golang.org/grpc"
	pb "htwkalender/common/genproto/modules"
)

func StartGRPCServer(app *pocketbase.PocketBase) {
	lis, err := net.Listen("tcp", ":50051")
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()

	pb.RegisterModuleServiceServer(s, &ModuleServiceHandler{
		app: app,
	})

	pb.RegisterFeedServiceServer(s, &FeedServiceHandler{
		app: app,
	})

	log.Printf("server listening at %v", lis.Addr())
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
