package cn.sh.stc.sict.theme.hphy.controller.mp;

import cn.hutool.json.JSONUtil;
import cn.sh.stc.sict.cloud.common.core.util.R;
import cn.sh.stc.sict.theme.hphy.service.HphyAiCallService;
import cn.sh.stc.sict.theme.hphy.vo.JhCallbackDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.EncodeException;
import java.io.IOException;

/**
 * @author zhangly
 * @Description
 * @Date 2020/10/9 16:02
 **/
@Slf4j
@Api(value = "[D]AI 语音呼叫接口", tags = "[D]AI 语音呼叫接口")
@RequestMapping("/hphy/c/ai")
@RestController
public class HphyAiCallController {

    @Autowired
    private HphyAiCallService hphyAiCallService;

    @ApiOperation("AI 语音呼叫接口")
    @PostMapping("/call")
    public R<?> postAiCall(@RequestParam("userId") Long userId, @RequestParam("phone") String phone){
        return hphyAiCallService.postAiCall(userId, phone);
    }

    @ApiOperation("AI 语音呼叫接口")
    @PostMapping("/api/callback")
    public R<?> callback(@RequestBody JhCallbackDTO callback) throws IOException, EncodeException {
        log.error("语音回调参数 ===================> {}", JSONUtil.toJsonStr(callback));

        return hphyAiCallService.callback(callback);
    }

    @ApiOperation("test")
    @GetMapping("/test")
    public R<?> test(@RequestParam("ip")String ip){
//        IpAddressSearchWebService ipAddressSearchWebService = new IpAddressSearchWebService();
//
//        IpAddressSearchWebServiceSoap soap = ipAddressSearchWebService.getIpAddressSearchWebServiceSoap();
//
//        // "58.246.13.178"
//        ArrayOfString result = soap.getCountryCityByIp(ip);
//
//        System.out.println(result);


        return new R<>();
    }
}
