package com.tzld.piaoquan.recommend.model.grpc.client;

import com.tzld.piaoquan.recommend.model.grpc.model.PredictRequest;
import com.tzld.piaoquan.recommend.model.grpc.model.PredictResponse;
import com.tzld.piaoquan.recommend.model.grpc.model.PredictServiceGrpc;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * @author dyp
 */
@Component
@Slf4j
public class PredictClient {
    @GrpcClient("recommend-model")
    private PredictServiceGrpc.PredictServiceBlockingStub client;


    public String predict(String modelName, String param) {
        PredictRequest request = PredictRequest.newBuilder()
                .setModelName("")
                .setParam("")
                .build();
        PredictResponse response = client.predict(request);
        if (response == null || !response.hasResult()) {
            log.info("predict grpc error");
            return null;
        }
        if (response.getResult().getCode() != 1) {
            log.info("predict grpc code={}, msg={}", response.getResult().getCode(),
                    response.getResult().getMessage());
            return null;
        }
        return response.getData();
    }

}
