package cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.paperInvoice.dto.request.SID25TaxDeviceInfo;

import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.xml.AnXMLUtils;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.paperInvoice.dto.request._SzhtxxPaperInvoiceBaseRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.UnsupportedEncodingException;

/**
 * @Description: 17. 金税设备查询 SID=25
 * 查询金税盘设备状态。
 * @Author: linjinyu
 * @CreateDate: 2022/4/27 7:02 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/4/27 7:02 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@SuperBuilder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
public class SID25TaxDeviceInfoRequestBody extends _SzhtxxPaperInvoiceBaseRequest {

    String encMsg = "eyJTSURQYXJhbSI6ICI8P3htbCB2ZXJzaW9uPScxLjAnIGVuY29kaW5nPSdHQksnPz48RlBYVF9DT01fSU5QVVQ_PElEPjA0MDA8L0lEPjxEQVRBPjwvREFUQT48L0ZQWFRfQ09NX0lOUFVUPiJ9";
//    {"SIDParam": "<?xml version='1.0' encoding='GBK'?><FPXT_COM_INPUT><ID>0400</ID><DATA></DATA></FPXT_COM_INPUT>"}

    @ApiModelProperty("明文")
    private SID25TaxDeviceInfoRequestBodyStructVo structVo;

    public SID25TaxDeviceInfoRequestBody packing() {

        try {

            this.SID = "25";

            FpxtComInputStructFactory fpxtComInputStructFactory = new FpxtComInputStructFactory();

            FpxtComInputStruct fpxtComInputStruct = fpxtComInputStructFactory.createFpxtComInputStruct();
            fpxtComInputStruct.setID("0400");

            String _SIDParam = AnXMLUtils.objToXml(fpxtComInputStruct);
//            String _SIDParam = fpxtComInputStructFactory.createFPXTCOMINPUT(fpxtComInputStruct).toString();

            structVo = SID25TaxDeviceInfoRequestBodyStructVo
                    .builder()
                    .sIdParam(_SIDParam)
                    .build();

            this.SIDParam = this.base64EncodeAndReplace(AnJsonUtils.toJson(structVo));
        } catch (UnsupportedEncodingException unsupportedEncodingException) {
            unsupportedEncodingException.printStackTrace();
            this.SIDParam = "ERROR";
        }

        return this;

    }
}
