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

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: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2022/5/23 6:34 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/5/23 6:34 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@SuperBuilder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
public class SID20BitchLlqRequestBody extends _SzhtxxPaperInvoiceBaseRequest {

    @ApiModelProperty("ID0200 红字专用发票信息表上传_0200")
    private cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.paperInvoice.dto.request.SID20BitchLlq.ID0200.FpxtType fpxtTypeID0200;
    @ApiModelProperty("ID0201 红字专用发票信息表下载_0201")
    private cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.paperInvoice.dto.request.SID20BitchLlq.ID0201.FpxtType fpxtTypeID0201;

    @ApiModelProperty("FPXT_COM_INPUT->DATA(base64(XML 结构体))")
    private FpxtComInputStruct fpxtComInputStruct;

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


    public SID20BitchLlqRequestBody dataID0200() {

        try {
            FpxtComInputStructFactory fpxtComInputStructFactory = new FpxtComInputStructFactory();
            this.fpxtComInputStruct = fpxtComInputStructFactory.createFpxtComInputStruct();

            fpxtComInputStruct.setID("0200");
            fpxtComInputStruct.setDATA(this.base64Encode(AnXMLUtils.objToXml(fpxtTypeID0200)));

        } catch (UnsupportedEncodingException unsupportedEncodingException) {
            unsupportedEncodingException.printStackTrace();
            this.SIDParam = "ERROR-dataID0200";
        }

        return this;

    }

    public SID20BitchLlqRequestBody dataID0201() {

        try {
            FpxtComInputStructFactory fpxtComInputStructFactory = new FpxtComInputStructFactory();
            this.fpxtComInputStruct = fpxtComInputStructFactory.createFpxtComInputStruct();

            fpxtComInputStruct.setID("0201");
            fpxtComInputStruct.setDATA(this.base64Encode(AnXMLUtils.objToXml(fpxtTypeID0201)));

        } catch (UnsupportedEncodingException unsupportedEncodingException) {
            unsupportedEncodingException.printStackTrace();
            this.SIDParam = "ERROR-dataID0201";
        }

        return this;

    }

    public SID20BitchLlqRequestBody shell() {

        try {
            this.structVo = SID20BitchLlqRequestBodyStructVo
                    .builder()
                    .param(AnXMLUtils.objToXml(this.fpxtComInputStruct))
                    .build();

        } catch (Exception exception) {
            exception.printStackTrace();
            this.SIDParam = "ERROR-shell";
        }

        return this;

    }

    public SID20BitchLlqRequestBody packing() {

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

        return this;

    }
}
