package logic

import (
	"context"

	"juwan-backend/app/search/rpc/internal/svc"
	"juwan-backend/app/search/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetFavoritesByIdLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetFavoritesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFavoritesByIdLogic {
	return &GetFavoritesByIdLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetFavoritesByIdLogic) GetFavoritesById(in *pb.GetFavoritesByIdReq) (*pb.GetFavoritesByIdResp, error) {
	f, err := l.svcCtx.SearchModelRO.Favorites.Get(l.ctx, in.GetId())
	if err != nil {
		return nil, err
	}

	return &pb.GetFavoritesByIdResp{Favorites: entFavoriteToPb(f)}, nil
}
