package com.sonic.cow.lib.client;

import com.alibaba.fastjson.TypeReference;
import com.sonic.common.AppRuntime;
import com.sonic.common.rpc.Result;
import com.sonic.common.rpc.RpcClient;
import com.sonic.cow.lib.input.NsfwCheckInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author code
 */
@Slf4j
@Service
public class NsfwCheckClient {

    private static final String NSFW_CHECK = "/api/nsfw/check";

    private RpcClient rpcClient;
    private String host;

    public NsfwCheckClient(RpcClient rpcClient, AppRuntime appRuntime) {
        this.rpcClient = rpcClient;
        switch (appRuntime.getEnv()) {
            case dev:
                this.host = "http://dev-cow.svc.cloud";
                break;
            case local:
                this.host = "http://localhost:8080";
                break;
            case test:
                this.host = "http://test-cow-svc:8080";
                break;
            case product:
            default:
                this.host = "http://prod-cow-svc:8080";
        }
    }

    /**
     * 敏感词校验
     * @param content
     */
    public void checkContent(String content) {
        NsfwCheckInput input = NsfwCheckInput.builder()
                .content(content)
                .build();
        rpcClient.postBodySign(host + NSFW_CHECK, input, new TypeReference<Result<Void>>() {});
    }

}
