package com.isidroid.network.request

import com.google.gson.annotations.SerializedName

class FilteredRequest<T>(
    @SerializedName("filters") val filters: T,
    @SerializedName("pagination") val pagination: PagingRequest = PagingRequest(),
    @SerializedName("sorting") var sorting: SortingRequest? = null,

    page: Int? = null,
    limit: Int? = null,
    sortField: String? = null,
    isSortAsc: Boolean? = null
) {
    init {
        page?.also { pagination.page = it }
        limit?.also { pagination.limit = it }

        if (sortField != null)
            sorting = SortingRequest(
                field = sortField,
                direction = if (isSortAsc == true) "asc" else "desc"
            )

    }
}