package com.sifang.modules.sys.util.insurance;

import com.google.gson.Gson;
import com.sifang.modules.sys.util.http.InsuranceRestTemplate;
import com.sifang.modules.sys.util.insurance.form.endorse.EndorseCallbackReq;
import com.sifang.modules.sys.util.insurance.form.endorse.EndorseReq;
import com.sifang.modules.sys.util.insurance.form.endorse.EndorseResp;
import com.sifang.modules.sys.util.insurance.form.endorsequery.EndorseQueryReq;
import com.sifang.modules.sys.util.insurance.form.endorsequery.EndorseQueryResp;
import com.sifang.modules.sys.util.insurance.form.insuresubmit.InsureSubmitReq;
import com.sifang.modules.sys.util.insurance.form.insuresubmit.InsureSubmitResp;
import com.sifang.modules.sys.util.insurance.form.orderquery.OrderQueryReq;
import com.sifang.modules.sys.util.insurance.form.orderquery.OrderQueryResp;
import com.sifang.modules.sys.util.insurance.form.ordersubmit.*;
import com.sifang.modules.sys.util.insurance.form.upload.FileUploadReq;
import com.sifang.modules.sys.util.insurance.form.upload.FileUploadResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Service;

@Service
public class InsuranceApiService {

    @Autowired
    InsuranceRestTemplate restTemplate;

    private static final Logger log = LoggerFactory.getLogger(InsuranceApiService.class);

//    private static final String base = "https://pre-hbhp-aaa.hzins.com/api/external/pv/";
    // 生产
    private static final String base = "https://aaa.huibaohuipeifw.com/api/external/pv/";

    private static final String baseUrl = "https://pre-hbhp-aaa.hzins.com/api/external/projectInsure";
    /**
     *
     *安工险投保接口
     */

    public IRet<InsureSubmitResp> insureSubmit(InsureSubmitReq req) {
        IRet<InsureSubmitResp> ret = restTemplate.postJson(baseUrl + "/submit", req, new ParameterizedTypeReference<IRet<InsureSubmitResp>>() {
        });
        return ret;
    }

    /**
     * 提交核保接口
     */
    public IRet<OrderSubmitResp> orderSubmit(OrderSubmitReq req) {
        log.info("order submit req: {}", new Gson().toJson(req));
        IRet<OrderSubmitResp> ret = restTemplate.postJson(base + "order/submit", req, new ParameterizedTypeReference<IRet<OrderSubmitResp>>() {
        });
        log.info("order submit ret: {}", new Gson().toJson(ret));
        return ret;
    }

    /**
     * 退保接口
     */
    public IRet<Void> orderCancel(OrderCancelReq req) {
        log.info("order cancel req: {}", new Gson().toJson(req));
        IRet<Void> ret = restTemplate.postJson(base + "order/cancel", req, new ParameterizedTypeReference<IRet<Void>>() {
        });
        log.info("order cancel ret: {}", new Gson().toJson(ret));
        return ret;
    }

    /**
     * 核保文件上传接口
     */
    public IRet<FileUploadResp> fileUpload(FileUploadReq req) {
        log.info("file upload req: {}", new Gson().toJson(req));
        IRet<FileUploadResp> ret = restTemplate.postJson(base + "file/uploadFile", req, new ParameterizedTypeReference<IRet<FileUploadResp>>() {
        });
        log.info("file upload ret: {}", new Gson().toJson(ret));
        return ret;
    }

    public void handleOrderCallback(OrderCallbackReq req) {
    }

    /**
     * 保单查询接口
     */
    public IRet<OrderQueryResp> orderQuery(OrderQueryReq req) {
        log.info("order query req: {}", new Gson().toJson(req));
        IRet<OrderQueryResp> ret = restTemplate.postJson(base + "order/page", req, new ParameterizedTypeReference<IRet<OrderQueryResp>>() {
        });
        log.info("order query ret: {}", new Gson().toJson(ret));
        return ret;
    }

    /**
     * 批改接口
     */
    public IRet<EndorseResp> endorse(EndorseReq req) {
        log.info("endorse req: {}", new Gson().toJson(req));
        IRet<EndorseResp> ret = restTemplate.postJson(base + "endorse/submit", req, new ParameterizedTypeReference<IRet<EndorseResp>>() {
        });
        log.info("endorse ret: {}", new Gson().toJson(ret));
        return ret;
    }


    public void handleEndorseCallback(EndorseCallbackReq req) {
    }


    /**
     * 批改查询接口
     */
    public IRet<EndorseQueryResp> endorseQuery(EndorseQueryReq req) {
        log.info("endorse query req: {}", new Gson().toJson(req));
        IRet<EndorseQueryResp> ret = restTemplate.postJson(base + "endorse/page", req, new ParameterizedTypeReference<IRet<EndorseQueryResp>>() {
        });
        log.info("endorse query ret: {}", new Gson().toJson(ret));
        return ret;
    }

}
