package com.stripe.model;

import com.stripe.net.RequestOptions;

import java.util.List;
import java.util.Map;

/**
 * Provides a representation of a single page worth of data from the Stripe
 * API.
 *
 * <p>The following code will have the effect of iterating through a single page
 * worth of invoice data retrieve from the API:
 *
 * <p><pre>
 * {@code
 * foreach (Invoice invoice : Invoice.list(...).getData()) {
 *   System.out.println("Current invoice = " + invoice.toString());
 * }
 * }
 * </pre>
 *
 * <p>The class also provides a helper for iterating over collections that may be
 * longer than a single page:
 *
 * <p><pre>
 * {@code
 * foreach (Invoice invoice : Invoice.list(...).autoPagingIterable()) {
 *   System.out.println("Current invoice = " + invoice.toString());
 * }
 * }
 * </pre>
 */
public abstract class StripeCollection<T extends HasId> extends StripeObject
    implements StripeCollectionInterface<T> {
  List<T> data;
  Long totalCount;
  Boolean hasMore;
  private RequestOptions requestOptions;
  private Map<String, Object> requestParams;
  String url;

  /**
   * 3/2014: Legacy (from before newstyle pagination API).
   */
  Long count;

  @Override
  public List<T> getData() {
    return data;
  }

  public void setData(List<T> data) {
    this.data = data;
  }

  @Override
  public Long getTotalCount() {
    return totalCount;
  }

  public void setTotalCount(Long totalCount) {
    this.totalCount = totalCount;
  }

  @Override
  public Boolean getHasMore() {
    return hasMore;
  }

  public void setHasMore(Boolean hasMore) {
    this.hasMore = hasMore;
  }

  @Override
  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  /**
   * 3/2014: Legacy (from before newstyle pagination API).
   */
  public Long getCount() {
    return count;
  }

  /**
   * 3/2014: Legacy (from before newstyle pagination API).
   */
  public void setCount(Long count) {
    this.count = count;
  }

  public Iterable<T> autoPagingIterable() {
    return new PagingIterable<T>(this);
  }

  public Iterable<T> autoPagingIterable(Map<String, Object> params) {
    this.setRequestParams(params);
    return new PagingIterable<T>(this);
  }

  /**
   * Constructs an iterable that can be used to iterate across all objects
   * across all pages. As page boundaries are encountered, the next page will
   * be fetched automatically for continued iteration.
   *
   * @param params request parameters (will override the parameters from the initial list request)
   * @param options request options (will override the options from the initial list request)
   */
  public Iterable<T> autoPagingIterable(Map<String, Object> params, RequestOptions options) {
    this.setRequestOptions(options);
    this.setRequestParams(params);
    return new PagingIterable<T>(this);
  }

  @Override
  public RequestOptions getRequestOptions() {
    return this.requestOptions;
  }

  @Override
  public Map<String, Object> getRequestParams() {
    return this.requestParams;
  }

  @Override
  public void setRequestOptions(RequestOptions requestOptions) {
    this.requestOptions = requestOptions;
  }

  @Override
  public void setRequestParams(Map<String, Object> requestParams) {
    this.requestParams = requestParams;
  }
}

@@ -105,16 +105,94 @@
 l.Map;%0A%0A
+import lombok.EqualsAndHashCode;%0Aimport lombok.Getter;%0Aimport lombok.Setter;%0A%0A
 /**%0A * P
@@ -881,16 +881,70 @@
 re%3E%0A */%0A
+@Getter%0A@Setter%0A@EqualsAndHashCode(callSuper = false)%0A
 public a
@@ -1064,1055 +1064,696 @@
 %7B%0A  
-List%3CT%3E data;%0A  Long totalCount;%0A  Boolean hasMore;%0A  private RequestOptions requestOptions;%0A  private Map%3CString, Object%3E requestParams;%0A  String url;%0A%0A  /**%0A   * 3/2014: Legacy (from before newstyle pagination API)
+String object;%0A  @Getter(onMethod = @__(%7B@Override%7D)) List%3CT%3E data;%0A  @Getter(onMethod = @__(%7B@Override%7D)) Boolean hasMore;%0A  @Getter(onMethod = @__(%7B@Override%7D)) Long totalCount;%0A  @Getter(onMethod = @__(%7B@Override%7D)) String url;%0A%0A  /**%0A   * The %7B@code count%7D attribute
 .%0A   *
-/
 %0A  
-Long count;%0A%0A  @Override%0A  public List%3CT%3E getData() %7B%0A    return data;%0A  %7D%0A%0A  public void setData(List%3CT%3E data) %7B%0A    this.data = data;%0A  %7D%0A%0A  @Override%0A  public Long getTotalCount() %7B%0A    return totalCount;%0A  %7D%0A%0A  public void setTotalCount(Long totalCount) %7B%0A    this.totalCount = totalCount;%0A  %7D%0A%0A  @Override%0A  public Boolean getHasMore() %7B%0A    return hasMore;%0A  %7D%0A%0A  public void setHasMore(Boolean hasMore) %7B%0A    this.hasMore = hasMore;%0A  %7D%0A%0A  @Override%0A  public String getUrl() %7B%0A    return url;%0A  %7D%0A%0A  public void setUrl(String url) %7B%0A    this.url = url;%0A  %7D%0A%0A  /**%0A   * 3/2014: Legacy (from before newstyle pagination API).%0A   */%0A  public Long getCount() %7B%0A    return count;%0A  %7D%0A%0A  /**%0A   * 3/2014: Legacy (from before newstyle pagination API).%0A   */%0A  public void setCount(Long count) %7B%0A    this.count = count;%0A  %7D
+ * @deprecated Use pagination parameters instead.%0A   * @see %3Ca href=%22https://stripe.com/docs/api/java#pagination%22%3EPagination%3C/a%3E%0A   */%0A  @Deprecated%0A  Long count;%0A%0A  @Getter(onMethod = @__(%7B@Override%7D)) @Setter(onMethod = @__(%7B@Override%7D))%0A      private RequestOptions requestOptions;%0A  @Getter(onMethod = @__(%7B@Override%7D)) @Setter(onMethod = @__(%7B@Override%7D))%0A      private Map%3CString, Object%3E requestParams;
 %0A%0A  
@@ -2620,449 +2620,7 @@
 %0A  %7D
-%0A%0A  @Override%0A  public RequestOptions getRequestOptions() %7B%0A    return this.requestOptions;%0A  %7D%0A%0A  @Override%0A  public Map%3CString, Object%3E getRequestParams() %7B%0A    return this.requestParams;%0A  %7D%0A%0A  @Override%0A  public void setRequestOptions(RequestOptions requestOptions) %7B%0A    this.requestOptions = requestOptions;%0A  %7D%0A%0A  @Override%0A  public void setRequestParams(Map%3CString, Object%3E requestParams) %7B%0A    this.requestParams = requestParams;%0A  %7D
 %0A%7D%0A

Use Lombok for StripeCollection