package com.sonic.cow.lib.client;

import com.alibaba.fastjson.TypeReference;
import com.google.common.collect.Maps;
import com.sonic.common.AppRuntime;
import com.sonic.common.rpc.Result;
import com.sonic.common.rpc.RpcClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

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

    private static final String CHECK_IMAGE_IS_AI_GENERATED = "/api/checkImageIsAIGenerated";

    private RpcClient rpcClient;
    private String host;

    public ImageClient(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";
        }
    }

    /**
     * 添加相册图片，背景图片，ai形象图时，检查图片是否是AI生成的
     *
     * @param userId
     * @param imgUrlList
     * @return
     */
    public Void checkImageIsAIGenerated(Long userId, List<String> imgUrlList) {
        Map<Object, Object> params = Maps.newHashMap();
        params.put("userId", userId);
        params.put("imgUrlList", imgUrlList);
        return rpcClient.postBodySign(host + CHECK_IMAGE_IS_AI_GENERATED, params, new TypeReference<Result<Void>>() {
        });
    }

}
