package com.tzld.piaoquan.recommend.server.grpcservice;

import com.tzld.piaoquan.recommend.feature.client.ProtobufUtils;
import com.tzld.piaoquan.recommend.server.gen.model.ModelServiceGrpc;
import com.tzld.piaoquan.recommend.server.gen.model.ScoreRequest;
import com.tzld.piaoquan.recommend.server.gen.model.ScoreResponse;
import com.tzld.piaoquan.recommend.server.service.ModelService;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author dyp
 */
@GrpcService
@Slf4j
public class ModelGrpcService extends ModelServiceGrpc.ModelServiceImplBase {
    @Autowired
    private ModelService modelService;

    @Override
    public void score(ScoreRequest request, StreamObserver<ScoreResponse> responseObserver) {
        log.info("ModelGrpcService score request={}", ProtobufUtils.toJson(request));
        ScoreResponse response = modelService.score(request);
        log.info("ModelGrpcService score response={}", ProtobufUtils.toJson(response));

        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }

}
