//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//
// The supplied json has fields with names that are not valid in apex
// and so can only be parsed with explicitly generated code, this option
// was auto selected for you.

public class QBSalesReceiptQueryJSON {
  public class TaxLineDetail_Z {
    public TaxCodeRef TaxRateRef { get; set; }
    public Boolean PercentBased { get; set; }
    public Double TaxPercent { get; set; }
    public Double NetAmountTaxable { get; set; }

    public TaxLineDetail_Z(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'TaxRateRef') {
              TaxRateRef = new TaxCodeRef(parser);
            } else if (text == 'PercentBased') {
              PercentBased = parser.getBooleanValue();
            } else if (text == 'TaxPercent') {
              TaxPercent = parser.getDoubleValue();
            } else if (text == 'NetAmountTaxable') {
              NetAmountTaxable = parser.getDoubleValue();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'TaxLineDetail_Z consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class CreditChargeResponse {
    public String CCTransId { get; set; }
    public String Status { get; set; }
    public String CardSecurityCodeMatch { get; set; }
    public String AuthCode { get; set; }
    public String AvsStreet { get; set; }
    public String AvsZip { get; set; }
    public String TxnAuthorizationTime { get; set; }

    public CreditChargeResponse(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'CCTransId') {
              CCTransId = parser.getText();
            } else if (text == 'Status') {
              Status = parser.getText();
            } else if (text == 'CardSecurityCodeMatch') {
              CardSecurityCodeMatch = parser.getText();
            } else if (text == 'AuthCode') {
              AuthCode = parser.getText();
            } else if (text == 'AvsStreet') {
              AvsStreet = parser.getText();
            } else if (text == 'AvsZip') {
              AvsZip = parser.getText();
            } else if (text == 'TxnAuthorizationTime') {
              TxnAuthorizationTime = parser.getText();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'CreditChargeResponse consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class SalesItemLineDetail {
    public DepartmentRef ItemRef { get; set; }
    public Integer UnitPrice { get; set; }
    public Integer Qty { get; set; }
    public TaxCodeRef TaxCodeRef { get; set; }
    public DepartmentRef ClassRef { get; set; }
    public SalesItemLineDetail(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'ItemRef') {
              ItemRef = new DepartmentRef(parser);
            } else if (text == 'UnitPrice') {
              UnitPrice = parser.getIntegerValue();
            } else if (text == 'Qty') {
              Qty = parser.getIntegerValue();
            } else if (text == 'TaxCodeRef') {
              TaxCodeRef = new TaxCodeRef(parser);
            } else if (text == 'ClassRef') {
              ClassRef = new DepartmentRef(parser);
            } else {
              System.debug(
                LoggingLevel.WARN,
                'SalesItemLineDetail consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class DepartmentRef {
    public String value { get; set; }
    public String name { get; set; }

    public DepartmentRef(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'value') {
              value = parser.getText();
            } else if (text == 'name') {
              name = parser.getText();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'DepartmentRef consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class DeliveryInfo {
    public String DeliveryType { get; set; }
    public String DeliveryTime { get; set; }

    public DeliveryInfo(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'DeliveryType') {
              DeliveryType = parser.getText();
            } else if (text == 'DeliveryTime') {
              DeliveryTime = parser.getText();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'DeliveryInfo consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class TaxLine {
    public Double Amount { get; set; }
    public String DetailType { get; set; }
    public TaxLineDetail TaxLineDetail { get; set; }

    public TaxLine(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'Amount') {
              Amount = parser.getDoubleValue();
            } else if (text == 'DetailType') {
              DetailType = parser.getText();
            } else if (text == 'TaxLineDetail') {
              TaxLineDetail = new TaxLineDetail(parser);
            } else {
              System.debug(
                LoggingLevel.WARN,
                'TaxLine consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class Line {
    public String Id { get; set; }
    public Integer LineNum { get; set; }
    public Double Amount { get; set; }
    public String DetailType { get; set; }
    public SalesItemLineDetail SalesItemLineDetail { get; set; }
    public GroupLineDetail GroupLineDetail { get; set; }
    public CustomField SubTotalLineDetail { get; set; }
    public String Description { get; set; }

    public Line(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'Id') {
              Id = parser.getText();
            } else if (text == 'LineNum') {
              LineNum = parser.getIntegerValue();
            } else if (text == 'Amount') {
              Amount = parser.getDoubleValue();
            } else if (text == 'DetailType') {
              DetailType = parser.getText();
            } else if (text == 'Description') {
              Description = parser.getText();
            } else if (text == 'SalesItemLineDetail') {
              SalesItemLineDetail = new SalesItemLineDetail(parser);
            } else if (text == 'GroupLineDetail') {
              GroupLineDetail = new GroupLineDetail(parser);
            } else if (text == 'SubTotalLineDetail') {
              SubTotalLineDetail = new CustomField(parser);
            } else {
              System.debug(
                LoggingLevel.WARN,
                'Line consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class GroupLineDetail {
    public GroupItemRef GroupItemRef { get; set; }
    public Decimal Quantity { get; set; }
    public Decimal Amount { get; set; }
    public List<Line> Line { get; set; }

    public GroupLineDetail(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'GroupItemRef') {
              GroupItemRef = new GroupItemRef(parser);
            } else if (text == 'Quantity') {
              Quantity = parser.getDecimalValue();
            } else if (text == 'Amount') {
              Amount = parser.getDecimalValue();
            } else if (text == 'Line') {
              Line = arrayOfLine(parser);
            } else {
              System.debug(
                LoggingLevel.WARN,
                'SalesItemLineDetail_Z consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class GroupItemRef {
    public String name { get; set; }
    public String value { get; set; }

    public GroupItemRef(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'value') {
              value = parser.getText();
            } else if (text == 'name') {
              name = parser.getText();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'TaxCodeRef consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class CreditCardPayment {
    public CreditChargeInfo CreditChargeInfo { get; set; }
    public CreditChargeResponse CreditChargeResponse { get; set; }

    public CreditCardPayment(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'CreditChargeInfo') {
              CreditChargeInfo = new CreditChargeInfo(parser);
            } else if (text == 'CreditChargeResponse') {
              CreditChargeResponse = new CreditChargeResponse(parser);
            } else {
              System.debug(
                LoggingLevel.WARN,
                'CreditCardPayment consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class SalesReceipt {
    public String domain { get; set; }
    public Boolean sparse { get; set; }
    public String Id { get; set; }
    public String SyncToken { get; set; }
    public MetaData MetaData { get; set; }
    public List<CustomField> CustomField { get; set; }
    public String DocNumber { get; set; }
    public String TxnDate { get; set; }
    public DepartmentRef DepartmentRef { get; set; }
    public DepartmentRef CurrencyRef { get; set; }
    public List<Line> Line { get; set; }
    public TxnTaxDetail TxnTaxDetail { get; set; }
    public DepartmentRef CustomerRef { get; set; }
    public DepartmentRef ClassRef { get; set; }
    public TaxCodeRef CustomerMemo { get; set; }
    public String PrivateNote { get; set; }
    public Double TotalAmt { get; set; }
    public Boolean ApplyTaxAfterDiscount { get; set; }
    public String PrintStatus { get; set; }
    public String EmailStatus { get; set; }
    public BillEmail BillEmail { get; set; }
    public BillEmail BillEmailCc { get; set; }
    public BillEmail BillEmailBcc { get; set; }
    public Integer Balance { get; set; }
    public DepartmentRef PaymentMethodRef { get; set; }
    public CreditCardPayment CreditCardPayment { get; set; }
    public DepartmentRef DepositToAccountRef { get; set; }
    public DeliveryInfo DeliveryInfo { get; set; }

    public SalesReceipt(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'domain') {
              domain = parser.getText();
            } else if (text == 'sparse') {
              sparse = parser.getBooleanValue();
            } else if (text == 'Id') {
              Id = parser.getText();
            } else if (text == 'SyncToken') {
              SyncToken = parser.getText();
            } else if (text == 'MetaData') {
              MetaData = new MetaData(parser);
            } else if (text == 'CustomField') {
              CustomField = arrayOfCustomField(parser);
            } else if (text == 'DocNumber') {
              DocNumber = parser.getText();
            } else if (text == 'TxnDate') {
              TxnDate = parser.getText();
            } else if (text == 'DepartmentRef') {
              DepartmentRef = new DepartmentRef(parser);
            } else if (text == 'ClassRef') {
              ClassRef = new DepartmentRef(parser);
            } else if (text == 'CurrencyRef') {
              CurrencyRef = new DepartmentRef(parser);
            } else if (text == 'Line') {
              Line = arrayOfLine(parser);
            } else if (text == 'TxnTaxDetail') {
              TxnTaxDetail = new TxnTaxDetail(parser);
            } else if (text == 'CustomerRef') {
              CustomerRef = new DepartmentRef(parser);
            } else if (text == 'TotalAmt') {
              TotalAmt = parser.getDoubleValue();
            } else if (text == 'ApplyTaxAfterDiscount') {
              ApplyTaxAfterDiscount = parser.getBooleanValue();
            } else if (text == 'PrintStatus') {
              PrintStatus = parser.getText();
            } else if (text == 'EmailStatus') {
              EmailStatus = parser.getText();
            } else if (text == 'BillEmail') {
              BillEmail = new BillEmail(parser);
            } else if (text == 'BillEmailCc') {
              BillEmailCc = new BillEmail(parser);
            } else if (text == 'BillEmailBcc') {
              BillEmailBcc = new BillEmail(parser);
            } else if (text == 'Balance') {
              Balance = parser.getIntegerValue();
            } else if (text == 'PaymentMethodRef') {
              PaymentMethodRef = new DepartmentRef(parser);
            } else if (text == 'CreditCardPayment') {
              CreditCardPayment = new CreditCardPayment(parser);
            } else if (text == 'DepositToAccountRef') {
              DepositToAccountRef = new DepartmentRef(parser);
            } else if (text == 'DeliveryInfo') {
              DeliveryInfo = new DeliveryInfo(parser);
            } else if (text == 'CustomerMemo') {
              CustomerMemo = new TaxCodeRef(parser);
            } else if (text == 'PrivateNote') {
              PrivateNote = parser.getText();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'SalesReceipt consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public QueryResponse QueryResponse { get; set; }
  public String time_Z { get; set; } // in json: time

  public QBSalesReceiptQueryJSON(JSONParser parser) {
    while (parser.nextToken() != System.JSONToken.END_OBJECT) {
      if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
        String text = parser.getText();
        if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
          if (text == 'QueryResponse') {
            QueryResponse = new QueryResponse(parser);
          } else if (text == 'time') {
            time_Z = parser.getText();
          } else {
            System.debug(
              LoggingLevel.WARN,
              'QBSalesReceiptQueryJSON consuming unrecognized property: ' + text
            );
            consumeObject(parser);
          }
        }
      }
    }
  }

  public class TaxCodeRef {
    public String value { get; set; }

    public TaxCodeRef(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'value') {
              value = parser.getText();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'TaxCodeRef consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class MetaData {
    public String CreateTime { get; set; }
    public String LastUpdatedTime { get; set; }

    public MetaData(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'CreateTime') {
              CreateTime = parser.getText();
            } else if (text == 'LastUpdatedTime') {
              LastUpdatedTime = parser.getText();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'MetaData consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class TaxLineDetail {
    public TaxCodeRef TaxRateRef { get; set; }
    public Boolean PercentBased { get; set; }
    public Integer TaxPercent { get; set; }
    public Double NetAmountTaxable { get; set; }

    public TaxLineDetail(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'TaxRateRef') {
              TaxRateRef = new TaxCodeRef(parser);
            } else if (text == 'PercentBased') {
              PercentBased = parser.getBooleanValue();
            } else if (text == 'TaxPercent') {
              TaxPercent = parser.getIntegerValue();
            } else if (text == 'NetAmountTaxable') {
              NetAmountTaxable = parser.getDoubleValue();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'TaxLineDetail consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class QueryResponse {
    public List<SalesReceipt> SalesReceipt { get; set; }
    public Integer startPosition { get; set; }
    public Integer maxResults { get; set; }
    public Integer totalCount { get; set; }

    public QueryResponse(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'SalesReceipt') {
              SalesReceipt = arrayOfSalesReceipt(parser);
            } else if (text == 'startPosition') {
              startPosition = parser.getIntegerValue();
            } else if (text == 'maxResults') {
              maxResults = parser.getIntegerValue();
            } else if (text == 'totalCount') {
              totalCount = parser.getIntegerValue();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'QueryResponse consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class CustomField {
    public CustomField(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            {
              System.debug(
                LoggingLevel.WARN,
                'CustomField consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class CreditChargeInfo {
    public Integer CcExpiryMonth { get; set; }
    public Integer CcExpiryYear { get; set; }
    public Double Amount { get; set; }

    public CreditChargeInfo(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'CcExpiryMonth') {
              CcExpiryMonth = parser.getIntegerValue();
            } else if (text == 'CcExpiryYear') {
              CcExpiryYear = parser.getIntegerValue();
            } else if (text == 'Amount') {
              Amount = parser.getDoubleValue();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'CreditChargeInfo consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class BillEmail {
    public String Address { get; set; }

    public BillEmail(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'Address') {
              Address = parser.getText();
            } else {
              System.debug(
                LoggingLevel.WARN,
                'BillEmail consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public class TxnTaxDetail {
    public TaxCodeRef TxnTaxCodeRef { get; set; }
    public Double TotalTax { get; set; }
    public List<TaxLine> TaxLine { get; set; }

    public TxnTaxDetail(JSONParser parser) {
      while (parser.nextToken() != System.JSONToken.END_OBJECT) {
        if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
          String text = parser.getText();
          if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
            if (text == 'TxnTaxCodeRef') {
              TxnTaxCodeRef = new TaxCodeRef(parser);
            } else if (text == 'TotalTax') {
              TotalTax = parser.getDoubleValue();
            } else if (text == 'TaxLine') {
              TaxLine = arrayOfTaxLine(parser);
            } else {
              System.debug(
                LoggingLevel.WARN,
                'TxnTaxDetail consuming unrecognized property: ' + text
              );
              consumeObject(parser);
            }
          }
        }
      }
    }
  }

  public static QBSalesReceiptQueryJSON parse(String json) {
    System.JSONParser parser = System.JSON.createParser(json);
    return new QBSalesReceiptQueryJSON(parser);
  }

  public static void consumeObject(System.JSONParser parser) {
    Integer depth = 0;
    do {
      System.JSONToken curr = parser.getCurrentToken();
      if (
        curr == System.JSONToken.START_OBJECT ||
        curr == System.JSONToken.START_ARRAY
      ) {
        depth++;
      } else if (
        curr == System.JSONToken.END_OBJECT ||
        curr == System.JSONToken.END_ARRAY
      ) {
        depth--;
      }
    } while (depth > 0 && parser.nextToken() != null);
  }

  private static List<Line> arrayOfLine(System.JSONParser p) {
    List<Line> res = new List<Line>();
    if (p.getCurrentToken() == null)
      p.nextToken();
    while (p.nextToken() != System.JSONToken.END_ARRAY) {
      res.add(new Line(p));
    }
    return res;
  }

  private static List<TaxLine> arrayOfTaxLine(System.JSONParser p) {
    List<TaxLine> res = new List<TaxLine>();
    if (p.getCurrentToken() == null)
      p.nextToken();
    while (p.nextToken() != System.JSONToken.END_ARRAY) {
      res.add(new TaxLine(p));
    }
    return res;
  }

  private static List<CustomField> arrayOfCustomField(System.JSONParser p) {
    List<CustomField> res = new List<CustomField>();
    if (p.getCurrentToken() == null)
      p.nextToken();
    while (p.nextToken() != System.JSONToken.END_ARRAY) {
      res.add(new CustomField(p));
    }
    return res;
  }

  private static List<SalesReceipt> arrayOfSalesReceipt(System.JSONParser p) {
    List<SalesReceipt> res = new List<SalesReceipt>();
    if (p.getCurrentToken() == null)
      p.nextToken();
    while (p.nextToken() != System.JSONToken.END_ARRAY) {
      res.add(new SalesReceipt(p));
    }
    return res;
  }
}
