package com.jkcredit.invoice.service.upService.impl;

import cn.com.taiji.common.manager.net.http.binclient.ApiRequestException;
import cn.com.taiji.sdk.comm.ETCCommHelper;
import cn.com.taiji.sdk.model.comm.protocol.eoms.company.*;
import cn.com.taiji.sdk.model.comm.protocol.tts.card.server.*;
import cn.com.taiji.sdk.model.comm.protocol.tts.invoice.server.*;
import cn.com.taiji.sdk.model.comm.protocol.tts.trade.service.CardTradeRequest;
import cn.com.taiji.sdk.model.comm.protocol.tts.trade.service.CardTradeResponse;
import com.jkcredit.invoice.service.upService.SelfCarInterface;
import com.jkcredit.invoice.util.RespR;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Slf4j
@Service("selfCarInterface")
public class SelfCarInterfaceImpl  implements SelfCarInterface{
    @Override
    public RespR<CardBindQueryListToBResponse> cardBindQueryListToB(CardBindQueryListToBRequest cardBindQueryListToBRequest) {
        String fileName = cardBindQueryListToBRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            CardBindQueryListToBResponse response=ETCCommHelper.upload(fileName, cardBindQueryListToBRequest, CardBindQueryListToBResponse.class);
            log.info("SelfCarInterfaceImpl.cardBindQueryListToB上游接口返回：{},请求参数：{}", response.toString(), cardBindQueryListToBRequest.toString());

            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<CardQueryCardToBResponse> cardQueryCardToB(CardQueryCardToBRequest cardQueryCardToBRequest) {
        String fileName = cardQueryCardToBRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            CardQueryCardToBResponse response=ETCCommHelper.upload(fileName, cardQueryCardToBRequest, CardQueryCardToBResponse.class);
            log.info("SelfCarInterfaceImpl.cardQueryCardToB上游接口返回：{},请求参数：{}", response.toString(), cardQueryCardToBRequest.toString());

            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<CardBindingToBResponse> cardBindingToB(CardBindingToBRequest cardBindingToBRequest) {
        String fileName = cardBindingToBRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            CardBindingToBResponse response=ETCCommHelper.upload(fileName, cardBindingToBRequest, CardBindingToBResponse.class);
            log.info("SelfCarInterfaceImpl.cardBindingToB上游接口返回：{},请求参数：{}", response.toString(), cardBindingToBRequest.toString());


            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<CardValidCodeToBResponse> cardValidCodeToB(CardValidCodeToBRequest cardValidCodeToBRequest) {
        String fileName = cardValidCodeToBRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            CardValidCodeToBResponse response=ETCCommHelper.upload(fileName, cardValidCodeToBRequest, CardValidCodeToBResponse.class);
            log.info("SelfCarInterfaceImpl.cardValidCodeToB上游接口返回：{},请求参数：{}", response.toString(), cardValidCodeToBRequest.toString());


            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<CardUnbindToBResponse> cardUnbindToB(CardUnbindToBRequest cardUnbindToBRequest) {
        String fileName = cardUnbindToBRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            CardUnbindToBResponse response=ETCCommHelper.upload(fileName, cardUnbindToBRequest, CardUnbindToBResponse.class);
            log.info("SelfCarInterfaceImpl.cardUnbindToB上游接口返回：{},请求参数：{}", response.toString(), cardUnbindToBRequest.toString());


            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<CardTradeResponse> cardTrade(CardTradeRequest cardTradeRequest) {
        String fileName = cardTradeRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            CardTradeResponse response=ETCCommHelper.upload(fileName, cardTradeRequest, CardTradeResponse.class);
            log.info("SelfCarInterfaceImpl.cardTrade上游接口返回：{},请求参数：{}", response.toString(), cardTradeRequest.toString());


            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<B2BInvoiceApplyResponse> b2BInvoiceApply(B2BInvoiceApplyRequest b2BInvoiceApplyRequest) {
        String fileName = b2BInvoiceApplyRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            B2BInvoiceApplyResponse response=ETCCommHelper.upload(fileName, b2BInvoiceApplyRequest, B2BInvoiceApplyResponse.class);
            log.info("SelfCarInterfaceImpl.b2BInvoiceApply上游接口返回：{},请求参数：{}", response.toString(), b2BInvoiceApplyRequest.toString());


            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<B2BInvoiceQueryResponse> b2BInvoiceQuery(B2BInvoiceQueryRequest b2BInvoiceQueryRequest) {
        String fileName = b2BInvoiceQueryRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            B2BInvoiceQueryResponse response=ETCCommHelper.upload(fileName, b2BInvoiceQueryRequest, B2BInvoiceQueryResponse.class);
            log.info("SelfCarInterfaceImpl.b2BInvoiceQuery上游接口返回：{},请求参数：{}", response.toString(), b2BInvoiceQueryRequest.toString());


            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<B2BInvoiceQueryByApplyResponse> b2bContractQuery(B2BInvoiceQueryByApplyRequest b2BInvoiceQueryByApplyRequest) {
        String fileName = b2BInvoiceQueryByApplyRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            B2BInvoiceQueryByApplyResponse response=ETCCommHelper.upload(fileName, b2BInvoiceQueryByApplyRequest, B2BInvoiceQueryByApplyResponse.class);
            log.info("SelfCarInterfaceImpl.b2bContractQuery上游接口返回：{},请求参数：{}", response.toString(), b2BInvoiceQueryByApplyRequest.toString());

            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }

    @Override
    public RespR<B2bInvoicePackageResponse> b2bInvoicePackage(B2bInvoicePackageRequest b2bInvoicePackageRequest) {
        String fileName = b2bInvoicePackageRequest.getFilename();
        try {
            //(4)指定协议的响应模型（IssuerUploadResponse），调用upload 发送数据
            B2bInvoicePackageResponse response=ETCCommHelper.upload(fileName, b2bInvoicePackageRequest, B2bInvoicePackageResponse.class);
            log.info("SelfCarInterfaceImpl.b2bInvoicePackage上游接口返回：{},请求参数：{}", response.toString(), b2bInvoicePackageRequest.toString());

            return new RespR<>(response);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespR(false,"网络异常,请联系管理人员");
        }catch (ApiRequestException apie) {
            apie.printStackTrace();
            return new RespR(false,"错误码："+apie.getErrCode()+" 错误信息："+apie.getMessage());
        }
    }
}
