// File generated from our OpenAPI spec by Stainless.

package com.increase.api.models.events

import com.increase.api.core.http.QueryParams
import java.time.OffsetDateTime
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class EventListParamsTest {

    @Test
    fun create() {
        EventListParams.builder()
            .associatedObjectId("associated_object_id")
            .category(
                EventListParams.Category.builder()
                    .addIn(EventListParams.Category.In.ACCOUNT_CREATED)
                    .build()
            )
            .createdAt(
                EventListParams.CreatedAt.builder()
                    .after(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                    .before(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                    .onOrAfter(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                    .onOrBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                    .build()
            )
            .cursor("cursor")
            .limit(1L)
            .orderBy(
                EventListParams.OrderBy.builder()
                    .direction(EventListParams.OrderBy.Direction.ASCENDING)
                    .field(EventListParams.OrderBy.Field.CREATED_AT)
                    .build()
            )
            .build()
    }

    @Test
    fun queryParams() {
        val params =
            EventListParams.builder()
                .associatedObjectId("associated_object_id")
                .category(
                    EventListParams.Category.builder()
                        .addIn(EventListParams.Category.In.ACCOUNT_CREATED)
                        .build()
                )
                .createdAt(
                    EventListParams.CreatedAt.builder()
                        .after(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                        .before(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                        .onOrAfter(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                        .onOrBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
                        .build()
                )
                .cursor("cursor")
                .limit(1L)
                .orderBy(
                    EventListParams.OrderBy.builder()
                        .direction(EventListParams.OrderBy.Direction.ASCENDING)
                        .field(EventListParams.OrderBy.Field.CREATED_AT)
                        .build()
                )
                .build()

        val queryParams = params._queryParams()

        assertThat(queryParams)
            .isEqualTo(
                QueryParams.builder()
                    .put("associated_object_id", "associated_object_id")
                    .put("category.in", listOf("account.created").joinToString(","))
                    .put("created_at.after", "2019-12-27T18:11:19.117Z")
                    .put("created_at.before", "2019-12-27T18:11:19.117Z")
                    .put("created_at.on_or_after", "2019-12-27T18:11:19.117Z")
                    .put("created_at.on_or_before", "2019-12-27T18:11:19.117Z")
                    .put("cursor", "cursor")
                    .put("limit", "1")
                    .put("order_by.direction", "ascending")
                    .put("order_by.field", "created_at")
                    .build()
            )
    }

    @Test
    fun queryParamsWithoutOptionalFields() {
        val params = EventListParams.builder().build()

        val queryParams = params._queryParams()

        assertThat(queryParams).isEqualTo(QueryParams.builder().build())
    }
}
