com.ecwid.apiclient.v3.dto.coupon.request.CouponSearchRequest.kt Maven / Gradle / Ivy
The newest version!
package com.ecwid.apiclient.v3.dto.coupon.request
import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.dto.order.enums.DiscountCouponStatus
import com.ecwid.apiclient.v3.dto.order.enums.DiscountCouponType
import com.ecwid.apiclient.v3.impl.RequestInfo
import com.ecwid.apiclient.v3.responsefields.ResponseFields
import java.util.*
import java.util.concurrent.TimeUnit
data class CouponSearchRequest(
val offset: Int = 0,
val limit: Int = 100,
val code: String? = null,
val discountType: Set? = null,
val availability: DiscountCouponStatus? = null,
val createdFrom: Date? = null,
val createdTo: Date? = null,
val updatedFrom: Date? = null,
val updatedTo: Date? = null,
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"discount_coupons"
),
params = toParams(),
responseFields = responseFields,
)
private fun toParams(): Map {
val request = this
return mutableMapOf().apply {
put("offset", request.offset.toString())
put("limit", request.limit.toString())
request.code?.let { put("code", it) }
request.discountType?.let { put("discount_type", it.joinToString(separator = ",")) }
request.availability?.let { put("availability", it.name) }
request.createdFrom?.let { put("createdFrom", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
request.createdTo?.let { put("createdTo", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
request.updatedFrom?.let { put("updatedFrom", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
request.updatedTo?.let { put("updatedTo", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
}.toMap()
}
}