// Path: src/main/java/javapns/notification/exceptions/PayloadMaxSizeExceededException.java
// public class PayloadMaxSizeExceededException extends Exception {
// 
//   private static final long serialVersionUID = 2896151447959250527L;
// 
//   /**
//    * Default constructor
//    */
//   public PayloadMaxSizeExceededException() {
//     super("Total payload size exceeds allowed limit");
//   }
// 
//   public PayloadMaxSizeExceededException(final int maxSize) {
//     super(String.format("Total payload size exceeds allowed limit (%s bytes max)", maxSize));
//   }
// 
//   public PayloadMaxSizeExceededException(final int maxSize, final int currentSize) {
//     super(String.format("Total payload size exceeds allowed limit (payload is %s bytes, limit is %s)", currentSize, maxSize));
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public PayloadMaxSizeExceededException(final String message) {
//     super(message);
//   }
// 
// }
// 
// Path: src/main/java/javapns/notification/exceptions/PayloadMaxSizeProbablyExceededException.java
// public class PayloadMaxSizeProbablyExceededException extends JSONException {
// 
//   private static final long serialVersionUID = 580227446786047134L;
// 
//   /**
//    * Default constructor
//    */
//   public PayloadMaxSizeProbablyExceededException() {
//     super("Total payload size will most likely exceed allowed limit");
//   }
// 
//   public PayloadMaxSizeProbablyExceededException(final int maxSize) {
//     super(String.format("Total payload size will most likely exceed allowed limit (%s bytes max)", maxSize));
//   }
// 
//   public PayloadMaxSizeProbablyExceededException(final int maxSize, final int estimatedSize) {
//     super(String.format("Total payload size will most likely exceed allowed limit (estimated to become %s bytes, limit is %s)", estimatedSize, maxSize));
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public PayloadMaxSizeProbablyExceededException(final String message) {
//     super(message);
//   }
// 
// }


import javapns.notification.exceptions.PayloadMaxSizeExceededException;
import javapns.notification.exceptions.PayloadMaxSizeProbablyExceededException;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
      try {
        return getPayloadSize();
      } catch (final Exception e1) {
        return 0;
      }
    }
  }

  /**
   * Validate if the estimated payload size after adding a given property will be allowed.
   * For performance reasons, this estimate is not as reliable as actually adding
   * the property and checking the payload size afterwards.
   *
   * @param propertyName  the name of the property to use for calculating the estimation
   * @param propertyValue the value of the property to use for calculating the estimation
   * @return true if the payload size is not expected to exceed the maximum allowed, false if it might be too big
   */
  public boolean isEstimatedPayloadSizeAllowedAfterAdding(final String propertyName, final Object propertyValue) {
    final int maximumPayloadSize = getMaximumPayloadSize();
    final int estimatedPayloadSize = estimatePayloadSizeAfterAdding(propertyName, propertyValue);
    return estimatedPayloadSize <= maximumPayloadSize;
  }

  /**
   * Validate that the payload does not exceed the maximum size allowed.
   * If the limit is exceeded, a PayloadMaxSizeExceededException is thrown.
   *
   * @param currentPayloadSize the total size of the payload in bytes
   * @throws PayloadMaxSizeExceededException if the payload exceeds the maximum size allowed
   */
// Path: src/main/java/javapns/notification/exceptions/PayloadMaxSizeExceededException.java
// public class PayloadMaxSizeExceededException extends Exception {
// 
//   private static final long serialVersionUID = 2896151447959250527L;
// 
//   /**
//    * Default constructor
//    */
//   public PayloadMaxSizeExceededException() {
//     super("Total payload size exceeds allowed limit");
//   }
// 
//   public PayloadMaxSizeExceededException(final int maxSize) {
//     super(String.format("Total payload size exceeds allowed limit (%s bytes max)", maxSize));
//   }
// 
//   public PayloadMaxSizeExceededException(final int maxSize, final int currentSize) {
//     super(String.format("Total payload size exceeds allowed limit (payload is %s bytes, limit is %s)", currentSize, maxSize));
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public PayloadMaxSizeExceededException(final String message) {
//     super(message);
//   }
// 
// }
// 
// Path: src/main/java/javapns/notification/exceptions/PayloadMaxSizeProbablyExceededException.java
// public class PayloadMaxSizeProbablyExceededException extends JSONException {
// 
//   private static final long serialVersionUID = 580227446786047134L;
// 
//   /**
//    * Default constructor
//    */
//   public PayloadMaxSizeProbablyExceededException() {
//     super("Total payload size will most likely exceed allowed limit");
//   }
// 
//   public PayloadMaxSizeProbablyExceededException(final int maxSize) {
//     super(String.format("Total payload size will most likely exceed allowed limit (%s bytes max)", maxSize));
//   }
// 
//   public PayloadMaxSizeProbablyExceededException(final int maxSize, final int estimatedSize) {
//     super(String.format("Total payload size will most likely exceed allowed limit (estimated to become %s bytes, limit is %s)", estimatedSize, maxSize));
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public PayloadMaxSizeProbablyExceededException(final String message) {
//     super(message);
//   }
// 
// }


// Path: src/main/java/javapns/notification/Payload.java
import javapns.notification.exceptions.PayloadMaxSizeExceededException;
import javapns.notification.exceptions.PayloadMaxSizeProbablyExceededException;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;

      try {
        return getPayloadSize();
      } catch (final Exception e1) {
        return 0;
      }
    }
  }

  /**
   * Validate if the estimated payload size after adding a given property will be allowed.
   * For performance reasons, this estimate is not as reliable as actually adding
   * the property and checking the payload size afterwards.
   *
   * @param propertyName  the name of the property to use for calculating the estimation
   * @param propertyValue the value of the property to use for calculating the estimation
   * @return true if the payload size is not expected to exceed the maximum allowed, false if it might be too big
   */
  public boolean isEstimatedPayloadSizeAllowedAfterAdding(final String propertyName, final Object propertyValue) {
    final int maximumPayloadSize = getMaximumPayloadSize();
    final int estimatedPayloadSize = estimatePayloadSizeAfterAdding(propertyName, propertyValue);
    return estimatedPayloadSize <= maximumPayloadSize;
  }

  /**
   * Validate that the payload does not exceed the maximum size allowed.
   * If the limit is exceeded, a PayloadMaxSizeExceededException is thrown.
   *
   * @param currentPayloadSize the total size of the payload in bytes
   * @throws PayloadMaxSizeExceededException if the payload exceeds the maximum size allowed
   */
  private void validateMaximumPayloadSize(final int currentPayloadSize) throws PayloadMaxSizeExceededException {