package cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.electronicInvoice.service;

import cn.hutool.json.JSONUtil;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.electronicInvoice.dto.request.WcCardRequest;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.electronicInvoice.dto.response.WcCardResponse;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.electronicInvoice.restapi.WcCardCallApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import retrofit2.Call;

import java.io.IOException;

/**
 * @Description: 1.1.5_微信卡包接口-
 * @Author: linjinyu
 * @CreateDate: 2021/12/23 下午5:12
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/12/23 下午5:12
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class WcCardCallService extends _SzhtxxElectronicInvoiceAuthService {

    @Autowired
    private WcCardCallApi wcCardCallApi;

    public WcCardResponse callWcCardApi(WcCardRequest request) {

        super.addAuth(request);

        WcCardResponse response = null;

        try {
            Call<WcCardResponse> callResponse = wcCardCallApi.callWcCardApi(request);

            response = callResponse.execute().body();

            log.info("response\n{}", JSONUtil.toJsonStr(response));

        } catch (com.github.lianjiatech.retrofit.spring.boot.exception.RetrofitException retrofitException) {

            retrofitException.printStackTrace();

            return null;

        } catch (IOException ioe) {

            ioe.printStackTrace();

            return null;
        }

        return response;
    }
}
