package com.jianshui.income.service.impl.adapter.response;

import com.alibaba.fastjson.JSONObject;
import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.common.core.domain.entity.Companyservice;
import com.jianshui.common.enums.ErrorCode;
import com.jianshui.common.exception.jianshui.JianshuiParamErrorException;
import com.jianshui.common.utils.StringUtils;
import com.jianshui.common.utils.encrypt.AisinoInvoiceDecryptUtil;
import com.jianshui.common.utils.http.HttpHelper;
import com.jianshui.income.service.IIncomeRequestService;
import com.jianshui.income.service.IIncomeResponseService;
import com.jianshui.system.service.ICompanyserviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;

/**
 * @Description
 * @Author 巩权林
 * @Date 2022-03-25 10:03
 **/
@Slf4j
@Component("jn_aisino_income_response_adapter")
public class AisinoIncomeResponseAdapterImpl implements IIncomeResponseService {

    @Autowired
    private ICompanyserviceService companyserviceService;

    @Override
    public Object response(AjaxResult result, Companyservice companyservice, String src) {
        // TODO 这里要利用反射拆分成函数，而不是再用equals

        AjaxResult resp = result;

        if (StringUtils.equals(src, "check_single")) {
            if (result.isSuccess()) {
                JSONObject content = (JSONObject) result.get("data");
                if (content != null) {
                    resp = AjaxResult.success(content.getJSONObject("resultContent"));
                }
            }
        }
        if (StringUtils.equals(src, "check_multil")) {

        }

        if (StringUtils.equals(src, "check_multilreqult")) {
            if (result.isSuccess()) {
                JSONObject data = (JSONObject) result.get("data");
                resp = AjaxResult.success(data.getJSONObject("data"));
            }
        }

        // 全票面采集
        if (StringUtils.equals(src, "get_invoice")) {

        }


        return resp;
    }

    @Override
    public Object response(JianshuiParamErrorException result, Companyservice companyservice) {
        JSONObject myResult = new JSONObject();
        myResult.put("status", result.getErrorCode());
        myResult.put("message", result.getMsg());
        return myResult;
    }


}
