# `FlopRest.Pagination`
[🔗](https://github.com/guess/flop_rest/blob/v0.6.1/lib/flop_rest/pagination.ex#L1)

Transforms REST-style pagination params to Flop format and vice versa.

Supports three pagination types:

- **Cursor-based**: `limit`, `after`, `before`
- **Page-based**: `page`, `page_size`
- **Offset-based**: `offset`, `limit`

When only `limit` is provided, it defaults to cursor-based pagination
(`first`). This ensures Flop returns cursor metadata that can be used
for subsequent requests with `after`/`before`. To force
offset-based pagination, include `offset` (e.g., `offset=0`).

No validation is performed - conflicting params are passed through
for Flop to validate.

# `reserved_keys`

```elixir
@spec reserved_keys() :: [String.t()]
```

Returns the list of reserved pagination keys.

# `to_rest`

```elixir
@spec to_rest(Flop.t()) :: map()
```

Converts a Flop struct's pagination fields back to REST-style params.

## Examples

    iex> FlopRest.Pagination.to_rest(%Flop{first: 20, after: "abc"})
    %{"limit" => 20, "after" => "abc"}

    iex> FlopRest.Pagination.to_rest(%Flop{last: 20, before: "xyz"})
    %{"limit" => 20, "before" => "xyz"}

    iex> FlopRest.Pagination.to_rest(%Flop{page: 2, page_size: 25})
    %{"page" => 2, "page_size" => 25}

    iex> FlopRest.Pagination.to_rest(%Flop{offset: 50, limit: 25})
    %{"offset" => 50, "limit" => 25}

    iex> FlopRest.Pagination.to_rest(%Flop{})
    %{}

# `transform`

```elixir
@spec transform(map()) :: map()
```

Transforms pagination parameters to Flop format.

## Examples

    iex> FlopRest.Pagination.transform(%{"limit" => "20", "after" => "abc"})
    %{"first" => 20, "after" => "abc"}

    iex> FlopRest.Pagination.transform(%{"limit" => "20"})
    %{"first" => 20}

    iex> FlopRest.Pagination.transform(%{"page" => "2", "page_size" => "25"})
    %{"page" => 2, "page_size" => 25}

    iex> FlopRest.Pagination.transform(%{"offset" => "0", "limit" => "25"})
    %{"offset" => 0, "limit" => 25}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
