package logic

import (
	"context"

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

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

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

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

func (l *GetReviewsByIdLogic) GetReviewsById(in *pb.GetReviewsByIdReq) (*pb.GetReviewsByIdResp, error) {
	r, err := l.svcCtx.ReviewModelRO.Reviews.Get(l.ctx, in.GetId())
	if err != nil {
		return nil, err
	}
	return &pb.GetReviewsByIdResp{Reviews: entReviewToPb(r)}, nil
}
