package nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto;

import org.immutables.value.Value;

import java.util.Base64;
import java.util.Optional;

@Value.Immutable
public interface PaginationArguments {

  /**
   * Cursor is either
   *  - the empty string which indicates pagination from the first item forwards
   *  - the literal value "LAST" which indicates pagination from the last item backwards
   *  - a magic cookie (a token generated by the data provider and passed back verbatim) that should contain information
   *    on where to start and what direction to take.
   */
  String getCursor();

  /**
   * Count is either a positive number which provides a suggestion on how many items to return (might be overridden by
   * the data provider) or a negative number (usually -1) that indicates that there is no preference
   */
  int getCount();

  /**
   * If filter is present, it contains a configured function that returns Uri's of objects matching a query as provided
   * by the user
   */
  Optional<ConfiguredFilter> getFilter();

  static PaginationArguments create(int count, String cursor, Optional<ConfiguredFilter> filter) {
    return ImmutablePaginationArguments.builder()
      .count(count)
      .filter(filter)
      .cursor(cursor)
      .build();
  }
}
