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

import cn.hutool.core.util.ObjectUtil;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
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/4/25 12:57 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/4/25 12:57 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@SuperBuilder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
public class SID1SingleBillingRequestBody extends _SzhtxxPaperInvoiceBaseRequest {

    @ApiModelProperty("明文")
    private SID1SingleBillingRequestBodyKpContentFptxxVo fptxx;

    public SID1SingleBillingRequestBody packing() {

        try {
            // 公用类 需要对专票红冲单独处理, 不含税的
            if(0==fptxx.getInvoiceType() &&  -1 == Double.valueOf(fptxx.getKphjje()).compareTo(0.00)){
                SID1SingleBillingRequestBodyKpContentFptxxVo fptxxVo =  new SID1SingleBillingRequestBodyKpContentFptxxVo();
                fptxxVo = ObjectUtil.clone(fptxx);
                fptxxVo.setInvoiceItems(fptxxVo.getInvoiceItems2());
                fptxxVo.setInvoiceItems2(null);
                this.SIDParam = this.base64EncodeAndReplace(AnJsonUtils.toJson(fptxxVo));
            }else{
                this.SIDParam = this.base64EncodeAndReplace(AnJsonUtils.toJson(fptxx));
            }

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

        return this;

    }
}
