package com.gxwebsoft.shop.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;

/**
 * 机构
 *
 * @author LX
 * @since 2025-04-14 00:35:34
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class UnifiedOrderBody implements Serializable {
    //消息ID
    public String msgId;
    //报文请求时间，格式yyyy-MM-ddHH:mm:ss

    public String requestTimestamp;
    //商户订单号
    public String merOrderId;
    //请求系统预留字段
    public String srcReserve;
    //商户号
    public String mid;
    //终端号
    public String tid;
    //业务类型
    public String instMid;
    //商品信息
    public String goods;
    //商户附加数据
    public String attachedData;
    //订单过期时间
    public String expireTime;
    //商品标记
    public String goodsTag;
    //商品交易单号
    public String goodsTradeNo;
    //账单描述
    public String orderDesc;
    //订单原始金额
    public String originalAmount;
    //商品ID
    public String productId;
    //支付总金额
    public String totalAmount;
    //子商户id
    public String subAppId;
    //分账标记
    public String divisionFlag;
    //平台商户分账金额
    public String platformAmount;
    //子订单信息
    public List<UnionSubOrderItem> subOrders;
    //支付结果通知地址
    public String notifyUrl;
    //订单展示页面
    public String showUrl;
    //担保交易标识
    public String secureTransaction;
    //用户子标识
    public String tradeType;
    //交易类型
    public String subOpenId;
    //商户用户号
    public String merchantUserId;
    //用户Id
    public String userId;
    //实名认证手机号
    public String mobile;
    //是否需要限制信用卡支付
    public String limitCreditCard;

    String toJson() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        if (this.userId != null) sb.append("\"userId\":\"" + this.userId + "\",");
        if (this.msgId != null) sb.append("\"msgId\":\"" + this.msgId + "\",");
        if (this.requestTimestamp != null) sb.append("\"requestTimestamp\":\"" + this.requestTimestamp + "\",");
        if (this.merOrderId != null) sb.append("\"merOrderId\":\"" + this.merOrderId + "\",");
        if (this.srcReserve != null) sb.append("\"srcReserve\":\"" + this.srcReserve + "\",");
        if (this.mid != null) sb.append("\"mid\":\"" + this.mid + "\",");
        if (this.tid != null) sb.append("\"tid\":\"" + this.tid + "\",");
        if (this.instMid != null) sb.append("\"instMid\":\"" + this.instMid + "\",");
        if (this.goods != null && !this.goods.isEmpty()) {
//            sb.append("\"goods\":[");
//            for (int i = 0; i < goods.size(); i++) {
//                if (goods.get(i) != null) {
//                    sb.append(goods.get(i));
//                    sb.append(",");
//                }
//            }
//            if (sb.charAt(sb.length() - 1) == ',')
//                sb.deleteCharAt(sb.length() - 1);
//            sb.append("],");
            sb.append("\"goods\":").append(this.goods).append(",");
        }
        if (this.attachedData != null) sb.append("\"attachedData\":\"" + this.attachedData + "\",");
        if (this.expireTime != null) sb.append("\"expireTime\":\"" + this.expireTime + "\",");
        if (this.goodsTag != null) sb.append("\"goodsTag\":\"" + this.goodsTag + "\",");
        if (this.goodsTradeNo != null) sb.append("\"goodsTradeNo\":\"" + this.goodsTradeNo + "\",");
        if (this.orderDesc != null) sb.append("\"orderDesc\":\"" + this.orderDesc + "\",");
        if (this.originalAmount != null) sb.append("\"originalAmount\":\"" + this.originalAmount + "\",");
        if (this.productId != null) sb.append("\"productId\":\"" + this.productId + "\",");
        if (this.totalAmount != null) sb.append("\"totalAmount\":\"" + this.totalAmount + "\",");
        if (this.divisionFlag != null) sb.append("\"divisionFlag\":\"" + this.divisionFlag + "\",");
        if (this.platformAmount != null) sb.append("\"platformAmount\":\"" + this.platformAmount + "\",");
        if (this.subOrders != null && this.subOrders.size() > 0) {
            sb.append("\"subOrders\":[");
            for (int i = 0; i < subOrders.size(); i++) {
                sb.append(subOrders.get(i));
                sb.append(",");
            }
            if (sb.charAt(sb.length() - 1) == ',')
                sb.deleteCharAt(sb.length() - 1);
            sb.append("],");
        }
        if (this.notifyUrl != null) sb.append("\"notifyUrl\":\"" + this.notifyUrl + "\",");
        if (this.showUrl != null) sb.append("\"showUrl\":\"" + this.showUrl + "\",");
        if (this.secureTransaction != null) sb.append("\"secureTransaction\":\"" + this.secureTransaction + "\",");
        if (this.subOpenId != null) sb.append("\"subOpenId\":\"" + this.subOpenId + "\",");
        if (this.tradeType != null) sb.append("\"tradeType\":\"" + this.tradeType + "\",");
        if (this.merchantUserId != null) sb.append("\"merchantUserId\":\"" + this.merchantUserId + "\",");
        if (this.mobile != null) sb.append("\"mobile\":\"" + this.mobile + "\",");
        if (this.limitCreditCard != null) sb.append("\"limitCreditCard\":\"" + this.limitCreditCard + "\",");
        if (this.subAppId != null) sb.append("\"subAppId\":\"" + this.subAppId + "\",");
        if (sb.charAt(sb.length() - 1) == ',')
            sb.deleteCharAt(sb.length() - 1);
        sb.append("}");
        return sb.toString();
    }

    public String toString() {
        return this.toJson();
    }

}
