package grpc

import (
	"context"
	"github.com/pocketbase/pocketbase"
	pb "htwkalender/common/genproto/modules"
	"htwkalender/data-manager/service/db"
)

type RoomServiceHandler struct {
	app *pocketbase.PocketBase
	pb.UnimplementedRoomServiceServer
}

func (s *RoomServiceHandler) GetRoomEvents(ctx context.Context, in *pb.GetRoomRequest) (*pb.GetRoomResponse, error) {

	s.app.Logger().Info(
		"Protobuf - GetRoomEvents",
		"room", in.Room,
	)
	// get events from database by room
	events, err := db.GetRoomSchedule(s.app, in.Room)
	if err != nil {
		return nil, err
	}

	// Implement your logic here to fetch events data based on the room
	// Example response
	return &pb.GetRoomResponse{
		Events: eventsToProto(events),
	}, nil
}
