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

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 net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author dyp
 */
@Component
//@Slf4j
public class ModelClient {
    @GrpcClient("recommend-server")
    private ModelServiceGrpc.ModelServiceBlockingStub client;

    public Map<String, Double> getScore(long videoId, String mid, String uid, String city, String province) {
        ScoreRequest request = ScoreRequest.newBuilder()
                .setVideoId(videoId)
                .setMid(mid)
                .setUid(uid)
                .setCity(city)
                .setProvince(province)
                .build();
        ScoreResponse response = client.score(request);
        if (response == null || !response.hasResult()) {
            return null;
        }
        if (response.getResult().getCode() != 1) {
            return null;
        }
        return response.getScoreMap();
    }
}
