package grpc

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

type FeedServiceHandler struct {
	app *pocketbase.PocketBase
	pb.UnimplementedFeedServiceServer
}

func (s *FeedServiceHandler) GetFeed(ctx context.Context, in *pb.GetFeedRequest) (*pb.GetFeedResponse, error) {

	s.app.Logger().Info(
		"Protobuf - GetFeed",
		"uuid", in.Id,
	)

	// get feed from database by UUID
	feed, err := db.FindFeedByToken(s.app, in.Id)
	if err != nil {
		return nil, err
	}

	// Implement your logic here to fetch feed data based on the UUID
	// Example response
	return &pb.GetFeedResponse{
		Feed: feedToProto(feed),
	}, nil
}
