From a2e9d20128590a3a1487ef3ac17a53c647d9ea14 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 22:15:14 +0000 Subject: [PATCH 1/2] feat(preferences): workspace preference sections & nested topics endpoints --- .stats.yml | 8 +- .../com/courier/client/CourierClient.kt | 5 + .../com/courier/client/CourierClientAsync.kt | 5 + .../courier/client/CourierClientAsyncImpl.kt | 15 + .../com/courier/client/CourierClientImpl.kt | 15 + .../PreferenceSectionArchiveParams.kt | 236 ++++ .../PreferenceSectionCreateParams.kt | 212 ++++ .../PreferenceSectionCreateRequest.kt | 308 +++++ .../PreferenceSectionGetResponse.kt | 553 +++++++++ .../PreferenceSectionListParams.kt | 175 +++ .../PreferenceSectionListResponse.kt | 204 ++++ .../PreferenceSectionPublishParams.kt | 218 ++++ .../PreferenceSectionReplaceParams.kt | 243 ++++ .../PreferenceSectionReplaceRequest.kt | 312 +++++ .../PreferenceSectionRetrieveParams.kt | 198 ++++ .../PreferenceTopicCreateRequest.kt | 868 ++++++++++++++ .../PreferenceTopicGetResponse.kt | 1037 +++++++++++++++++ .../PreferenceTopicListResponse.kt | 203 ++++ .../PreferenceTopicReplaceRequest.kt | 869 ++++++++++++++ .../PublishPreferencesResponse.kt | 363 ++++++ .../topics/TopicArchiveParams.kt | 258 ++++ .../topics/TopicCreateParams.kt | 235 ++++ .../topics/TopicListParams.kt | 189 +++ .../topics/TopicReplaceParams.kt | 255 ++++ .../topics/TopicRetrieveParams.kt | 220 ++++ .../async/PreferenceSectionServiceAsync.kt | 428 +++++++ .../PreferenceSectionServiceAsyncImpl.kt | 300 +++++ .../preferencesections/TopicServiceAsync.kt | 348 ++++++ .../TopicServiceAsyncImpl.kt | 270 +++++ .../blocking/PreferenceSectionService.kt | 427 +++++++ .../blocking/PreferenceSectionServiceImpl.kt | 277 +++++ .../preferencesections/TopicService.kt | 339 ++++++ .../preferencesections/TopicServiceImpl.kt | 252 ++++ .../PreferenceSectionArchiveParamsTest.kt | 23 + .../PreferenceSectionCreateParamsTest.kt | 65 ++ .../PreferenceSectionCreateRequestTest.kt | 48 + .../PreferenceSectionGetResponseTest.kt | 120 ++ .../PreferenceSectionListParamsTest.kt | 13 + .../PreferenceSectionListResponseTest.kt | 138 +++ .../PreferenceSectionPublishParamsTest.kt | 13 + .../PreferenceSectionReplaceParamsTest.kt | 80 ++ .../PreferenceSectionReplaceRequestTest.kt | 48 + .../PreferenceSectionRetrieveParamsTest.kt | 23 + .../PreferenceTopicCreateRequestTest.kt | 72 ++ .../PreferenceTopicGetResponseTest.kt | 86 ++ .../PreferenceTopicListResponseTest.kt | 95 ++ .../PreferenceTopicReplaceRequestTest.kt | 73 ++ .../PublishPreferencesResponseTest.kt | 50 + .../topics/TopicArchiveParamsTest.kt | 25 + .../topics/TopicCreateParamsTest.kt | 115 ++ .../topics/TopicListParamsTest.kt | 23 + .../topics/TopicReplaceParamsTest.kt | 122 ++ .../topics/TopicRetrieveParamsTest.kt | 25 + .../PreferenceSectionServiceAsyncTest.kt | 105 ++ .../TopicServiceAsyncTest.kt | 126 ++ .../blocking/PreferenceSectionServiceTest.kt | 97 ++ .../preferencesections/TopicServiceTest.kt | 119 ++ .../proguard/ProGuardCompatibilityTest.kt | 1 + 58 files changed, 11546 insertions(+), 4 deletions(-) create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionArchiveParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateRequest.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionGetResponse.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionListParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionListResponse.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionPublishParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceRequest.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionRetrieveParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicCreateRequest.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicGetResponse.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicListResponse.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicReplaceRequest.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PublishPreferencesResponse.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicArchiveParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicCreateParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicListParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicReplaceParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicRetrieveParams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/services/async/PreferenceSectionServiceAsync.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/services/async/PreferenceSectionServiceAsyncImpl.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/services/async/preferencesections/TopicServiceAsync.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/services/async/preferencesections/TopicServiceAsyncImpl.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/services/blocking/PreferenceSectionService.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/services/blocking/PreferenceSectionServiceImpl.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/services/blocking/preferencesections/TopicService.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/services/blocking/preferencesections/TopicServiceImpl.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionArchiveParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateRequestTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionGetResponseTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionListParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionListResponseTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionPublishParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceRequestTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionRetrieveParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicCreateRequestTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicGetResponseTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicListResponseTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicReplaceRequestTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PublishPreferencesResponseTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicArchiveParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicCreateParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicListParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicReplaceParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicRetrieveParamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/services/async/PreferenceSectionServiceAsyncTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/services/async/preferencesections/TopicServiceAsyncTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/services/blocking/PreferenceSectionServiceTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/services/blocking/preferencesections/TopicServiceTest.kt diff --git a/.stats.yml b/.stats.yml index 0dd4709..9be8c11 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 123 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier/courier-f54bd32a07b6d85cfda75812728f86aa295b0f3fb662ead7670179f809195896.yml -openapi_spec_hash: 0a283754d97445ef84d50720ba47081a -config_hash: 3536872b17998fc451577505e15afb3d +configured_endpoints: 134 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier/courier-e0c54fd2a28d7beec2c18a6c7abb833e0dd9b14e99c48cf1cfd126f664f1dc62.yml +openapi_spec_hash: 713a396d0875e2000de918032b499b2e +config_hash: 83c79a6ad0a0b5dcce3b85208026343b diff --git a/courier-java-core/src/main/kotlin/com/courier/client/CourierClient.kt b/courier-java-core/src/main/kotlin/com/courier/client/CourierClient.kt index 5460c23..392b1f9 100644 --- a/courier-java-core/src/main/kotlin/com/courier/client/CourierClient.kt +++ b/courier-java-core/src/main/kotlin/com/courier/client/CourierClient.kt @@ -15,6 +15,7 @@ import com.courier.services.blocking.JourneyService import com.courier.services.blocking.ListService import com.courier.services.blocking.MessageService import com.courier.services.blocking.NotificationService +import com.courier.services.blocking.PreferenceSectionService import com.courier.services.blocking.ProfileService import com.courier.services.blocking.ProviderService import com.courier.services.blocking.RequestService @@ -93,6 +94,8 @@ interface CourierClient { fun routingStrategies(): RoutingStrategyService + fun preferenceSections(): PreferenceSectionService + fun profiles(): ProfileService fun tenants(): TenantService @@ -156,6 +159,8 @@ interface CourierClient { fun routingStrategies(): RoutingStrategyService.WithRawResponse + fun preferenceSections(): PreferenceSectionService.WithRawResponse + fun profiles(): ProfileService.WithRawResponse fun tenants(): TenantService.WithRawResponse diff --git a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsync.kt b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsync.kt index 68f03a7..8070b04 100644 --- a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsync.kt +++ b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsync.kt @@ -15,6 +15,7 @@ import com.courier.services.async.JourneyServiceAsync import com.courier.services.async.ListServiceAsync import com.courier.services.async.MessageServiceAsync import com.courier.services.async.NotificationServiceAsync +import com.courier.services.async.PreferenceSectionServiceAsync import com.courier.services.async.ProfileServiceAsync import com.courier.services.async.ProviderServiceAsync import com.courier.services.async.RequestServiceAsync @@ -93,6 +94,8 @@ interface CourierClientAsync { fun routingStrategies(): RoutingStrategyServiceAsync + fun preferenceSections(): PreferenceSectionServiceAsync + fun profiles(): ProfileServiceAsync fun tenants(): TenantServiceAsync @@ -160,6 +163,8 @@ interface CourierClientAsync { fun routingStrategies(): RoutingStrategyServiceAsync.WithRawResponse + fun preferenceSections(): PreferenceSectionServiceAsync.WithRawResponse + fun profiles(): ProfileServiceAsync.WithRawResponse fun tenants(): TenantServiceAsync.WithRawResponse diff --git a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsyncImpl.kt index e23ede4..a242769 100644 --- a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsyncImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsyncImpl.kt @@ -28,6 +28,8 @@ import com.courier.services.async.MessageServiceAsync import com.courier.services.async.MessageServiceAsyncImpl import com.courier.services.async.NotificationServiceAsync import com.courier.services.async.NotificationServiceAsyncImpl +import com.courier.services.async.PreferenceSectionServiceAsync +import com.courier.services.async.PreferenceSectionServiceAsyncImpl import com.courier.services.async.ProfileServiceAsync import com.courier.services.async.ProfileServiceAsyncImpl import com.courier.services.async.ProviderServiceAsync @@ -119,6 +121,10 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier RoutingStrategyServiceAsyncImpl(clientOptionsWithUserAgent) } + private val preferenceSections: PreferenceSectionServiceAsync by lazy { + PreferenceSectionServiceAsyncImpl(clientOptionsWithUserAgent) + } + private val profiles: ProfileServiceAsync by lazy { ProfileServiceAsyncImpl(clientOptionsWithUserAgent) } @@ -172,6 +178,8 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier override fun routingStrategies(): RoutingStrategyServiceAsync = routingStrategies + override fun preferenceSections(): PreferenceSectionServiceAsync = preferenceSections + override fun profiles(): ProfileServiceAsync = profiles override fun tenants(): TenantServiceAsync = tenants @@ -249,6 +257,10 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier RoutingStrategyServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val preferenceSections: PreferenceSectionServiceAsync.WithRawResponse by lazy { + PreferenceSectionServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val profiles: ProfileServiceAsync.WithRawResponse by lazy { ProfileServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -305,6 +317,9 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier override fun routingStrategies(): RoutingStrategyServiceAsync.WithRawResponse = routingStrategies + override fun preferenceSections(): PreferenceSectionServiceAsync.WithRawResponse = + preferenceSections + override fun profiles(): ProfileServiceAsync.WithRawResponse = profiles override fun tenants(): TenantServiceAsync.WithRawResponse = tenants diff --git a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientImpl.kt b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientImpl.kt index 82fa31c..b1383bb 100644 --- a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientImpl.kt @@ -28,6 +28,8 @@ import com.courier.services.blocking.MessageService import com.courier.services.blocking.MessageServiceImpl import com.courier.services.blocking.NotificationService import com.courier.services.blocking.NotificationServiceImpl +import com.courier.services.blocking.PreferenceSectionService +import com.courier.services.blocking.PreferenceSectionServiceImpl import com.courier.services.blocking.ProfileService import com.courier.services.blocking.ProfileServiceImpl import com.courier.services.blocking.ProviderService @@ -107,6 +109,10 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien RoutingStrategyServiceImpl(clientOptionsWithUserAgent) } + private val preferenceSections: PreferenceSectionService by lazy { + PreferenceSectionServiceImpl(clientOptionsWithUserAgent) + } + private val profiles: ProfileService by lazy { ProfileServiceImpl(clientOptionsWithUserAgent) } private val tenants: TenantService by lazy { TenantServiceImpl(clientOptionsWithUserAgent) } @@ -156,6 +162,8 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien override fun routingStrategies(): RoutingStrategyService = routingStrategies + override fun preferenceSections(): PreferenceSectionService = preferenceSections + override fun profiles(): ProfileService = profiles override fun tenants(): TenantService = tenants @@ -233,6 +241,10 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien RoutingStrategyServiceImpl.WithRawResponseImpl(clientOptions) } + private val preferenceSections: PreferenceSectionService.WithRawResponse by lazy { + PreferenceSectionServiceImpl.WithRawResponseImpl(clientOptions) + } + private val profiles: ProfileService.WithRawResponse by lazy { ProfileServiceImpl.WithRawResponseImpl(clientOptions) } @@ -288,6 +300,9 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien override fun routingStrategies(): RoutingStrategyService.WithRawResponse = routingStrategies + override fun preferenceSections(): PreferenceSectionService.WithRawResponse = + preferenceSections + override fun profiles(): ProfileService.WithRawResponse = profiles override fun tenants(): TenantService.WithRawResponse = tenants diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionArchiveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionArchiveParams.kt new file mode 100644 index 0000000..2fcbc96 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionArchiveParams.kt @@ -0,0 +1,236 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import com.courier.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Archive a preference section. The section must be empty: delete its topics first, otherwise the + * request fails with 409. + */ +class PreferenceSectionArchiveParams +private constructor( + private val sectionId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun sectionId(): Optional = Optional.ofNullable(sectionId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): PreferenceSectionArchiveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceSectionArchiveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionArchiveParams]. */ + class Builder internal constructor() { + + private var sectionId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceSectionArchiveParams: PreferenceSectionArchiveParams) = apply { + sectionId = preferenceSectionArchiveParams.sectionId + additionalHeaders = preferenceSectionArchiveParams.additionalHeaders.toBuilder() + additionalQueryParams = preferenceSectionArchiveParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + preferenceSectionArchiveParams.additionalBodyProperties.toMutableMap() + } + + fun sectionId(sectionId: String?) = apply { this.sectionId = sectionId } + + /** Alias for calling [Builder.sectionId] with `sectionId.orElse(null)`. */ + fun sectionId(sectionId: Optional) = sectionId(sectionId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [PreferenceSectionArchiveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PreferenceSectionArchiveParams = + PreferenceSectionArchiveParams( + sectionId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sectionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionArchiveParams && + sectionId == other.sectionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(sectionId, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "PreferenceSectionArchiveParams{sectionId=$sectionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateParams.kt new file mode 100644 index 0000000..a175a88 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateParams.kt @@ -0,0 +1,212 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects + +/** + * Create a preference section in your workspace. The section id is generated and returned. Topics + * are created inside a section via POST /preferences/sections/{section_id}/topics. + */ +class PreferenceSectionCreateParams +private constructor( + private val preferenceSectionCreateRequest: PreferenceSectionCreateRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Request body for creating a preference section. */ + fun preferenceSectionCreateRequest(): PreferenceSectionCreateRequest = + preferenceSectionCreateRequest + + fun _additionalBodyProperties(): Map = + preferenceSectionCreateRequest._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceSectionCreateParams]. + * + * The following fields are required: + * ```java + * .preferenceSectionCreateRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionCreateParams]. */ + class Builder internal constructor() { + + private var preferenceSectionCreateRequest: PreferenceSectionCreateRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(preferenceSectionCreateParams: PreferenceSectionCreateParams) = apply { + preferenceSectionCreateRequest = + preferenceSectionCreateParams.preferenceSectionCreateRequest + additionalHeaders = preferenceSectionCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = preferenceSectionCreateParams.additionalQueryParams.toBuilder() + } + + /** Request body for creating a preference section. */ + fun preferenceSectionCreateRequest( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest + ) = apply { this.preferenceSectionCreateRequest = preferenceSectionCreateRequest } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreferenceSectionCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .preferenceSectionCreateRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceSectionCreateParams = + PreferenceSectionCreateParams( + checkRequired("preferenceSectionCreateRequest", preferenceSectionCreateRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): PreferenceSectionCreateRequest = preferenceSectionCreateRequest + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionCreateParams && + preferenceSectionCreateRequest == other.preferenceSectionCreateRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(preferenceSectionCreateRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "PreferenceSectionCreateParams{preferenceSectionCreateRequest=$preferenceSectionCreateRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateRequest.kt new file mode 100644 index 0000000..700d10c --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateRequest.kt @@ -0,0 +1,308 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Request body for creating a preference section. */ +class PreferenceSectionCreateRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val name: JsonField, + private val hasCustomRouting: JsonField, + private val routingOptions: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("has_custom_routing") + @ExcludeMissing + hasCustomRouting: JsonField = JsonMissing.of(), + @JsonProperty("routing_options") + @ExcludeMissing + routingOptions: JsonField> = JsonMissing.of(), + ) : this(name, hasCustomRouting, routingOptions, mutableMapOf()) + + /** + * Human-readable name for the section. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Whether the section defines custom routing for its topics. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun hasCustomRouting(): Optional = hasCustomRouting.getOptional("has_custom_routing") + + /** + * Default channels for the section. Defaults to empty if omitted. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun routingOptions(): Optional> = + routingOptions.getOptional("routing_options") + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [hasCustomRouting]. + * + * Unlike [hasCustomRouting], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("has_custom_routing") + @ExcludeMissing + fun _hasCustomRouting(): JsonField = hasCustomRouting + + /** + * Returns the raw JSON value of [routingOptions]. + * + * Unlike [routingOptions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing_options") + @ExcludeMissing + fun _routingOptions(): JsonField> = routingOptions + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceSectionCreateRequest]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionCreateRequest]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var hasCustomRouting: JsonField = JsonMissing.of() + private var routingOptions: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceSectionCreateRequest: PreferenceSectionCreateRequest) = apply { + name = preferenceSectionCreateRequest.name + hasCustomRouting = preferenceSectionCreateRequest.hasCustomRouting + routingOptions = + preferenceSectionCreateRequest.routingOptions.map { it.toMutableList() } + additionalProperties = + preferenceSectionCreateRequest.additionalProperties.toMutableMap() + } + + /** Human-readable name for the section. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Whether the section defines custom routing for its topics. */ + fun hasCustomRouting(hasCustomRouting: Boolean?) = + hasCustomRouting(JsonField.ofNullable(hasCustomRouting)) + + /** + * Alias for [Builder.hasCustomRouting]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun hasCustomRouting(hasCustomRouting: Boolean) = + hasCustomRouting(hasCustomRouting as Boolean?) + + /** Alias for calling [Builder.hasCustomRouting] with `hasCustomRouting.orElse(null)`. */ + fun hasCustomRouting(hasCustomRouting: Optional) = + hasCustomRouting(hasCustomRouting.getOrNull()) + + /** + * Sets [Builder.hasCustomRouting] to an arbitrary JSON value. + * + * You should usually call [Builder.hasCustomRouting] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun hasCustomRouting(hasCustomRouting: JsonField) = apply { + this.hasCustomRouting = hasCustomRouting + } + + /** Default channels for the section. Defaults to empty if omitted. */ + fun routingOptions(routingOptions: List?) = + routingOptions(JsonField.ofNullable(routingOptions)) + + /** Alias for calling [Builder.routingOptions] with `routingOptions.orElse(null)`. */ + fun routingOptions(routingOptions: Optional>) = + routingOptions(routingOptions.getOrNull()) + + /** + * Sets [Builder.routingOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.routingOptions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun routingOptions(routingOptions: JsonField>) = apply { + this.routingOptions = routingOptions.map { it.toMutableList() } + } + + /** + * Adds a single [ChannelClassification] to [routingOptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRoutingOption(routingOption: ChannelClassification) = apply { + routingOptions = + (routingOptions ?: JsonField.of(mutableListOf())).also { + checkKnown("routingOptions", it).add(routingOption) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PreferenceSectionCreateRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceSectionCreateRequest = + PreferenceSectionCreateRequest( + checkRequired("name", name), + hasCustomRouting, + (routingOptions ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreferenceSectionCreateRequest = apply { + if (validated) { + return@apply + } + + name() + hasCustomRouting() + routingOptions().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (hasCustomRouting.asKnown().isPresent) 1 else 0) + + (routingOptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionCreateRequest && + name == other.name && + hasCustomRouting == other.hasCustomRouting && + routingOptions == other.routingOptions && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(name, hasCustomRouting, routingOptions, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreferenceSectionCreateRequest{name=$name, hasCustomRouting=$hasCustomRouting, routingOptions=$routingOptions, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionGetResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionGetResponse.kt new file mode 100644 index 0000000..2b200ea --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionGetResponse.kt @@ -0,0 +1,553 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A preference section in your workspace, including its topics. */ +class PreferenceSectionGetResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val created: JsonField, + private val hasCustomRouting: JsonField, + private val name: JsonField, + private val routingOptions: JsonField>, + private val topics: JsonField>, + private val creator: JsonField, + private val updated: JsonField, + private val updater: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created") @ExcludeMissing created: JsonField = JsonMissing.of(), + @JsonProperty("has_custom_routing") + @ExcludeMissing + hasCustomRouting: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("routing_options") + @ExcludeMissing + routingOptions: JsonField> = JsonMissing.of(), + @JsonProperty("topics") + @ExcludeMissing + topics: JsonField> = JsonMissing.of(), + @JsonProperty("creator") @ExcludeMissing creator: JsonField = JsonMissing.of(), + @JsonProperty("updated") @ExcludeMissing updated: JsonField = JsonMissing.of(), + @JsonProperty("updater") @ExcludeMissing updater: JsonField = JsonMissing.of(), + ) : this( + id, + created, + hasCustomRouting, + name, + routingOptions, + topics, + creator, + updated, + updater, + mutableMapOf(), + ) + + /** + * The preference section id. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * ISO-8601 timestamp of when the section was created. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun created(): String = created.getRequired("created") + + /** + * Whether the section defines custom routing for its topics. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun hasCustomRouting(): Boolean = hasCustomRouting.getRequired("has_custom_routing") + + /** + * Human-readable name. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Default channels for the section. May be empty. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun routingOptions(): List = + routingOptions.getRequired("routing_options") + + /** + * The topics contained in this section. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun topics(): List = topics.getRequired("topics") + + /** + * Id of the creator. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun creator(): Optional = creator.getOptional("creator") + + /** + * ISO-8601 timestamp of the last update. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updated(): Optional = updated.getOptional("updated") + + /** + * Id of the last updater. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updater(): Optional = updater.getOptional("updater") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [created]. + * + * Unlike [created], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created") @ExcludeMissing fun _created(): JsonField = created + + /** + * Returns the raw JSON value of [hasCustomRouting]. + * + * Unlike [hasCustomRouting], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("has_custom_routing") + @ExcludeMissing + fun _hasCustomRouting(): JsonField = hasCustomRouting + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [routingOptions]. + * + * Unlike [routingOptions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing_options") + @ExcludeMissing + fun _routingOptions(): JsonField> = routingOptions + + /** + * Returns the raw JSON value of [topics]. + * + * Unlike [topics], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("topics") + @ExcludeMissing + fun _topics(): JsonField> = topics + + /** + * Returns the raw JSON value of [creator]. + * + * Unlike [creator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("creator") @ExcludeMissing fun _creator(): JsonField = creator + + /** + * Returns the raw JSON value of [updated]. + * + * Unlike [updated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated") @ExcludeMissing fun _updated(): JsonField = updated + + /** + * Returns the raw JSON value of [updater]. + * + * Unlike [updater], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updater") @ExcludeMissing fun _updater(): JsonField = updater + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PreferenceSectionGetResponse]. + * + * The following fields are required: + * ```java + * .id() + * .created() + * .hasCustomRouting() + * .name() + * .routingOptions() + * .topics() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionGetResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var created: JsonField? = null + private var hasCustomRouting: JsonField? = null + private var name: JsonField? = null + private var routingOptions: JsonField>? = null + private var topics: JsonField>? = null + private var creator: JsonField = JsonMissing.of() + private var updated: JsonField = JsonMissing.of() + private var updater: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceSectionGetResponse: PreferenceSectionGetResponse) = apply { + id = preferenceSectionGetResponse.id + created = preferenceSectionGetResponse.created + hasCustomRouting = preferenceSectionGetResponse.hasCustomRouting + name = preferenceSectionGetResponse.name + routingOptions = preferenceSectionGetResponse.routingOptions.map { it.toMutableList() } + topics = preferenceSectionGetResponse.topics.map { it.toMutableList() } + creator = preferenceSectionGetResponse.creator + updated = preferenceSectionGetResponse.updated + updater = preferenceSectionGetResponse.updater + additionalProperties = preferenceSectionGetResponse.additionalProperties.toMutableMap() + } + + /** The preference section id. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** ISO-8601 timestamp of when the section was created. */ + fun created(created: String) = created(JsonField.of(created)) + + /** + * Sets [Builder.created] to an arbitrary JSON value. + * + * You should usually call [Builder.created] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun created(created: JsonField) = apply { this.created = created } + + /** Whether the section defines custom routing for its topics. */ + fun hasCustomRouting(hasCustomRouting: Boolean) = + hasCustomRouting(JsonField.of(hasCustomRouting)) + + /** + * Sets [Builder.hasCustomRouting] to an arbitrary JSON value. + * + * You should usually call [Builder.hasCustomRouting] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun hasCustomRouting(hasCustomRouting: JsonField) = apply { + this.hasCustomRouting = hasCustomRouting + } + + /** Human-readable name. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Default channels for the section. May be empty. */ + fun routingOptions(routingOptions: List) = + routingOptions(JsonField.of(routingOptions)) + + /** + * Sets [Builder.routingOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.routingOptions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun routingOptions(routingOptions: JsonField>) = apply { + this.routingOptions = routingOptions.map { it.toMutableList() } + } + + /** + * Adds a single [ChannelClassification] to [routingOptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRoutingOption(routingOption: ChannelClassification) = apply { + routingOptions = + (routingOptions ?: JsonField.of(mutableListOf())).also { + checkKnown("routingOptions", it).add(routingOption) + } + } + + /** The topics contained in this section. */ + fun topics(topics: List) = topics(JsonField.of(topics)) + + /** + * Sets [Builder.topics] to an arbitrary JSON value. + * + * You should usually call [Builder.topics] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun topics(topics: JsonField>) = apply { + this.topics = topics.map { it.toMutableList() } + } + + /** + * Adds a single [PreferenceTopicGetResponse] to [topics]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTopic(topic: PreferenceTopicGetResponse) = apply { + topics = + (topics ?: JsonField.of(mutableListOf())).also { + checkKnown("topics", it).add(topic) + } + } + + /** Id of the creator. */ + fun creator(creator: String?) = creator(JsonField.ofNullable(creator)) + + /** Alias for calling [Builder.creator] with `creator.orElse(null)`. */ + fun creator(creator: Optional) = creator(creator.getOrNull()) + + /** + * Sets [Builder.creator] to an arbitrary JSON value. + * + * You should usually call [Builder.creator] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun creator(creator: JsonField) = apply { this.creator = creator } + + /** ISO-8601 timestamp of the last update. */ + fun updated(updated: String?) = updated(JsonField.ofNullable(updated)) + + /** Alias for calling [Builder.updated] with `updated.orElse(null)`. */ + fun updated(updated: Optional) = updated(updated.getOrNull()) + + /** + * Sets [Builder.updated] to an arbitrary JSON value. + * + * You should usually call [Builder.updated] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun updated(updated: JsonField) = apply { this.updated = updated } + + /** Id of the last updater. */ + fun updater(updater: String?) = updater(JsonField.ofNullable(updater)) + + /** Alias for calling [Builder.updater] with `updater.orElse(null)`. */ + fun updater(updater: Optional) = updater(updater.getOrNull()) + + /** + * Sets [Builder.updater] to an arbitrary JSON value. + * + * You should usually call [Builder.updater] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun updater(updater: JsonField) = apply { this.updater = updater } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PreferenceSectionGetResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .created() + * .hasCustomRouting() + * .name() + * .routingOptions() + * .topics() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceSectionGetResponse = + PreferenceSectionGetResponse( + checkRequired("id", id), + checkRequired("created", created), + checkRequired("hasCustomRouting", hasCustomRouting), + checkRequired("name", name), + checkRequired("routingOptions", routingOptions).map { it.toImmutable() }, + checkRequired("topics", topics).map { it.toImmutable() }, + creator, + updated, + updater, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreferenceSectionGetResponse = apply { + if (validated) { + return@apply + } + + id() + created() + hasCustomRouting() + name() + routingOptions().forEach { it.validate() } + topics().forEach { it.validate() } + creator() + updated() + updater() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (hasCustomRouting.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (routingOptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (topics.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (creator.asKnown().isPresent) 1 else 0) + + (if (updated.asKnown().isPresent) 1 else 0) + + (if (updater.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionGetResponse && + id == other.id && + created == other.created && + hasCustomRouting == other.hasCustomRouting && + name == other.name && + routingOptions == other.routingOptions && + topics == other.topics && + creator == other.creator && + updated == other.updated && + updater == other.updater && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + created, + hasCustomRouting, + name, + routingOptions, + topics, + creator, + updated, + updater, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreferenceSectionGetResponse{id=$id, created=$created, hasCustomRouting=$hasCustomRouting, name=$name, routingOptions=$routingOptions, topics=$topics, creator=$creator, updated=$updated, updater=$updater, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionListParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionListParams.kt new file mode 100644 index 0000000..a6117e0 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionListParams.kt @@ -0,0 +1,175 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects + +/** + * List the workspace's preference sections. Each section embeds its topics. Scoped to the workspace + * of the API key. + */ +class PreferenceSectionListParams +private constructor( + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): PreferenceSectionListParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [PreferenceSectionListParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionListParams]. */ + class Builder internal constructor() { + + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(preferenceSectionListParams: PreferenceSectionListParams) = apply { + additionalHeaders = preferenceSectionListParams.additionalHeaders.toBuilder() + additionalQueryParams = preferenceSectionListParams.additionalQueryParams.toBuilder() + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreferenceSectionListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PreferenceSectionListParams = + PreferenceSectionListParams(additionalHeaders.build(), additionalQueryParams.build()) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionListParams && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) + + override fun toString() = + "PreferenceSectionListParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionListResponse.kt new file mode 100644 index 0000000..3a73db2 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionListResponse.kt @@ -0,0 +1,204 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** The workspace's preference sections, each with its topics. */ +class PreferenceSectionListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val results: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of() + ) : this(results, mutableMapOf()) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun results(): List = results.getRequired("results") + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") + @ExcludeMissing + fun _results(): JsonField> = results + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceSectionListResponse]. + * + * The following fields are required: + * ```java + * .results() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionListResponse]. */ + class Builder internal constructor() { + + private var results: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceSectionListResponse: PreferenceSectionListResponse) = apply { + results = preferenceSectionListResponse.results.map { it.toMutableList() } + additionalProperties = preferenceSectionListResponse.additionalProperties.toMutableMap() + } + + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [PreferenceSectionGetResponse] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: PreferenceSectionGetResponse) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PreferenceSectionListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .results() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceSectionListResponse = + PreferenceSectionListResponse( + checkRequired("results", results).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreferenceSectionListResponse = apply { + if (validated) { + return@apply + } + + results().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionListResponse && + results == other.results && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(results, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreferenceSectionListResponse{results=$results, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionPublishParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionPublishParams.kt new file mode 100644 index 0000000..78f7c82 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionPublishParams.kt @@ -0,0 +1,218 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import com.courier.core.toImmutable +import java.util.Objects +import java.util.Optional + +/** + * Publish the workspace's preferences page. Takes a snapshot of every section with its topics under + * a new published version, making the current state visible on the hosted preferences page + * (non-draft). + */ +class PreferenceSectionPublishParams +private constructor( + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): PreferenceSectionPublishParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceSectionPublishParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionPublishParams]. */ + class Builder internal constructor() { + + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceSectionPublishParams: PreferenceSectionPublishParams) = apply { + additionalHeaders = preferenceSectionPublishParams.additionalHeaders.toBuilder() + additionalQueryParams = preferenceSectionPublishParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + preferenceSectionPublishParams.additionalBodyProperties.toMutableMap() + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [PreferenceSectionPublishParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PreferenceSectionPublishParams = + PreferenceSectionPublishParams( + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionPublishParams && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "PreferenceSectionPublishParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceParams.kt new file mode 100644 index 0000000..77d4d0f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceParams.kt @@ -0,0 +1,243 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Replace a preference section. Full document replacement; missing optional fields are cleared. + * Topics attached to the section are unaffected. + */ +class PreferenceSectionReplaceParams +private constructor( + private val sectionId: String?, + private val preferenceSectionReplaceRequest: PreferenceSectionReplaceRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sectionId(): Optional = Optional.ofNullable(sectionId) + + /** + * Request body for replacing a preference section. Full document replacement; missing optional + * fields are cleared. + */ + fun preferenceSectionReplaceRequest(): PreferenceSectionReplaceRequest = + preferenceSectionReplaceRequest + + fun _additionalBodyProperties(): Map = + preferenceSectionReplaceRequest._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceSectionReplaceParams]. + * + * The following fields are required: + * ```java + * .preferenceSectionReplaceRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionReplaceParams]. */ + class Builder internal constructor() { + + private var sectionId: String? = null + private var preferenceSectionReplaceRequest: PreferenceSectionReplaceRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(preferenceSectionReplaceParams: PreferenceSectionReplaceParams) = apply { + sectionId = preferenceSectionReplaceParams.sectionId + preferenceSectionReplaceRequest = + preferenceSectionReplaceParams.preferenceSectionReplaceRequest + additionalHeaders = preferenceSectionReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = preferenceSectionReplaceParams.additionalQueryParams.toBuilder() + } + + fun sectionId(sectionId: String?) = apply { this.sectionId = sectionId } + + /** Alias for calling [Builder.sectionId] with `sectionId.orElse(null)`. */ + fun sectionId(sectionId: Optional) = sectionId(sectionId.getOrNull()) + + /** + * Request body for replacing a preference section. Full document replacement; missing + * optional fields are cleared. + */ + fun preferenceSectionReplaceRequest( + preferenceSectionReplaceRequest: PreferenceSectionReplaceRequest + ) = apply { this.preferenceSectionReplaceRequest = preferenceSectionReplaceRequest } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreferenceSectionReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .preferenceSectionReplaceRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceSectionReplaceParams = + PreferenceSectionReplaceParams( + sectionId, + checkRequired("preferenceSectionReplaceRequest", preferenceSectionReplaceRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): PreferenceSectionReplaceRequest = preferenceSectionReplaceRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sectionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionReplaceParams && + sectionId == other.sectionId && + preferenceSectionReplaceRequest == other.preferenceSectionReplaceRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + sectionId, + preferenceSectionReplaceRequest, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "PreferenceSectionReplaceParams{sectionId=$sectionId, preferenceSectionReplaceRequest=$preferenceSectionReplaceRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceRequest.kt new file mode 100644 index 0000000..5dd8264 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceRequest.kt @@ -0,0 +1,312 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Request body for replacing a preference section. Full document replacement; missing optional + * fields are cleared. + */ +class PreferenceSectionReplaceRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val name: JsonField, + private val hasCustomRouting: JsonField, + private val routingOptions: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("has_custom_routing") + @ExcludeMissing + hasCustomRouting: JsonField = JsonMissing.of(), + @JsonProperty("routing_options") + @ExcludeMissing + routingOptions: JsonField> = JsonMissing.of(), + ) : this(name, hasCustomRouting, routingOptions, mutableMapOf()) + + /** + * Human-readable name for the section. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Whether the section defines custom routing for its topics. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun hasCustomRouting(): Optional = hasCustomRouting.getOptional("has_custom_routing") + + /** + * Default channels for the section. Omit to clear. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun routingOptions(): Optional> = + routingOptions.getOptional("routing_options") + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [hasCustomRouting]. + * + * Unlike [hasCustomRouting], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("has_custom_routing") + @ExcludeMissing + fun _hasCustomRouting(): JsonField = hasCustomRouting + + /** + * Returns the raw JSON value of [routingOptions]. + * + * Unlike [routingOptions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing_options") + @ExcludeMissing + fun _routingOptions(): JsonField> = routingOptions + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceSectionReplaceRequest]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionReplaceRequest]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var hasCustomRouting: JsonField = JsonMissing.of() + private var routingOptions: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceSectionReplaceRequest: PreferenceSectionReplaceRequest) = + apply { + name = preferenceSectionReplaceRequest.name + hasCustomRouting = preferenceSectionReplaceRequest.hasCustomRouting + routingOptions = + preferenceSectionReplaceRequest.routingOptions.map { it.toMutableList() } + additionalProperties = + preferenceSectionReplaceRequest.additionalProperties.toMutableMap() + } + + /** Human-readable name for the section. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Whether the section defines custom routing for its topics. */ + fun hasCustomRouting(hasCustomRouting: Boolean?) = + hasCustomRouting(JsonField.ofNullable(hasCustomRouting)) + + /** + * Alias for [Builder.hasCustomRouting]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun hasCustomRouting(hasCustomRouting: Boolean) = + hasCustomRouting(hasCustomRouting as Boolean?) + + /** Alias for calling [Builder.hasCustomRouting] with `hasCustomRouting.orElse(null)`. */ + fun hasCustomRouting(hasCustomRouting: Optional) = + hasCustomRouting(hasCustomRouting.getOrNull()) + + /** + * Sets [Builder.hasCustomRouting] to an arbitrary JSON value. + * + * You should usually call [Builder.hasCustomRouting] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun hasCustomRouting(hasCustomRouting: JsonField) = apply { + this.hasCustomRouting = hasCustomRouting + } + + /** Default channels for the section. Omit to clear. */ + fun routingOptions(routingOptions: List?) = + routingOptions(JsonField.ofNullable(routingOptions)) + + /** Alias for calling [Builder.routingOptions] with `routingOptions.orElse(null)`. */ + fun routingOptions(routingOptions: Optional>) = + routingOptions(routingOptions.getOrNull()) + + /** + * Sets [Builder.routingOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.routingOptions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun routingOptions(routingOptions: JsonField>) = apply { + this.routingOptions = routingOptions.map { it.toMutableList() } + } + + /** + * Adds a single [ChannelClassification] to [routingOptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRoutingOption(routingOption: ChannelClassification) = apply { + routingOptions = + (routingOptions ?: JsonField.of(mutableListOf())).also { + checkKnown("routingOptions", it).add(routingOption) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PreferenceSectionReplaceRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceSectionReplaceRequest = + PreferenceSectionReplaceRequest( + checkRequired("name", name), + hasCustomRouting, + (routingOptions ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreferenceSectionReplaceRequest = apply { + if (validated) { + return@apply + } + + name() + hasCustomRouting() + routingOptions().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (hasCustomRouting.asKnown().isPresent) 1 else 0) + + (routingOptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionReplaceRequest && + name == other.name && + hasCustomRouting == other.hasCustomRouting && + routingOptions == other.routingOptions && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(name, hasCustomRouting, routingOptions, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreferenceSectionReplaceRequest{name=$name, hasCustomRouting=$hasCustomRouting, routingOptions=$routingOptions, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionRetrieveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionRetrieveParams.kt new file mode 100644 index 0000000..7f9504d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceSectionRetrieveParams.kt @@ -0,0 +1,198 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieve a preference section by id, including its topics. */ +class PreferenceSectionRetrieveParams +private constructor( + private val sectionId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sectionId(): Optional = Optional.ofNullable(sectionId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): PreferenceSectionRetrieveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceSectionRetrieveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceSectionRetrieveParams]. */ + class Builder internal constructor() { + + private var sectionId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(preferenceSectionRetrieveParams: PreferenceSectionRetrieveParams) = + apply { + sectionId = preferenceSectionRetrieveParams.sectionId + additionalHeaders = preferenceSectionRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + preferenceSectionRetrieveParams.additionalQueryParams.toBuilder() + } + + fun sectionId(sectionId: String?) = apply { this.sectionId = sectionId } + + /** Alias for calling [Builder.sectionId] with `sectionId.orElse(null)`. */ + fun sectionId(sectionId: Optional) = sectionId(sectionId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreferenceSectionRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PreferenceSectionRetrieveParams = + PreferenceSectionRetrieveParams( + sectionId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sectionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceSectionRetrieveParams && + sectionId == other.sectionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(sectionId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "PreferenceSectionRetrieveParams{sectionId=$sectionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicCreateRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicCreateRequest.kt new file mode 100644 index 0000000..a76bd6b --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicCreateRequest.kt @@ -0,0 +1,868 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.Enum +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Request body for creating a preference topic. */ +class PreferenceTopicCreateRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val defaultStatus: JsonField, + private val name: JsonField, + private val allowedPreferences: JsonField>, + private val includeUnsubscribeHeader: JsonField, + private val routingOptions: JsonField>, + private val topicData: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("default_status") + @ExcludeMissing + defaultStatus: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("allowed_preferences") + @ExcludeMissing + allowedPreferences: JsonField> = JsonMissing.of(), + @JsonProperty("include_unsubscribe_header") + @ExcludeMissing + includeUnsubscribeHeader: JsonField = JsonMissing.of(), + @JsonProperty("routing_options") + @ExcludeMissing + routingOptions: JsonField> = JsonMissing.of(), + @JsonProperty("topic_data") + @ExcludeMissing + topicData: JsonField = JsonMissing.of(), + ) : this( + defaultStatus, + name, + allowedPreferences, + includeUnsubscribeHeader, + routingOptions, + topicData, + mutableMapOf(), + ) + + /** + * The default subscription status applied when a recipient has not set their own. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun defaultStatus(): DefaultStatus = defaultStatus.getRequired("default_status") + + /** + * Human-readable name for the preference topic. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Preference controls a recipient may customize for this topic. Defaults to empty if omitted. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedPreferences(): Optional> = + allowedPreferences.getOptional("allowed_preferences") + + /** + * Whether to include a list-unsubscribe header on emails for this topic. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun includeUnsubscribeHeader(): Optional = + includeUnsubscribeHeader.getOptional("include_unsubscribe_header") + + /** + * Default channels delivered for this topic. Defaults to empty if omitted. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun routingOptions(): Optional> = + routingOptions.getOptional("routing_options") + + /** + * Arbitrary metadata associated with the topic. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun topicData(): Optional = topicData.getOptional("topic_data") + + /** + * Returns the raw JSON value of [defaultStatus]. + * + * Unlike [defaultStatus], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("default_status") + @ExcludeMissing + fun _defaultStatus(): JsonField = defaultStatus + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [allowedPreferences]. + * + * Unlike [allowedPreferences], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allowed_preferences") + @ExcludeMissing + fun _allowedPreferences(): JsonField> = allowedPreferences + + /** + * Returns the raw JSON value of [includeUnsubscribeHeader]. + * + * Unlike [includeUnsubscribeHeader], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("include_unsubscribe_header") + @ExcludeMissing + fun _includeUnsubscribeHeader(): JsonField = includeUnsubscribeHeader + + /** + * Returns the raw JSON value of [routingOptions]. + * + * Unlike [routingOptions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing_options") + @ExcludeMissing + fun _routingOptions(): JsonField> = routingOptions + + /** + * Returns the raw JSON value of [topicData]. + * + * Unlike [topicData], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("topic_data") @ExcludeMissing fun _topicData(): JsonField = topicData + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PreferenceTopicCreateRequest]. + * + * The following fields are required: + * ```java + * .defaultStatus() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceTopicCreateRequest]. */ + class Builder internal constructor() { + + private var defaultStatus: JsonField? = null + private var name: JsonField? = null + private var allowedPreferences: JsonField>? = null + private var includeUnsubscribeHeader: JsonField = JsonMissing.of() + private var routingOptions: JsonField>? = null + private var topicData: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceTopicCreateRequest: PreferenceTopicCreateRequest) = apply { + defaultStatus = preferenceTopicCreateRequest.defaultStatus + name = preferenceTopicCreateRequest.name + allowedPreferences = + preferenceTopicCreateRequest.allowedPreferences.map { it.toMutableList() } + includeUnsubscribeHeader = preferenceTopicCreateRequest.includeUnsubscribeHeader + routingOptions = preferenceTopicCreateRequest.routingOptions.map { it.toMutableList() } + topicData = preferenceTopicCreateRequest.topicData + additionalProperties = preferenceTopicCreateRequest.additionalProperties.toMutableMap() + } + + /** The default subscription status applied when a recipient has not set their own. */ + fun defaultStatus(defaultStatus: DefaultStatus) = defaultStatus(JsonField.of(defaultStatus)) + + /** + * Sets [Builder.defaultStatus] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultStatus] with a well-typed [DefaultStatus] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun defaultStatus(defaultStatus: JsonField) = apply { + this.defaultStatus = defaultStatus + } + + /** Human-readable name for the preference topic. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Preference controls a recipient may customize for this topic. Defaults to empty if + * omitted. + */ + fun allowedPreferences(allowedPreferences: List?) = + allowedPreferences(JsonField.ofNullable(allowedPreferences)) + + /** + * Alias for calling [Builder.allowedPreferences] with `allowedPreferences.orElse(null)`. + */ + fun allowedPreferences(allowedPreferences: Optional>) = + allowedPreferences(allowedPreferences.getOrNull()) + + /** + * Sets [Builder.allowedPreferences] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedPreferences] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun allowedPreferences(allowedPreferences: JsonField>) = apply { + this.allowedPreferences = allowedPreferences.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedPreference] to [allowedPreferences]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedPreference(allowedPreference: AllowedPreference) = apply { + allowedPreferences = + (allowedPreferences ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedPreferences", it).add(allowedPreference) + } + } + + /** Whether to include a list-unsubscribe header on emails for this topic. */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: Boolean?) = + includeUnsubscribeHeader(JsonField.ofNullable(includeUnsubscribeHeader)) + + /** + * Alias for [Builder.includeUnsubscribeHeader]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: Boolean) = + includeUnsubscribeHeader(includeUnsubscribeHeader as Boolean?) + + /** + * Alias for calling [Builder.includeUnsubscribeHeader] with + * `includeUnsubscribeHeader.orElse(null)`. + */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: Optional) = + includeUnsubscribeHeader(includeUnsubscribeHeader.getOrNull()) + + /** + * Sets [Builder.includeUnsubscribeHeader] to an arbitrary JSON value. + * + * You should usually call [Builder.includeUnsubscribeHeader] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: JsonField) = apply { + this.includeUnsubscribeHeader = includeUnsubscribeHeader + } + + /** Default channels delivered for this topic. Defaults to empty if omitted. */ + fun routingOptions(routingOptions: List?) = + routingOptions(JsonField.ofNullable(routingOptions)) + + /** Alias for calling [Builder.routingOptions] with `routingOptions.orElse(null)`. */ + fun routingOptions(routingOptions: Optional>) = + routingOptions(routingOptions.getOrNull()) + + /** + * Sets [Builder.routingOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.routingOptions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun routingOptions(routingOptions: JsonField>) = apply { + this.routingOptions = routingOptions.map { it.toMutableList() } + } + + /** + * Adds a single [ChannelClassification] to [routingOptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRoutingOption(routingOption: ChannelClassification) = apply { + routingOptions = + (routingOptions ?: JsonField.of(mutableListOf())).also { + checkKnown("routingOptions", it).add(routingOption) + } + } + + /** Arbitrary metadata associated with the topic. */ + fun topicData(topicData: TopicData?) = topicData(JsonField.ofNullable(topicData)) + + /** Alias for calling [Builder.topicData] with `topicData.orElse(null)`. */ + fun topicData(topicData: Optional) = topicData(topicData.getOrNull()) + + /** + * Sets [Builder.topicData] to an arbitrary JSON value. + * + * You should usually call [Builder.topicData] with a well-typed [TopicData] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun topicData(topicData: JsonField) = apply { this.topicData = topicData } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PreferenceTopicCreateRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .defaultStatus() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceTopicCreateRequest = + PreferenceTopicCreateRequest( + checkRequired("defaultStatus", defaultStatus), + checkRequired("name", name), + (allowedPreferences ?: JsonMissing.of()).map { it.toImmutable() }, + includeUnsubscribeHeader, + (routingOptions ?: JsonMissing.of()).map { it.toImmutable() }, + topicData, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreferenceTopicCreateRequest = apply { + if (validated) { + return@apply + } + + defaultStatus().validate() + name() + allowedPreferences().ifPresent { it.forEach { it.validate() } } + includeUnsubscribeHeader() + routingOptions().ifPresent { it.forEach { it.validate() } } + topicData().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (defaultStatus.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (allowedPreferences.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (includeUnsubscribeHeader.asKnown().isPresent) 1 else 0) + + (routingOptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (topicData.asKnown().getOrNull()?.validity() ?: 0) + + /** The default subscription status applied when a recipient has not set their own. */ + class DefaultStatus @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val OPTED_OUT = of("OPTED_OUT") + + @JvmField val OPTED_IN = of("OPTED_IN") + + @JvmField val REQUIRED = of("REQUIRED") + + @JvmStatic fun of(value: String) = DefaultStatus(JsonField.of(value)) + } + + /** An enum containing [DefaultStatus]'s known values. */ + enum class Known { + OPTED_OUT, + OPTED_IN, + REQUIRED, + } + + /** + * An enum containing [DefaultStatus]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [DefaultStatus] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + OPTED_OUT, + OPTED_IN, + REQUIRED, + /** + * An enum member indicating that [DefaultStatus] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + OPTED_OUT -> Value.OPTED_OUT + OPTED_IN -> Value.OPTED_IN + REQUIRED -> Value.REQUIRED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + OPTED_OUT -> Known.OPTED_OUT + OPTED_IN -> Known.OPTED_IN + REQUIRED -> Known.REQUIRED + else -> throw CourierInvalidDataException("Unknown DefaultStatus: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DefaultStatus = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DefaultStatus && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** A preference control a recipient may customize for a topic. */ + class AllowedPreference @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val SNOOZE = of("snooze") + + @JvmField val CHANNEL_PREFERENCES = of("channel_preferences") + + @JvmStatic fun of(value: String) = AllowedPreference(JsonField.of(value)) + } + + /** An enum containing [AllowedPreference]'s known values. */ + enum class Known { + SNOOZE, + CHANNEL_PREFERENCES, + } + + /** + * An enum containing [AllowedPreference]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedPreference] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + SNOOZE, + CHANNEL_PREFERENCES, + /** + * An enum member indicating that [AllowedPreference] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + SNOOZE -> Value.SNOOZE + CHANNEL_PREFERENCES -> Value.CHANNEL_PREFERENCES + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SNOOZE -> Known.SNOOZE + CHANNEL_PREFERENCES -> Known.CHANNEL_PREFERENCES + else -> throw CourierInvalidDataException("Unknown AllowedPreference: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AllowedPreference = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AllowedPreference && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Arbitrary metadata associated with the topic. */ + class TopicData + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [TopicData]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TopicData]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(topicData: TopicData) = apply { + additionalProperties = topicData.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TopicData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): TopicData = TopicData(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): TopicData = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TopicData && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "TopicData{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceTopicCreateRequest && + defaultStatus == other.defaultStatus && + name == other.name && + allowedPreferences == other.allowedPreferences && + includeUnsubscribeHeader == other.includeUnsubscribeHeader && + routingOptions == other.routingOptions && + topicData == other.topicData && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + defaultStatus, + name, + allowedPreferences, + includeUnsubscribeHeader, + routingOptions, + topicData, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreferenceTopicCreateRequest{defaultStatus=$defaultStatus, name=$name, allowedPreferences=$allowedPreferences, includeUnsubscribeHeader=$includeUnsubscribeHeader, routingOptions=$routingOptions, topicData=$topicData, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicGetResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicGetResponse.kt new file mode 100644 index 0000000..de27c6d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicGetResponse.kt @@ -0,0 +1,1037 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.Enum +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A subscription preference topic in your workspace. */ +class PreferenceTopicGetResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val allowedPreferences: JsonField>, + private val created: JsonField, + private val defaultStatus: JsonField, + private val includeUnsubscribeHeader: JsonField, + private val name: JsonField, + private val routingOptions: JsonField>, + private val topicData: JsonField, + private val updated: JsonField, + private val creator: JsonField, + private val updater: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("allowed_preferences") + @ExcludeMissing + allowedPreferences: JsonField> = JsonMissing.of(), + @JsonProperty("created") @ExcludeMissing created: JsonField = JsonMissing.of(), + @JsonProperty("default_status") + @ExcludeMissing + defaultStatus: JsonField = JsonMissing.of(), + @JsonProperty("include_unsubscribe_header") + @ExcludeMissing + includeUnsubscribeHeader: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("routing_options") + @ExcludeMissing + routingOptions: JsonField> = JsonMissing.of(), + @JsonProperty("topic_data") + @ExcludeMissing + topicData: JsonField = JsonMissing.of(), + @JsonProperty("updated") @ExcludeMissing updated: JsonField = JsonMissing.of(), + @JsonProperty("creator") @ExcludeMissing creator: JsonField = JsonMissing.of(), + @JsonProperty("updater") @ExcludeMissing updater: JsonField = JsonMissing.of(), + ) : this( + id, + allowedPreferences, + created, + defaultStatus, + includeUnsubscribeHeader, + name, + routingOptions, + topicData, + updated, + creator, + updater, + mutableMapOf(), + ) + + /** + * The preference topic id. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * Preference controls a recipient may customize. May be empty. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun allowedPreferences(): List = + allowedPreferences.getRequired("allowed_preferences") + + /** + * ISO-8601 timestamp of when the topic was created. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun created(): String = created.getRequired("created") + + /** + * The default subscription status applied when a recipient has not set their own. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun defaultStatus(): DefaultStatus = defaultStatus.getRequired("default_status") + + /** + * Whether a list-unsubscribe header is included on emails for this topic. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun includeUnsubscribeHeader(): Boolean = + includeUnsubscribeHeader.getRequired("include_unsubscribe_header") + + /** + * Human-readable name. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Default channels delivered for this topic. May be empty. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun routingOptions(): List = + routingOptions.getRequired("routing_options") + + /** + * Arbitrary metadata associated with the topic. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun topicData(): TopicData = topicData.getRequired("topic_data") + + /** + * ISO-8601 timestamp of the last update. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun updated(): String = updated.getRequired("updated") + + /** + * Id of the creator. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun creator(): Optional = creator.getOptional("creator") + + /** + * Id of the last updater. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updater(): Optional = updater.getOptional("updater") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [allowedPreferences]. + * + * Unlike [allowedPreferences], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allowed_preferences") + @ExcludeMissing + fun _allowedPreferences(): JsonField> = allowedPreferences + + /** + * Returns the raw JSON value of [created]. + * + * Unlike [created], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created") @ExcludeMissing fun _created(): JsonField = created + + /** + * Returns the raw JSON value of [defaultStatus]. + * + * Unlike [defaultStatus], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("default_status") + @ExcludeMissing + fun _defaultStatus(): JsonField = defaultStatus + + /** + * Returns the raw JSON value of [includeUnsubscribeHeader]. + * + * Unlike [includeUnsubscribeHeader], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("include_unsubscribe_header") + @ExcludeMissing + fun _includeUnsubscribeHeader(): JsonField = includeUnsubscribeHeader + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [routingOptions]. + * + * Unlike [routingOptions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing_options") + @ExcludeMissing + fun _routingOptions(): JsonField> = routingOptions + + /** + * Returns the raw JSON value of [topicData]. + * + * Unlike [topicData], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("topic_data") @ExcludeMissing fun _topicData(): JsonField = topicData + + /** + * Returns the raw JSON value of [updated]. + * + * Unlike [updated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated") @ExcludeMissing fun _updated(): JsonField = updated + + /** + * Returns the raw JSON value of [creator]. + * + * Unlike [creator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("creator") @ExcludeMissing fun _creator(): JsonField = creator + + /** + * Returns the raw JSON value of [updater]. + * + * Unlike [updater], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updater") @ExcludeMissing fun _updater(): JsonField = updater + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PreferenceTopicGetResponse]. + * + * The following fields are required: + * ```java + * .id() + * .allowedPreferences() + * .created() + * .defaultStatus() + * .includeUnsubscribeHeader() + * .name() + * .routingOptions() + * .topicData() + * .updated() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceTopicGetResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var allowedPreferences: JsonField>? = null + private var created: JsonField? = null + private var defaultStatus: JsonField? = null + private var includeUnsubscribeHeader: JsonField? = null + private var name: JsonField? = null + private var routingOptions: JsonField>? = null + private var topicData: JsonField? = null + private var updated: JsonField? = null + private var creator: JsonField = JsonMissing.of() + private var updater: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceTopicGetResponse: PreferenceTopicGetResponse) = apply { + id = preferenceTopicGetResponse.id + allowedPreferences = + preferenceTopicGetResponse.allowedPreferences.map { it.toMutableList() } + created = preferenceTopicGetResponse.created + defaultStatus = preferenceTopicGetResponse.defaultStatus + includeUnsubscribeHeader = preferenceTopicGetResponse.includeUnsubscribeHeader + name = preferenceTopicGetResponse.name + routingOptions = preferenceTopicGetResponse.routingOptions.map { it.toMutableList() } + topicData = preferenceTopicGetResponse.topicData + updated = preferenceTopicGetResponse.updated + creator = preferenceTopicGetResponse.creator + updater = preferenceTopicGetResponse.updater + additionalProperties = preferenceTopicGetResponse.additionalProperties.toMutableMap() + } + + /** The preference topic id. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Preference controls a recipient may customize. May be empty. */ + fun allowedPreferences(allowedPreferences: List) = + allowedPreferences(JsonField.of(allowedPreferences)) + + /** + * Sets [Builder.allowedPreferences] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedPreferences] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun allowedPreferences(allowedPreferences: JsonField>) = apply { + this.allowedPreferences = allowedPreferences.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedPreference] to [allowedPreferences]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedPreference(allowedPreference: AllowedPreference) = apply { + allowedPreferences = + (allowedPreferences ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedPreferences", it).add(allowedPreference) + } + } + + /** ISO-8601 timestamp of when the topic was created. */ + fun created(created: String) = created(JsonField.of(created)) + + /** + * Sets [Builder.created] to an arbitrary JSON value. + * + * You should usually call [Builder.created] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun created(created: JsonField) = apply { this.created = created } + + /** The default subscription status applied when a recipient has not set their own. */ + fun defaultStatus(defaultStatus: DefaultStatus) = defaultStatus(JsonField.of(defaultStatus)) + + /** + * Sets [Builder.defaultStatus] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultStatus] with a well-typed [DefaultStatus] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun defaultStatus(defaultStatus: JsonField) = apply { + this.defaultStatus = defaultStatus + } + + /** Whether a list-unsubscribe header is included on emails for this topic. */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: Boolean) = + includeUnsubscribeHeader(JsonField.of(includeUnsubscribeHeader)) + + /** + * Sets [Builder.includeUnsubscribeHeader] to an arbitrary JSON value. + * + * You should usually call [Builder.includeUnsubscribeHeader] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: JsonField) = apply { + this.includeUnsubscribeHeader = includeUnsubscribeHeader + } + + /** Human-readable name. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Default channels delivered for this topic. May be empty. */ + fun routingOptions(routingOptions: List) = + routingOptions(JsonField.of(routingOptions)) + + /** + * Sets [Builder.routingOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.routingOptions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun routingOptions(routingOptions: JsonField>) = apply { + this.routingOptions = routingOptions.map { it.toMutableList() } + } + + /** + * Adds a single [ChannelClassification] to [routingOptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRoutingOption(routingOption: ChannelClassification) = apply { + routingOptions = + (routingOptions ?: JsonField.of(mutableListOf())).also { + checkKnown("routingOptions", it).add(routingOption) + } + } + + /** Arbitrary metadata associated with the topic. */ + fun topicData(topicData: TopicData) = topicData(JsonField.of(topicData)) + + /** + * Sets [Builder.topicData] to an arbitrary JSON value. + * + * You should usually call [Builder.topicData] with a well-typed [TopicData] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun topicData(topicData: JsonField) = apply { this.topicData = topicData } + + /** ISO-8601 timestamp of the last update. */ + fun updated(updated: String) = updated(JsonField.of(updated)) + + /** + * Sets [Builder.updated] to an arbitrary JSON value. + * + * You should usually call [Builder.updated] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun updated(updated: JsonField) = apply { this.updated = updated } + + /** Id of the creator. */ + fun creator(creator: String?) = creator(JsonField.ofNullable(creator)) + + /** Alias for calling [Builder.creator] with `creator.orElse(null)`. */ + fun creator(creator: Optional) = creator(creator.getOrNull()) + + /** + * Sets [Builder.creator] to an arbitrary JSON value. + * + * You should usually call [Builder.creator] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun creator(creator: JsonField) = apply { this.creator = creator } + + /** Id of the last updater. */ + fun updater(updater: String?) = updater(JsonField.ofNullable(updater)) + + /** Alias for calling [Builder.updater] with `updater.orElse(null)`. */ + fun updater(updater: Optional) = updater(updater.getOrNull()) + + /** + * Sets [Builder.updater] to an arbitrary JSON value. + * + * You should usually call [Builder.updater] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun updater(updater: JsonField) = apply { this.updater = updater } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PreferenceTopicGetResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .allowedPreferences() + * .created() + * .defaultStatus() + * .includeUnsubscribeHeader() + * .name() + * .routingOptions() + * .topicData() + * .updated() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceTopicGetResponse = + PreferenceTopicGetResponse( + checkRequired("id", id), + checkRequired("allowedPreferences", allowedPreferences).map { it.toImmutable() }, + checkRequired("created", created), + checkRequired("defaultStatus", defaultStatus), + checkRequired("includeUnsubscribeHeader", includeUnsubscribeHeader), + checkRequired("name", name), + checkRequired("routingOptions", routingOptions).map { it.toImmutable() }, + checkRequired("topicData", topicData), + checkRequired("updated", updated), + creator, + updater, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreferenceTopicGetResponse = apply { + if (validated) { + return@apply + } + + id() + allowedPreferences().forEach { it.validate() } + created() + defaultStatus().validate() + includeUnsubscribeHeader() + name() + routingOptions().forEach { it.validate() } + topicData().validate() + updated() + creator() + updater() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (allowedPreferences.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (defaultStatus.asKnown().getOrNull()?.validity() ?: 0) + + (if (includeUnsubscribeHeader.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (routingOptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (topicData.asKnown().getOrNull()?.validity() ?: 0) + + (if (updated.asKnown().isPresent) 1 else 0) + + (if (creator.asKnown().isPresent) 1 else 0) + + (if (updater.asKnown().isPresent) 1 else 0) + + /** A preference control a recipient may customize for a topic. */ + class AllowedPreference @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val SNOOZE = of("snooze") + + @JvmField val CHANNEL_PREFERENCES = of("channel_preferences") + + @JvmStatic fun of(value: String) = AllowedPreference(JsonField.of(value)) + } + + /** An enum containing [AllowedPreference]'s known values. */ + enum class Known { + SNOOZE, + CHANNEL_PREFERENCES, + } + + /** + * An enum containing [AllowedPreference]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedPreference] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + SNOOZE, + CHANNEL_PREFERENCES, + /** + * An enum member indicating that [AllowedPreference] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + SNOOZE -> Value.SNOOZE + CHANNEL_PREFERENCES -> Value.CHANNEL_PREFERENCES + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SNOOZE -> Known.SNOOZE + CHANNEL_PREFERENCES -> Known.CHANNEL_PREFERENCES + else -> throw CourierInvalidDataException("Unknown AllowedPreference: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AllowedPreference = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AllowedPreference && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The default subscription status applied when a recipient has not set their own. */ + class DefaultStatus @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val OPTED_OUT = of("OPTED_OUT") + + @JvmField val OPTED_IN = of("OPTED_IN") + + @JvmField val REQUIRED = of("REQUIRED") + + @JvmStatic fun of(value: String) = DefaultStatus(JsonField.of(value)) + } + + /** An enum containing [DefaultStatus]'s known values. */ + enum class Known { + OPTED_OUT, + OPTED_IN, + REQUIRED, + } + + /** + * An enum containing [DefaultStatus]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [DefaultStatus] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + OPTED_OUT, + OPTED_IN, + REQUIRED, + /** + * An enum member indicating that [DefaultStatus] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + OPTED_OUT -> Value.OPTED_OUT + OPTED_IN -> Value.OPTED_IN + REQUIRED -> Value.REQUIRED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + OPTED_OUT -> Known.OPTED_OUT + OPTED_IN -> Known.OPTED_IN + REQUIRED -> Known.REQUIRED + else -> throw CourierInvalidDataException("Unknown DefaultStatus: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DefaultStatus = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DefaultStatus && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Arbitrary metadata associated with the topic. */ + class TopicData + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [TopicData]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TopicData]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(topicData: TopicData) = apply { + additionalProperties = topicData.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TopicData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): TopicData = TopicData(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): TopicData = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TopicData && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "TopicData{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceTopicGetResponse && + id == other.id && + allowedPreferences == other.allowedPreferences && + created == other.created && + defaultStatus == other.defaultStatus && + includeUnsubscribeHeader == other.includeUnsubscribeHeader && + name == other.name && + routingOptions == other.routingOptions && + topicData == other.topicData && + updated == other.updated && + creator == other.creator && + updater == other.updater && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + allowedPreferences, + created, + defaultStatus, + includeUnsubscribeHeader, + name, + routingOptions, + topicData, + updated, + creator, + updater, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreferenceTopicGetResponse{id=$id, allowedPreferences=$allowedPreferences, created=$created, defaultStatus=$defaultStatus, includeUnsubscribeHeader=$includeUnsubscribeHeader, name=$name, routingOptions=$routingOptions, topicData=$topicData, updated=$updated, creator=$creator, updater=$updater, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicListResponse.kt new file mode 100644 index 0000000..b628a2b --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicListResponse.kt @@ -0,0 +1,203 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Topics contained in a preference section. */ +class PreferenceTopicListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val results: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of() + ) : this(results, mutableMapOf()) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun results(): List = results.getRequired("results") + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") + @ExcludeMissing + fun _results(): JsonField> = results + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PreferenceTopicListResponse]. + * + * The following fields are required: + * ```java + * .results() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceTopicListResponse]. */ + class Builder internal constructor() { + + private var results: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceTopicListResponse: PreferenceTopicListResponse) = apply { + results = preferenceTopicListResponse.results.map { it.toMutableList() } + additionalProperties = preferenceTopicListResponse.additionalProperties.toMutableMap() + } + + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [PreferenceTopicGetResponse] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: PreferenceTopicGetResponse) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PreferenceTopicListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .results() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceTopicListResponse = + PreferenceTopicListResponse( + checkRequired("results", results).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreferenceTopicListResponse = apply { + if (validated) { + return@apply + } + + results().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceTopicListResponse && + results == other.results && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(results, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreferenceTopicListResponse{results=$results, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicReplaceRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicReplaceRequest.kt new file mode 100644 index 0000000..0f4c49d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PreferenceTopicReplaceRequest.kt @@ -0,0 +1,869 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.Enum +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Request body for replacing a preference topic. Full document replacement; missing optional fields + * are cleared. + */ +class PreferenceTopicReplaceRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val defaultStatus: JsonField, + private val name: JsonField, + private val allowedPreferences: JsonField>, + private val includeUnsubscribeHeader: JsonField, + private val routingOptions: JsonField>, + private val topicData: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("default_status") + @ExcludeMissing + defaultStatus: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("allowed_preferences") + @ExcludeMissing + allowedPreferences: JsonField> = JsonMissing.of(), + @JsonProperty("include_unsubscribe_header") + @ExcludeMissing + includeUnsubscribeHeader: JsonField = JsonMissing.of(), + @JsonProperty("routing_options") + @ExcludeMissing + routingOptions: JsonField> = JsonMissing.of(), + @JsonProperty("topic_data") + @ExcludeMissing + topicData: JsonField = JsonMissing.of(), + ) : this( + defaultStatus, + name, + allowedPreferences, + includeUnsubscribeHeader, + routingOptions, + topicData, + mutableMapOf(), + ) + + /** + * The default subscription status applied when a recipient has not set their own. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun defaultStatus(): DefaultStatus = defaultStatus.getRequired("default_status") + + /** + * Human-readable name for the preference topic. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Preference controls a recipient may customize. Omit to clear. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedPreferences(): Optional> = + allowedPreferences.getOptional("allowed_preferences") + + /** + * Whether to include a list-unsubscribe header on emails for this topic. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun includeUnsubscribeHeader(): Optional = + includeUnsubscribeHeader.getOptional("include_unsubscribe_header") + + /** + * Default channels delivered for this topic. Omit to clear. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun routingOptions(): Optional> = + routingOptions.getOptional("routing_options") + + /** + * Arbitrary metadata associated with the topic. Omit to clear. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun topicData(): Optional = topicData.getOptional("topic_data") + + /** + * Returns the raw JSON value of [defaultStatus]. + * + * Unlike [defaultStatus], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("default_status") + @ExcludeMissing + fun _defaultStatus(): JsonField = defaultStatus + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [allowedPreferences]. + * + * Unlike [allowedPreferences], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allowed_preferences") + @ExcludeMissing + fun _allowedPreferences(): JsonField> = allowedPreferences + + /** + * Returns the raw JSON value of [includeUnsubscribeHeader]. + * + * Unlike [includeUnsubscribeHeader], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("include_unsubscribe_header") + @ExcludeMissing + fun _includeUnsubscribeHeader(): JsonField = includeUnsubscribeHeader + + /** + * Returns the raw JSON value of [routingOptions]. + * + * Unlike [routingOptions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing_options") + @ExcludeMissing + fun _routingOptions(): JsonField> = routingOptions + + /** + * Returns the raw JSON value of [topicData]. + * + * Unlike [topicData], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("topic_data") @ExcludeMissing fun _topicData(): JsonField = topicData + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [PreferenceTopicReplaceRequest]. + * + * The following fields are required: + * ```java + * .defaultStatus() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreferenceTopicReplaceRequest]. */ + class Builder internal constructor() { + + private var defaultStatus: JsonField? = null + private var name: JsonField? = null + private var allowedPreferences: JsonField>? = null + private var includeUnsubscribeHeader: JsonField = JsonMissing.of() + private var routingOptions: JsonField>? = null + private var topicData: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(preferenceTopicReplaceRequest: PreferenceTopicReplaceRequest) = apply { + defaultStatus = preferenceTopicReplaceRequest.defaultStatus + name = preferenceTopicReplaceRequest.name + allowedPreferences = + preferenceTopicReplaceRequest.allowedPreferences.map { it.toMutableList() } + includeUnsubscribeHeader = preferenceTopicReplaceRequest.includeUnsubscribeHeader + routingOptions = preferenceTopicReplaceRequest.routingOptions.map { it.toMutableList() } + topicData = preferenceTopicReplaceRequest.topicData + additionalProperties = preferenceTopicReplaceRequest.additionalProperties.toMutableMap() + } + + /** The default subscription status applied when a recipient has not set their own. */ + fun defaultStatus(defaultStatus: DefaultStatus) = defaultStatus(JsonField.of(defaultStatus)) + + /** + * Sets [Builder.defaultStatus] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultStatus] with a well-typed [DefaultStatus] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun defaultStatus(defaultStatus: JsonField) = apply { + this.defaultStatus = defaultStatus + } + + /** Human-readable name for the preference topic. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Preference controls a recipient may customize. Omit to clear. */ + fun allowedPreferences(allowedPreferences: List?) = + allowedPreferences(JsonField.ofNullable(allowedPreferences)) + + /** + * Alias for calling [Builder.allowedPreferences] with `allowedPreferences.orElse(null)`. + */ + fun allowedPreferences(allowedPreferences: Optional>) = + allowedPreferences(allowedPreferences.getOrNull()) + + /** + * Sets [Builder.allowedPreferences] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedPreferences] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun allowedPreferences(allowedPreferences: JsonField>) = apply { + this.allowedPreferences = allowedPreferences.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedPreference] to [allowedPreferences]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedPreference(allowedPreference: AllowedPreference) = apply { + allowedPreferences = + (allowedPreferences ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedPreferences", it).add(allowedPreference) + } + } + + /** Whether to include a list-unsubscribe header on emails for this topic. */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: Boolean?) = + includeUnsubscribeHeader(JsonField.ofNullable(includeUnsubscribeHeader)) + + /** + * Alias for [Builder.includeUnsubscribeHeader]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: Boolean) = + includeUnsubscribeHeader(includeUnsubscribeHeader as Boolean?) + + /** + * Alias for calling [Builder.includeUnsubscribeHeader] with + * `includeUnsubscribeHeader.orElse(null)`. + */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: Optional) = + includeUnsubscribeHeader(includeUnsubscribeHeader.getOrNull()) + + /** + * Sets [Builder.includeUnsubscribeHeader] to an arbitrary JSON value. + * + * You should usually call [Builder.includeUnsubscribeHeader] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun includeUnsubscribeHeader(includeUnsubscribeHeader: JsonField) = apply { + this.includeUnsubscribeHeader = includeUnsubscribeHeader + } + + /** Default channels delivered for this topic. Omit to clear. */ + fun routingOptions(routingOptions: List?) = + routingOptions(JsonField.ofNullable(routingOptions)) + + /** Alias for calling [Builder.routingOptions] with `routingOptions.orElse(null)`. */ + fun routingOptions(routingOptions: Optional>) = + routingOptions(routingOptions.getOrNull()) + + /** + * Sets [Builder.routingOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.routingOptions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun routingOptions(routingOptions: JsonField>) = apply { + this.routingOptions = routingOptions.map { it.toMutableList() } + } + + /** + * Adds a single [ChannelClassification] to [routingOptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRoutingOption(routingOption: ChannelClassification) = apply { + routingOptions = + (routingOptions ?: JsonField.of(mutableListOf())).also { + checkKnown("routingOptions", it).add(routingOption) + } + } + + /** Arbitrary metadata associated with the topic. Omit to clear. */ + fun topicData(topicData: TopicData?) = topicData(JsonField.ofNullable(topicData)) + + /** Alias for calling [Builder.topicData] with `topicData.orElse(null)`. */ + fun topicData(topicData: Optional) = topicData(topicData.getOrNull()) + + /** + * Sets [Builder.topicData] to an arbitrary JSON value. + * + * You should usually call [Builder.topicData] with a well-typed [TopicData] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun topicData(topicData: JsonField) = apply { this.topicData = topicData } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PreferenceTopicReplaceRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .defaultStatus() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreferenceTopicReplaceRequest = + PreferenceTopicReplaceRequest( + checkRequired("defaultStatus", defaultStatus), + checkRequired("name", name), + (allowedPreferences ?: JsonMissing.of()).map { it.toImmutable() }, + includeUnsubscribeHeader, + (routingOptions ?: JsonMissing.of()).map { it.toImmutable() }, + topicData, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreferenceTopicReplaceRequest = apply { + if (validated) { + return@apply + } + + defaultStatus().validate() + name() + allowedPreferences().ifPresent { it.forEach { it.validate() } } + includeUnsubscribeHeader() + routingOptions().ifPresent { it.forEach { it.validate() } } + topicData().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (defaultStatus.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (allowedPreferences.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (includeUnsubscribeHeader.asKnown().isPresent) 1 else 0) + + (routingOptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (topicData.asKnown().getOrNull()?.validity() ?: 0) + + /** The default subscription status applied when a recipient has not set their own. */ + class DefaultStatus @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val OPTED_OUT = of("OPTED_OUT") + + @JvmField val OPTED_IN = of("OPTED_IN") + + @JvmField val REQUIRED = of("REQUIRED") + + @JvmStatic fun of(value: String) = DefaultStatus(JsonField.of(value)) + } + + /** An enum containing [DefaultStatus]'s known values. */ + enum class Known { + OPTED_OUT, + OPTED_IN, + REQUIRED, + } + + /** + * An enum containing [DefaultStatus]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [DefaultStatus] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + OPTED_OUT, + OPTED_IN, + REQUIRED, + /** + * An enum member indicating that [DefaultStatus] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + OPTED_OUT -> Value.OPTED_OUT + OPTED_IN -> Value.OPTED_IN + REQUIRED -> Value.REQUIRED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + OPTED_OUT -> Known.OPTED_OUT + OPTED_IN -> Known.OPTED_IN + REQUIRED -> Known.REQUIRED + else -> throw CourierInvalidDataException("Unknown DefaultStatus: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DefaultStatus = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DefaultStatus && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** A preference control a recipient may customize for a topic. */ + class AllowedPreference @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val SNOOZE = of("snooze") + + @JvmField val CHANNEL_PREFERENCES = of("channel_preferences") + + @JvmStatic fun of(value: String) = AllowedPreference(JsonField.of(value)) + } + + /** An enum containing [AllowedPreference]'s known values. */ + enum class Known { + SNOOZE, + CHANNEL_PREFERENCES, + } + + /** + * An enum containing [AllowedPreference]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedPreference] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + SNOOZE, + CHANNEL_PREFERENCES, + /** + * An enum member indicating that [AllowedPreference] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + SNOOZE -> Value.SNOOZE + CHANNEL_PREFERENCES -> Value.CHANNEL_PREFERENCES + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SNOOZE -> Known.SNOOZE + CHANNEL_PREFERENCES -> Known.CHANNEL_PREFERENCES + else -> throw CourierInvalidDataException("Unknown AllowedPreference: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AllowedPreference = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AllowedPreference && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Arbitrary metadata associated with the topic. Omit to clear. */ + class TopicData + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [TopicData]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TopicData]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(topicData: TopicData) = apply { + additionalProperties = topicData.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TopicData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): TopicData = TopicData(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): TopicData = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TopicData && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "TopicData{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreferenceTopicReplaceRequest && + defaultStatus == other.defaultStatus && + name == other.name && + allowedPreferences == other.allowedPreferences && + includeUnsubscribeHeader == other.includeUnsubscribeHeader && + routingOptions == other.routingOptions && + topicData == other.topicData && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + defaultStatus, + name, + allowedPreferences, + includeUnsubscribeHeader, + routingOptions, + topicData, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreferenceTopicReplaceRequest{defaultStatus=$defaultStatus, name=$name, allowedPreferences=$allowedPreferences, includeUnsubscribeHeader=$includeUnsubscribeHeader, routingOptions=$routingOptions, topicData=$topicData, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PublishPreferencesResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PublishPreferencesResponse.kt new file mode 100644 index 0000000..780a0ea --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/PublishPreferencesResponse.kt @@ -0,0 +1,363 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkRequired +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Result of publishing the workspace's preferences page. */ +class PublishPreferencesResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val pageId: JsonField, + private val publishedAt: JsonField, + private val publishedVersion: JsonField, + private val previewUrl: JsonField, + private val publishedBy: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("page_id") @ExcludeMissing pageId: JsonField = JsonMissing.of(), + @JsonProperty("published_at") + @ExcludeMissing + publishedAt: JsonField = JsonMissing.of(), + @JsonProperty("published_version") + @ExcludeMissing + publishedVersion: JsonField = JsonMissing.of(), + @JsonProperty("preview_url") + @ExcludeMissing + previewUrl: JsonField = JsonMissing.of(), + @JsonProperty("published_by") + @ExcludeMissing + publishedBy: JsonField = JsonMissing.of(), + ) : this(pageId, publishedAt, publishedVersion, previewUrl, publishedBy, mutableMapOf()) + + /** + * Id of the published page snapshot. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun pageId(): String = pageId.getRequired("page_id") + + /** + * ISO-8601 timestamp of the publish. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun publishedAt(): String = publishedAt.getRequired("published_at") + + /** + * Monotonic published version (epoch milliseconds). + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun publishedVersion(): Double = publishedVersion.getRequired("published_version") + + /** + * Draft-mode hosted preferences page URL for previewing. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun previewUrl(): Optional = previewUrl.getOptional("preview_url") + + /** + * Id of the publisher. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun publishedBy(): Optional = publishedBy.getOptional("published_by") + + /** + * Returns the raw JSON value of [pageId]. + * + * Unlike [pageId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_id") @ExcludeMissing fun _pageId(): JsonField = pageId + + /** + * Returns the raw JSON value of [publishedAt]. + * + * Unlike [publishedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("published_at") + @ExcludeMissing + fun _publishedAt(): JsonField = publishedAt + + /** + * Returns the raw JSON value of [publishedVersion]. + * + * Unlike [publishedVersion], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("published_version") + @ExcludeMissing + fun _publishedVersion(): JsonField = publishedVersion + + /** + * Returns the raw JSON value of [previewUrl]. + * + * Unlike [previewUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("preview_url") @ExcludeMissing fun _previewUrl(): JsonField = previewUrl + + /** + * Returns the raw JSON value of [publishedBy]. + * + * Unlike [publishedBy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("published_by") + @ExcludeMissing + fun _publishedBy(): JsonField = publishedBy + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PublishPreferencesResponse]. + * + * The following fields are required: + * ```java + * .pageId() + * .publishedAt() + * .publishedVersion() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PublishPreferencesResponse]. */ + class Builder internal constructor() { + + private var pageId: JsonField? = null + private var publishedAt: JsonField? = null + private var publishedVersion: JsonField? = null + private var previewUrl: JsonField = JsonMissing.of() + private var publishedBy: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(publishPreferencesResponse: PublishPreferencesResponse) = apply { + pageId = publishPreferencesResponse.pageId + publishedAt = publishPreferencesResponse.publishedAt + publishedVersion = publishPreferencesResponse.publishedVersion + previewUrl = publishPreferencesResponse.previewUrl + publishedBy = publishPreferencesResponse.publishedBy + additionalProperties = publishPreferencesResponse.additionalProperties.toMutableMap() + } + + /** Id of the published page snapshot. */ + fun pageId(pageId: String) = pageId(JsonField.of(pageId)) + + /** + * Sets [Builder.pageId] to an arbitrary JSON value. + * + * You should usually call [Builder.pageId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun pageId(pageId: JsonField) = apply { this.pageId = pageId } + + /** ISO-8601 timestamp of the publish. */ + fun publishedAt(publishedAt: String) = publishedAt(JsonField.of(publishedAt)) + + /** + * Sets [Builder.publishedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.publishedAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun publishedAt(publishedAt: JsonField) = apply { this.publishedAt = publishedAt } + + /** Monotonic published version (epoch milliseconds). */ + fun publishedVersion(publishedVersion: Double) = + publishedVersion(JsonField.of(publishedVersion)) + + /** + * Sets [Builder.publishedVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.publishedVersion] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun publishedVersion(publishedVersion: JsonField) = apply { + this.publishedVersion = publishedVersion + } + + /** Draft-mode hosted preferences page URL for previewing. */ + fun previewUrl(previewUrl: String?) = previewUrl(JsonField.ofNullable(previewUrl)) + + /** Alias for calling [Builder.previewUrl] with `previewUrl.orElse(null)`. */ + fun previewUrl(previewUrl: Optional) = previewUrl(previewUrl.getOrNull()) + + /** + * Sets [Builder.previewUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.previewUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun previewUrl(previewUrl: JsonField) = apply { this.previewUrl = previewUrl } + + /** Id of the publisher. */ + fun publishedBy(publishedBy: String?) = publishedBy(JsonField.ofNullable(publishedBy)) + + /** Alias for calling [Builder.publishedBy] with `publishedBy.orElse(null)`. */ + fun publishedBy(publishedBy: Optional) = publishedBy(publishedBy.getOrNull()) + + /** + * Sets [Builder.publishedBy] to an arbitrary JSON value. + * + * You should usually call [Builder.publishedBy] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun publishedBy(publishedBy: JsonField) = apply { this.publishedBy = publishedBy } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PublishPreferencesResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .pageId() + * .publishedAt() + * .publishedVersion() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PublishPreferencesResponse = + PublishPreferencesResponse( + checkRequired("pageId", pageId), + checkRequired("publishedAt", publishedAt), + checkRequired("publishedVersion", publishedVersion), + previewUrl, + publishedBy, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PublishPreferencesResponse = apply { + if (validated) { + return@apply + } + + pageId() + publishedAt() + publishedVersion() + previewUrl() + publishedBy() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (pageId.asKnown().isPresent) 1 else 0) + + (if (publishedAt.asKnown().isPresent) 1 else 0) + + (if (publishedVersion.asKnown().isPresent) 1 else 0) + + (if (previewUrl.asKnown().isPresent) 1 else 0) + + (if (publishedBy.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PublishPreferencesResponse && + pageId == other.pageId && + publishedAt == other.publishedAt && + publishedVersion == other.publishedVersion && + previewUrl == other.previewUrl && + publishedBy == other.publishedBy && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + pageId, + publishedAt, + publishedVersion, + previewUrl, + publishedBy, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PublishPreferencesResponse{pageId=$pageId, publishedAt=$publishedAt, publishedVersion=$publishedVersion, previewUrl=$previewUrl, publishedBy=$publishedBy, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicArchiveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicArchiveParams.kt new file mode 100644 index 0000000..b5bdccf --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicArchiveParams.kt @@ -0,0 +1,258 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import com.courier.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Archive a topic and remove it from its section. Same 404 rules as GET. */ +class TopicArchiveParams +private constructor( + private val sectionId: String, + private val topicId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun sectionId(): String = sectionId + + fun topicId(): Optional = Optional.ofNullable(topicId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [TopicArchiveParams]. + * + * The following fields are required: + * ```java + * .sectionId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TopicArchiveParams]. */ + class Builder internal constructor() { + + private var sectionId: String? = null + private var topicId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(topicArchiveParams: TopicArchiveParams) = apply { + sectionId = topicArchiveParams.sectionId + topicId = topicArchiveParams.topicId + additionalHeaders = topicArchiveParams.additionalHeaders.toBuilder() + additionalQueryParams = topicArchiveParams.additionalQueryParams.toBuilder() + additionalBodyProperties = topicArchiveParams.additionalBodyProperties.toMutableMap() + } + + fun sectionId(sectionId: String) = apply { this.sectionId = sectionId } + + fun topicId(topicId: String?) = apply { this.topicId = topicId } + + /** Alias for calling [Builder.topicId] with `topicId.orElse(null)`. */ + fun topicId(topicId: Optional) = topicId(topicId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [TopicArchiveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sectionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TopicArchiveParams = + TopicArchiveParams( + checkRequired("sectionId", sectionId), + topicId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sectionId + 1 -> topicId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TopicArchiveParams && + sectionId == other.sectionId && + topicId == other.topicId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + sectionId, + topicId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "TopicArchiveParams{sectionId=$sectionId, topicId=$topicId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicCreateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicCreateParams.kt new file mode 100644 index 0000000..6d9f818 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicCreateParams.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import com.courier.models.preferencesections.PreferenceTopicCreateRequest +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Create a subscription preference topic inside a section. Fails with 404 if the section does not + * exist. The topic id is generated and returned. + */ +class TopicCreateParams +private constructor( + private val sectionId: String?, + private val preferenceTopicCreateRequest: PreferenceTopicCreateRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sectionId(): Optional = Optional.ofNullable(sectionId) + + /** Request body for creating a preference topic. */ + fun preferenceTopicCreateRequest(): PreferenceTopicCreateRequest = preferenceTopicCreateRequest + + fun _additionalBodyProperties(): Map = + preferenceTopicCreateRequest._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [TopicCreateParams]. + * + * The following fields are required: + * ```java + * .preferenceTopicCreateRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TopicCreateParams]. */ + class Builder internal constructor() { + + private var sectionId: String? = null + private var preferenceTopicCreateRequest: PreferenceTopicCreateRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(topicCreateParams: TopicCreateParams) = apply { + sectionId = topicCreateParams.sectionId + preferenceTopicCreateRequest = topicCreateParams.preferenceTopicCreateRequest + additionalHeaders = topicCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = topicCreateParams.additionalQueryParams.toBuilder() + } + + fun sectionId(sectionId: String?) = apply { this.sectionId = sectionId } + + /** Alias for calling [Builder.sectionId] with `sectionId.orElse(null)`. */ + fun sectionId(sectionId: Optional) = sectionId(sectionId.getOrNull()) + + /** Request body for creating a preference topic. */ + fun preferenceTopicCreateRequest( + preferenceTopicCreateRequest: PreferenceTopicCreateRequest + ) = apply { this.preferenceTopicCreateRequest = preferenceTopicCreateRequest } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [TopicCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .preferenceTopicCreateRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TopicCreateParams = + TopicCreateParams( + sectionId, + checkRequired("preferenceTopicCreateRequest", preferenceTopicCreateRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): PreferenceTopicCreateRequest = preferenceTopicCreateRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sectionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TopicCreateParams && + sectionId == other.sectionId && + preferenceTopicCreateRequest == other.preferenceTopicCreateRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + sectionId, + preferenceTopicCreateRequest, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "TopicCreateParams{sectionId=$sectionId, preferenceTopicCreateRequest=$preferenceTopicCreateRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicListParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicListParams.kt new file mode 100644 index 0000000..53e51fb --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicListParams.kt @@ -0,0 +1,189 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List the topics in a preference section. */ +class TopicListParams +private constructor( + private val sectionId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sectionId(): Optional = Optional.ofNullable(sectionId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): TopicListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [TopicListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TopicListParams]. */ + class Builder internal constructor() { + + private var sectionId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(topicListParams: TopicListParams) = apply { + sectionId = topicListParams.sectionId + additionalHeaders = topicListParams.additionalHeaders.toBuilder() + additionalQueryParams = topicListParams.additionalQueryParams.toBuilder() + } + + fun sectionId(sectionId: String?) = apply { this.sectionId = sectionId } + + /** Alias for calling [Builder.sectionId] with `sectionId.orElse(null)`. */ + fun sectionId(sectionId: Optional) = sectionId(sectionId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [TopicListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): TopicListParams = + TopicListParams(sectionId, additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sectionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TopicListParams && + sectionId == other.sectionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(sectionId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "TopicListParams{sectionId=$sectionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicReplaceParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicReplaceParams.kt new file mode 100644 index 0000000..e66216f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicReplaceParams.kt @@ -0,0 +1,255 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import com.courier.models.preferencesections.PreferenceTopicReplaceRequest +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Replace a topic within a section. Full document replacement; missing optional fields are cleared. + * Same 404 rules as GET. + */ +class TopicReplaceParams +private constructor( + private val sectionId: String, + private val topicId: String?, + private val preferenceTopicReplaceRequest: PreferenceTopicReplaceRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sectionId(): String = sectionId + + fun topicId(): Optional = Optional.ofNullable(topicId) + + /** + * Request body for replacing a preference topic. Full document replacement; missing optional + * fields are cleared. + */ + fun preferenceTopicReplaceRequest(): PreferenceTopicReplaceRequest = + preferenceTopicReplaceRequest + + fun _additionalBodyProperties(): Map = + preferenceTopicReplaceRequest._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [TopicReplaceParams]. + * + * The following fields are required: + * ```java + * .sectionId() + * .preferenceTopicReplaceRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TopicReplaceParams]. */ + class Builder internal constructor() { + + private var sectionId: String? = null + private var topicId: String? = null + private var preferenceTopicReplaceRequest: PreferenceTopicReplaceRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(topicReplaceParams: TopicReplaceParams) = apply { + sectionId = topicReplaceParams.sectionId + topicId = topicReplaceParams.topicId + preferenceTopicReplaceRequest = topicReplaceParams.preferenceTopicReplaceRequest + additionalHeaders = topicReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = topicReplaceParams.additionalQueryParams.toBuilder() + } + + fun sectionId(sectionId: String) = apply { this.sectionId = sectionId } + + fun topicId(topicId: String?) = apply { this.topicId = topicId } + + /** Alias for calling [Builder.topicId] with `topicId.orElse(null)`. */ + fun topicId(topicId: Optional) = topicId(topicId.getOrNull()) + + /** + * Request body for replacing a preference topic. Full document replacement; missing + * optional fields are cleared. + */ + fun preferenceTopicReplaceRequest( + preferenceTopicReplaceRequest: PreferenceTopicReplaceRequest + ) = apply { this.preferenceTopicReplaceRequest = preferenceTopicReplaceRequest } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [TopicReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sectionId() + * .preferenceTopicReplaceRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TopicReplaceParams = + TopicReplaceParams( + checkRequired("sectionId", sectionId), + topicId, + checkRequired("preferenceTopicReplaceRequest", preferenceTopicReplaceRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): PreferenceTopicReplaceRequest = preferenceTopicReplaceRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sectionId + 1 -> topicId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TopicReplaceParams && + sectionId == other.sectionId && + topicId == other.topicId && + preferenceTopicReplaceRequest == other.preferenceTopicReplaceRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + sectionId, + topicId, + preferenceTopicReplaceRequest, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "TopicReplaceParams{sectionId=$sectionId, topicId=$topicId, preferenceTopicReplaceRequest=$preferenceTopicReplaceRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicRetrieveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicRetrieveParams.kt new file mode 100644 index 0000000..04e3051 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/preferencesections/topics/TopicRetrieveParams.kt @@ -0,0 +1,220 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Retrieve a topic within a section. Returns 404 if the section does not exist, the topic does not + * exist, or the topic belongs to a different section. + */ +class TopicRetrieveParams +private constructor( + private val sectionId: String, + private val topicId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sectionId(): String = sectionId + + fun topicId(): Optional = Optional.ofNullable(topicId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [TopicRetrieveParams]. + * + * The following fields are required: + * ```java + * .sectionId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TopicRetrieveParams]. */ + class Builder internal constructor() { + + private var sectionId: String? = null + private var topicId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(topicRetrieveParams: TopicRetrieveParams) = apply { + sectionId = topicRetrieveParams.sectionId + topicId = topicRetrieveParams.topicId + additionalHeaders = topicRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = topicRetrieveParams.additionalQueryParams.toBuilder() + } + + fun sectionId(sectionId: String) = apply { this.sectionId = sectionId } + + fun topicId(topicId: String?) = apply { this.topicId = topicId } + + /** Alias for calling [Builder.topicId] with `topicId.orElse(null)`. */ + fun topicId(topicId: Optional) = topicId(topicId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [TopicRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sectionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TopicRetrieveParams = + TopicRetrieveParams( + checkRequired("sectionId", sectionId), + topicId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sectionId + 1 -> topicId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TopicRetrieveParams && + sectionId == other.sectionId && + topicId == other.topicId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(sectionId, topicId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "TopicRetrieveParams{sectionId=$sectionId, topicId=$topicId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/PreferenceSectionServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/PreferenceSectionServiceAsync.kt new file mode 100644 index 0000000..954fc4f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/PreferenceSectionServiceAsync.kt @@ -0,0 +1,428 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponseFor +import com.courier.models.preferencesections.PreferenceSectionArchiveParams +import com.courier.models.preferencesections.PreferenceSectionCreateParams +import com.courier.models.preferencesections.PreferenceSectionCreateRequest +import com.courier.models.preferencesections.PreferenceSectionGetResponse +import com.courier.models.preferencesections.PreferenceSectionListParams +import com.courier.models.preferencesections.PreferenceSectionListResponse +import com.courier.models.preferencesections.PreferenceSectionPublishParams +import com.courier.models.preferencesections.PreferenceSectionReplaceParams +import com.courier.models.preferencesections.PreferenceSectionRetrieveParams +import com.courier.models.preferencesections.PublishPreferencesResponse +import com.courier.services.async.preferencesections.TopicServiceAsync +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface PreferenceSectionServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PreferenceSectionServiceAsync + + fun topics(): TopicServiceAsync + + /** + * Create a preference section in your workspace. The section id is generated and returned. + * Topics are created inside a section via POST /preferences/sections/{section_id}/topics. + */ + fun create( + params: PreferenceSectionCreateParams + ): CompletableFuture = create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: PreferenceSectionCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see create */ + fun create( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + create( + PreferenceSectionCreateParams.builder() + .preferenceSectionCreateRequest(preferenceSectionCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest + ): CompletableFuture = + create(preferenceSectionCreateRequest, RequestOptions.none()) + + /** Retrieve a preference section by id, including its topics. */ + fun retrieve(sectionId: String): CompletableFuture = + retrieve(sectionId, PreferenceSectionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + sectionId: String, + params: PreferenceSectionRetrieveParams = PreferenceSectionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + sectionId: String, + params: PreferenceSectionRetrieveParams = PreferenceSectionRetrieveParams.none(), + ): CompletableFuture = + retrieve(sectionId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: PreferenceSectionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve( + params: PreferenceSectionRetrieveParams + ): CompletableFuture = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + sectionId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(sectionId, PreferenceSectionRetrieveParams.none(), requestOptions) + + /** + * List the workspace's preference sections. Each section embeds its topics. Scoped to the + * workspace of the API key. + */ + fun list(): CompletableFuture = + list(PreferenceSectionListParams.none()) + + /** @see list */ + fun list( + params: PreferenceSectionListParams = PreferenceSectionListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: PreferenceSectionListParams = PreferenceSectionListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(PreferenceSectionListParams.none(), requestOptions) + + /** + * Archive a preference section. The section must be empty: delete its topics first, otherwise + * the request fails with 409. + */ + fun archive(sectionId: String): CompletableFuture = + archive(sectionId, PreferenceSectionArchiveParams.none()) + + /** @see archive */ + fun archive( + sectionId: String, + params: PreferenceSectionArchiveParams = PreferenceSectionArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archive(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see archive */ + fun archive( + sectionId: String, + params: PreferenceSectionArchiveParams = PreferenceSectionArchiveParams.none(), + ): CompletableFuture = archive(sectionId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: PreferenceSectionArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see archive */ + fun archive(params: PreferenceSectionArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(sectionId: String, requestOptions: RequestOptions): CompletableFuture = + archive(sectionId, PreferenceSectionArchiveParams.none(), requestOptions) + + /** + * Publish the workspace's preferences page. Takes a snapshot of every section with its topics + * under a new published version, making the current state visible on the hosted preferences + * page (non-draft). + */ + fun publish(): CompletableFuture = + publish(PreferenceSectionPublishParams.none()) + + /** @see publish */ + fun publish( + params: PreferenceSectionPublishParams = PreferenceSectionPublishParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see publish */ + fun publish( + params: PreferenceSectionPublishParams = PreferenceSectionPublishParams.none() + ): CompletableFuture = publish(params, RequestOptions.none()) + + /** @see publish */ + fun publish(requestOptions: RequestOptions): CompletableFuture = + publish(PreferenceSectionPublishParams.none(), requestOptions) + + /** + * Replace a preference section. Full document replacement; missing optional fields are cleared. + * Topics attached to the section are unaffected. + */ + fun replace( + sectionId: String, + params: PreferenceSectionReplaceParams, + ): CompletableFuture = + replace(sectionId, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + sectionId: String, + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + replace(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see replace */ + fun replace( + params: PreferenceSectionReplaceParams + ): CompletableFuture = replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [PreferenceSectionServiceAsync] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): PreferenceSectionServiceAsync.WithRawResponse + + fun topics(): TopicServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /preferences/sections`, but is otherwise the same + * as [PreferenceSectionServiceAsync.create]. + */ + fun create( + params: PreferenceSectionCreateParams + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: PreferenceSectionCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see create */ + fun create( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + create( + PreferenceSectionCreateParams.builder() + .preferenceSectionCreateRequest(preferenceSectionCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest + ): CompletableFuture> = + create(preferenceSectionCreateRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /preferences/sections/{section_id}`, but is + * otherwise the same as [PreferenceSectionServiceAsync.retrieve]. + */ + fun retrieve( + sectionId: String + ): CompletableFuture> = + retrieve(sectionId, PreferenceSectionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + sectionId: String, + params: PreferenceSectionRetrieveParams = PreferenceSectionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + sectionId: String, + params: PreferenceSectionRetrieveParams = PreferenceSectionRetrieveParams.none(), + ): CompletableFuture> = + retrieve(sectionId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: PreferenceSectionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: PreferenceSectionRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + sectionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(sectionId, PreferenceSectionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /preferences/sections`, but is otherwise the same as + * [PreferenceSectionServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(PreferenceSectionListParams.none()) + + /** @see list */ + fun list( + params: PreferenceSectionListParams = PreferenceSectionListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: PreferenceSectionListParams = PreferenceSectionListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(PreferenceSectionListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /preferences/sections/{section_id}`, but is + * otherwise the same as [PreferenceSectionServiceAsync.archive]. + */ + fun archive(sectionId: String): CompletableFuture = + archive(sectionId, PreferenceSectionArchiveParams.none()) + + /** @see archive */ + fun archive( + sectionId: String, + params: PreferenceSectionArchiveParams = PreferenceSectionArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archive(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see archive */ + fun archive( + sectionId: String, + params: PreferenceSectionArchiveParams = PreferenceSectionArchiveParams.none(), + ): CompletableFuture = archive(sectionId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: PreferenceSectionArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see archive */ + fun archive(params: PreferenceSectionArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive( + sectionId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + archive(sectionId, PreferenceSectionArchiveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /preferences/publish`, but is otherwise the same as + * [PreferenceSectionServiceAsync.publish]. + */ + fun publish(): CompletableFuture> = + publish(PreferenceSectionPublishParams.none()) + + /** @see publish */ + fun publish( + params: PreferenceSectionPublishParams = PreferenceSectionPublishParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see publish */ + fun publish( + params: PreferenceSectionPublishParams = PreferenceSectionPublishParams.none() + ): CompletableFuture> = + publish(params, RequestOptions.none()) + + /** @see publish */ + fun publish( + requestOptions: RequestOptions + ): CompletableFuture> = + publish(PreferenceSectionPublishParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /preferences/sections/{section_id}`, but is + * otherwise the same as [PreferenceSectionServiceAsync.replace]. + */ + fun replace( + sectionId: String, + params: PreferenceSectionReplaceParams, + ): CompletableFuture> = + replace(sectionId, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + sectionId: String, + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + replace(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see replace */ + fun replace( + params: PreferenceSectionReplaceParams + ): CompletableFuture> = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/PreferenceSectionServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/PreferenceSectionServiceAsyncImpl.kt new file mode 100644 index 0000000..1e8975c --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/PreferenceSectionServiceAsyncImpl.kt @@ -0,0 +1,300 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.checkRequired +import com.courier.core.handlers.emptyHandler +import com.courier.core.handlers.errorBodyHandler +import com.courier.core.handlers.errorHandler +import com.courier.core.handlers.jsonHandler +import com.courier.core.http.HttpMethod +import com.courier.core.http.HttpRequest +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponse.Handler +import com.courier.core.http.HttpResponseFor +import com.courier.core.http.json +import com.courier.core.http.parseable +import com.courier.core.prepareAsync +import com.courier.models.preferencesections.PreferenceSectionArchiveParams +import com.courier.models.preferencesections.PreferenceSectionCreateParams +import com.courier.models.preferencesections.PreferenceSectionGetResponse +import com.courier.models.preferencesections.PreferenceSectionListParams +import com.courier.models.preferencesections.PreferenceSectionListResponse +import com.courier.models.preferencesections.PreferenceSectionPublishParams +import com.courier.models.preferencesections.PreferenceSectionReplaceParams +import com.courier.models.preferencesections.PreferenceSectionRetrieveParams +import com.courier.models.preferencesections.PublishPreferencesResponse +import com.courier.services.async.preferencesections.TopicServiceAsync +import com.courier.services.async.preferencesections.TopicServiceAsyncImpl +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class PreferenceSectionServiceAsyncImpl +internal constructor(private val clientOptions: ClientOptions) : PreferenceSectionServiceAsync { + + private val withRawResponse: PreferenceSectionServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val topics: TopicServiceAsync by lazy { TopicServiceAsyncImpl(clientOptions) } + + override fun withRawResponse(): PreferenceSectionServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions( + modifier: Consumer + ): PreferenceSectionServiceAsync = + PreferenceSectionServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun topics(): TopicServiceAsync = topics + + override fun create( + params: PreferenceSectionCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /preferences/sections + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: PreferenceSectionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /preferences/sections/{section_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: PreferenceSectionListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /preferences/sections + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun archive( + params: PreferenceSectionArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /preferences/sections/{section_id} + withRawResponse().archive(params, requestOptions).thenAccept {} + + override fun publish( + params: PreferenceSectionPublishParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /preferences/publish + withRawResponse().publish(params, requestOptions).thenApply { it.parse() } + + override fun replace( + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // put /preferences/sections/{section_id} + withRawResponse().replace(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + PreferenceSectionServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val topics: TopicServiceAsync.WithRawResponse by lazy { + TopicServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): PreferenceSectionServiceAsync.WithRawResponse = + PreferenceSectionServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun topics(): TopicServiceAsync.WithRawResponse = topics + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: PreferenceSectionCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: PreferenceSectionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0)) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: PreferenceSectionListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val archiveHandler: Handler = emptyHandler() + + override fun archive( + params: PreferenceSectionArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response.use { archiveHandler.handle(it) } + } + } + } + + private val publishHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun publish( + params: PreferenceSectionPublishParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "publish") + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { publishHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val replaceHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun replace( + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0)) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { replaceHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/preferencesections/TopicServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/preferencesections/TopicServiceAsync.kt new file mode 100644 index 0000000..7a12372 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/preferencesections/TopicServiceAsync.kt @@ -0,0 +1,348 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.preferencesections + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponseFor +import com.courier.models.preferencesections.PreferenceTopicGetResponse +import com.courier.models.preferencesections.PreferenceTopicListResponse +import com.courier.models.preferencesections.topics.TopicArchiveParams +import com.courier.models.preferencesections.topics.TopicCreateParams +import com.courier.models.preferencesections.topics.TopicListParams +import com.courier.models.preferencesections.topics.TopicReplaceParams +import com.courier.models.preferencesections.topics.TopicRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface TopicServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): TopicServiceAsync + + /** + * Create a subscription preference topic inside a section. Fails with 404 if the section does + * not exist. The topic id is generated and returned. + */ + fun create( + sectionId: String, + params: TopicCreateParams, + ): CompletableFuture = + create(sectionId, params, RequestOptions.none()) + + /** @see create */ + fun create( + sectionId: String, + params: TopicCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + create(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see create */ + fun create(params: TopicCreateParams): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: TopicCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * Retrieve a topic within a section. Returns 404 if the section does not exist, the topic does + * not exist, or the topic belongs to a different section. + */ + fun retrieve( + topicId: String, + params: TopicRetrieveParams, + ): CompletableFuture = + retrieve(topicId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + topicId: String, + params: TopicRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: TopicRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: TopicRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** List the topics in a preference section. */ + fun list(sectionId: String): CompletableFuture = + list(sectionId, TopicListParams.none()) + + /** @see list */ + fun list( + sectionId: String, + params: TopicListParams = TopicListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + list(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see list */ + fun list( + sectionId: String, + params: TopicListParams = TopicListParams.none(), + ): CompletableFuture = + list(sectionId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: TopicListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list(params: TopicListParams): CompletableFuture = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + sectionId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + list(sectionId, TopicListParams.none(), requestOptions) + + /** Archive a topic and remove it from its section. Same 404 rules as GET. */ + fun archive(topicId: String, params: TopicArchiveParams): CompletableFuture = + archive(topicId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + topicId: String, + params: TopicArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archive(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see archive */ + fun archive(params: TopicArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: TopicArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * Replace a topic within a section. Full document replacement; missing optional fields are + * cleared. Same 404 rules as GET. + */ + fun replace( + topicId: String, + params: TopicReplaceParams, + ): CompletableFuture = + replace(topicId, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + topicId: String, + params: TopicReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + replace(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see replace */ + fun replace(params: TopicReplaceParams): CompletableFuture = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: TopicReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** A view of [TopicServiceAsync] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): TopicServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /preferences/sections/{section_id}/topics`, but is + * otherwise the same as [TopicServiceAsync.create]. + */ + fun create( + sectionId: String, + params: TopicCreateParams, + ): CompletableFuture> = + create(sectionId, params, RequestOptions.none()) + + /** @see create */ + fun create( + sectionId: String, + params: TopicCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + create(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see create */ + fun create( + params: TopicCreateParams + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: TopicCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get + * /preferences/sections/{section_id}/topics/{topic_id}`, but is otherwise the same as + * [TopicServiceAsync.retrieve]. + */ + fun retrieve( + topicId: String, + params: TopicRetrieveParams, + ): CompletableFuture> = + retrieve(topicId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + topicId: String, + params: TopicRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: TopicRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: TopicRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /preferences/sections/{section_id}/topics`, but is + * otherwise the same as [TopicServiceAsync.list]. + */ + fun list( + sectionId: String + ): CompletableFuture> = + list(sectionId, TopicListParams.none()) + + /** @see list */ + fun list( + sectionId: String, + params: TopicListParams = TopicListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + list(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see list */ + fun list( + sectionId: String, + params: TopicListParams = TopicListParams.none(), + ): CompletableFuture> = + list(sectionId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: TopicListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: TopicListParams + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + sectionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + list(sectionId, TopicListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete + * /preferences/sections/{section_id}/topics/{topic_id}`, but is otherwise the same as + * [TopicServiceAsync.archive]. + */ + fun archive(topicId: String, params: TopicArchiveParams): CompletableFuture = + archive(topicId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + topicId: String, + params: TopicArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archive(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see archive */ + fun archive(params: TopicArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: TopicArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * Returns a raw HTTP response for `put + * /preferences/sections/{section_id}/topics/{topic_id}`, but is otherwise the same as + * [TopicServiceAsync.replace]. + */ + fun replace( + topicId: String, + params: TopicReplaceParams, + ): CompletableFuture> = + replace(topicId, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + topicId: String, + params: TopicReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + replace(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see replace */ + fun replace( + params: TopicReplaceParams + ): CompletableFuture> = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: TopicReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/preferencesections/TopicServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/preferencesections/TopicServiceAsyncImpl.kt new file mode 100644 index 0000000..0ec567f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/preferencesections/TopicServiceAsyncImpl.kt @@ -0,0 +1,270 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.preferencesections + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.checkRequired +import com.courier.core.handlers.emptyHandler +import com.courier.core.handlers.errorBodyHandler +import com.courier.core.handlers.errorHandler +import com.courier.core.handlers.jsonHandler +import com.courier.core.http.HttpMethod +import com.courier.core.http.HttpRequest +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponse.Handler +import com.courier.core.http.HttpResponseFor +import com.courier.core.http.json +import com.courier.core.http.parseable +import com.courier.core.prepareAsync +import com.courier.models.preferencesections.PreferenceTopicGetResponse +import com.courier.models.preferencesections.PreferenceTopicListResponse +import com.courier.models.preferencesections.topics.TopicArchiveParams +import com.courier.models.preferencesections.topics.TopicCreateParams +import com.courier.models.preferencesections.topics.TopicListParams +import com.courier.models.preferencesections.topics.TopicReplaceParams +import com.courier.models.preferencesections.topics.TopicRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class TopicServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + TopicServiceAsync { + + private val withRawResponse: TopicServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): TopicServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): TopicServiceAsync = + TopicServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: TopicCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /preferences/sections/{section_id}/topics + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: TopicRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /preferences/sections/{section_id}/topics/{topic_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: TopicListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /preferences/sections/{section_id}/topics + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun archive( + params: TopicArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /preferences/sections/{section_id}/topics/{topic_id} + withRawResponse().archive(params, requestOptions).thenAccept {} + + override fun replace( + params: TopicReplaceParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // put /preferences/sections/{section_id}/topics/{topic_id} + withRawResponse().replace(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + TopicServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): TopicServiceAsync.WithRawResponse = + TopicServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: TopicCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0), "topics") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: TopicRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("topicId", params.topicId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "preferences", + "sections", + params._pathParam(0), + "topics", + params._pathParam(1), + ) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: TopicListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0), "topics") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val archiveHandler: Handler = emptyHandler() + + override fun archive( + params: TopicArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("topicId", params.topicId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "preferences", + "sections", + params._pathParam(0), + "topics", + params._pathParam(1), + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response.use { archiveHandler.handle(it) } + } + } + } + + private val replaceHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun replace( + params: TopicReplaceParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("topicId", params.topicId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "preferences", + "sections", + params._pathParam(0), + "topics", + params._pathParam(1), + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { replaceHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreferenceSectionService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreferenceSectionService.kt new file mode 100644 index 0000000..0a6abc8 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreferenceSectionService.kt @@ -0,0 +1,427 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponseFor +import com.courier.models.preferencesections.PreferenceSectionArchiveParams +import com.courier.models.preferencesections.PreferenceSectionCreateParams +import com.courier.models.preferencesections.PreferenceSectionCreateRequest +import com.courier.models.preferencesections.PreferenceSectionGetResponse +import com.courier.models.preferencesections.PreferenceSectionListParams +import com.courier.models.preferencesections.PreferenceSectionListResponse +import com.courier.models.preferencesections.PreferenceSectionPublishParams +import com.courier.models.preferencesections.PreferenceSectionReplaceParams +import com.courier.models.preferencesections.PreferenceSectionRetrieveParams +import com.courier.models.preferencesections.PublishPreferencesResponse +import com.courier.services.blocking.preferencesections.TopicService +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface PreferenceSectionService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PreferenceSectionService + + fun topics(): TopicService + + /** + * Create a preference section in your workspace. The section id is generated and returned. + * Topics are created inside a section via POST /preferences/sections/{section_id}/topics. + */ + fun create(params: PreferenceSectionCreateParams): PreferenceSectionGetResponse = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: PreferenceSectionCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceSectionGetResponse + + /** @see create */ + fun create( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceSectionGetResponse = + create( + PreferenceSectionCreateParams.builder() + .preferenceSectionCreateRequest(preferenceSectionCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest + ): PreferenceSectionGetResponse = create(preferenceSectionCreateRequest, RequestOptions.none()) + + /** Retrieve a preference section by id, including its topics. */ + fun retrieve(sectionId: String): PreferenceSectionGetResponse = + retrieve(sectionId, PreferenceSectionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + sectionId: String, + params: PreferenceSectionRetrieveParams = PreferenceSectionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceSectionGetResponse = + retrieve(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + sectionId: String, + params: PreferenceSectionRetrieveParams = PreferenceSectionRetrieveParams.none(), + ): PreferenceSectionGetResponse = retrieve(sectionId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: PreferenceSectionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceSectionGetResponse + + /** @see retrieve */ + fun retrieve(params: PreferenceSectionRetrieveParams): PreferenceSectionGetResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(sectionId: String, requestOptions: RequestOptions): PreferenceSectionGetResponse = + retrieve(sectionId, PreferenceSectionRetrieveParams.none(), requestOptions) + + /** + * List the workspace's preference sections. Each section embeds its topics. Scoped to the + * workspace of the API key. + */ + fun list(): PreferenceSectionListResponse = list(PreferenceSectionListParams.none()) + + /** @see list */ + fun list( + params: PreferenceSectionListParams = PreferenceSectionListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceSectionListResponse + + /** @see list */ + fun list( + params: PreferenceSectionListParams = PreferenceSectionListParams.none() + ): PreferenceSectionListResponse = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): PreferenceSectionListResponse = + list(PreferenceSectionListParams.none(), requestOptions) + + /** + * Archive a preference section. The section must be empty: delete its topics first, otherwise + * the request fails with 409. + */ + fun archive(sectionId: String) = archive(sectionId, PreferenceSectionArchiveParams.none()) + + /** @see archive */ + fun archive( + sectionId: String, + params: PreferenceSectionArchiveParams = PreferenceSectionArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ) = archive(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see archive */ + fun archive( + sectionId: String, + params: PreferenceSectionArchiveParams = PreferenceSectionArchiveParams.none(), + ) = archive(sectionId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: PreferenceSectionArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ) + + /** @see archive */ + fun archive(params: PreferenceSectionArchiveParams) = archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(sectionId: String, requestOptions: RequestOptions) = + archive(sectionId, PreferenceSectionArchiveParams.none(), requestOptions) + + /** + * Publish the workspace's preferences page. Takes a snapshot of every section with its topics + * under a new published version, making the current state visible on the hosted preferences + * page (non-draft). + */ + fun publish(): PublishPreferencesResponse = publish(PreferenceSectionPublishParams.none()) + + /** @see publish */ + fun publish( + params: PreferenceSectionPublishParams = PreferenceSectionPublishParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): PublishPreferencesResponse + + /** @see publish */ + fun publish( + params: PreferenceSectionPublishParams = PreferenceSectionPublishParams.none() + ): PublishPreferencesResponse = publish(params, RequestOptions.none()) + + /** @see publish */ + fun publish(requestOptions: RequestOptions): PublishPreferencesResponse = + publish(PreferenceSectionPublishParams.none(), requestOptions) + + /** + * Replace a preference section. Full document replacement; missing optional fields are cleared. + * Topics attached to the section are unaffected. + */ + fun replace( + sectionId: String, + params: PreferenceSectionReplaceParams, + ): PreferenceSectionGetResponse = replace(sectionId, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + sectionId: String, + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceSectionGetResponse = + replace(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see replace */ + fun replace(params: PreferenceSectionReplaceParams): PreferenceSectionGetResponse = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceSectionGetResponse + + /** + * A view of [PreferenceSectionService] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): PreferenceSectionService.WithRawResponse + + fun topics(): TopicService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /preferences/sections`, but is otherwise the same + * as [PreferenceSectionService.create]. + */ + @MustBeClosed + fun create( + params: PreferenceSectionCreateParams + ): HttpResponseFor = create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: PreferenceSectionCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see create */ + @MustBeClosed + fun create( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + create( + PreferenceSectionCreateParams.builder() + .preferenceSectionCreateRequest(preferenceSectionCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + @MustBeClosed + fun create( + preferenceSectionCreateRequest: PreferenceSectionCreateRequest + ): HttpResponseFor = + create(preferenceSectionCreateRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /preferences/sections/{section_id}`, but is + * otherwise the same as [PreferenceSectionService.retrieve]. + */ + @MustBeClosed + fun retrieve(sectionId: String): HttpResponseFor = + retrieve(sectionId, PreferenceSectionRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + sectionId: String, + params: PreferenceSectionRetrieveParams = PreferenceSectionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + sectionId: String, + params: PreferenceSectionRetrieveParams = PreferenceSectionRetrieveParams.none(), + ): HttpResponseFor = + retrieve(sectionId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: PreferenceSectionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: PreferenceSectionRetrieveParams + ): HttpResponseFor = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + sectionId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(sectionId, PreferenceSectionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /preferences/sections`, but is otherwise the same as + * [PreferenceSectionService.list]. + */ + @MustBeClosed + fun list(): HttpResponseFor = + list(PreferenceSectionListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: PreferenceSectionListParams = PreferenceSectionListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list( + params: PreferenceSectionListParams = PreferenceSectionListParams.none() + ): HttpResponseFor = list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(PreferenceSectionListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /preferences/sections/{section_id}`, but is + * otherwise the same as [PreferenceSectionService.archive]. + */ + @MustBeClosed + fun archive(sectionId: String): HttpResponse = + archive(sectionId, PreferenceSectionArchiveParams.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + sectionId: String, + params: PreferenceSectionArchiveParams = PreferenceSectionArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = archive(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see archive */ + @MustBeClosed + fun archive( + sectionId: String, + params: PreferenceSectionArchiveParams = PreferenceSectionArchiveParams.none(), + ): HttpResponse = archive(sectionId, params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + params: PreferenceSectionArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** @see archive */ + @MustBeClosed + fun archive(params: PreferenceSectionArchiveParams): HttpResponse = + archive(params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive(sectionId: String, requestOptions: RequestOptions): HttpResponse = + archive(sectionId, PreferenceSectionArchiveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /preferences/publish`, but is otherwise the same as + * [PreferenceSectionService.publish]. + */ + @MustBeClosed + fun publish(): HttpResponseFor = + publish(PreferenceSectionPublishParams.none()) + + /** @see publish */ + @MustBeClosed + fun publish( + params: PreferenceSectionPublishParams = PreferenceSectionPublishParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see publish */ + @MustBeClosed + fun publish( + params: PreferenceSectionPublishParams = PreferenceSectionPublishParams.none() + ): HttpResponseFor = publish(params, RequestOptions.none()) + + /** @see publish */ + @MustBeClosed + fun publish(requestOptions: RequestOptions): HttpResponseFor = + publish(PreferenceSectionPublishParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /preferences/sections/{section_id}`, but is + * otherwise the same as [PreferenceSectionService.replace]. + */ + @MustBeClosed + fun replace( + sectionId: String, + params: PreferenceSectionReplaceParams, + ): HttpResponseFor = + replace(sectionId, params, RequestOptions.none()) + + /** @see replace */ + @MustBeClosed + fun replace( + sectionId: String, + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + replace(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see replace */ + @MustBeClosed + fun replace( + params: PreferenceSectionReplaceParams + ): HttpResponseFor = replace(params, RequestOptions.none()) + + /** @see replace */ + @MustBeClosed + fun replace( + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreferenceSectionServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreferenceSectionServiceImpl.kt new file mode 100644 index 0000000..470be2f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreferenceSectionServiceImpl.kt @@ -0,0 +1,277 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.checkRequired +import com.courier.core.handlers.emptyHandler +import com.courier.core.handlers.errorBodyHandler +import com.courier.core.handlers.errorHandler +import com.courier.core.handlers.jsonHandler +import com.courier.core.http.HttpMethod +import com.courier.core.http.HttpRequest +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponse.Handler +import com.courier.core.http.HttpResponseFor +import com.courier.core.http.json +import com.courier.core.http.parseable +import com.courier.core.prepare +import com.courier.models.preferencesections.PreferenceSectionArchiveParams +import com.courier.models.preferencesections.PreferenceSectionCreateParams +import com.courier.models.preferencesections.PreferenceSectionGetResponse +import com.courier.models.preferencesections.PreferenceSectionListParams +import com.courier.models.preferencesections.PreferenceSectionListResponse +import com.courier.models.preferencesections.PreferenceSectionPublishParams +import com.courier.models.preferencesections.PreferenceSectionReplaceParams +import com.courier.models.preferencesections.PreferenceSectionRetrieveParams +import com.courier.models.preferencesections.PublishPreferencesResponse +import com.courier.services.blocking.preferencesections.TopicService +import com.courier.services.blocking.preferencesections.TopicServiceImpl +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class PreferenceSectionServiceImpl internal constructor(private val clientOptions: ClientOptions) : + PreferenceSectionService { + + private val withRawResponse: PreferenceSectionService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val topics: TopicService by lazy { TopicServiceImpl(clientOptions) } + + override fun withRawResponse(): PreferenceSectionService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): PreferenceSectionService = + PreferenceSectionServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun topics(): TopicService = topics + + override fun create( + params: PreferenceSectionCreateParams, + requestOptions: RequestOptions, + ): PreferenceSectionGetResponse = + // post /preferences/sections + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve( + params: PreferenceSectionRetrieveParams, + requestOptions: RequestOptions, + ): PreferenceSectionGetResponse = + // get /preferences/sections/{section_id} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list( + params: PreferenceSectionListParams, + requestOptions: RequestOptions, + ): PreferenceSectionListResponse = + // get /preferences/sections + withRawResponse().list(params, requestOptions).parse() + + override fun archive(params: PreferenceSectionArchiveParams, requestOptions: RequestOptions) { + // delete /preferences/sections/{section_id} + withRawResponse().archive(params, requestOptions) + } + + override fun publish( + params: PreferenceSectionPublishParams, + requestOptions: RequestOptions, + ): PublishPreferencesResponse = + // post /preferences/publish + withRawResponse().publish(params, requestOptions).parse() + + override fun replace( + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions, + ): PreferenceSectionGetResponse = + // put /preferences/sections/{section_id} + withRawResponse().replace(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + PreferenceSectionService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val topics: TopicService.WithRawResponse by lazy { + TopicServiceImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): PreferenceSectionService.WithRawResponse = + PreferenceSectionServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun topics(): TopicService.WithRawResponse = topics + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: PreferenceSectionCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: PreferenceSectionRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0)) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: PreferenceSectionListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val archiveHandler: Handler = emptyHandler() + + override fun archive( + params: PreferenceSectionArchiveParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response.use { archiveHandler.handle(it) } + } + } + + private val publishHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun publish( + params: PreferenceSectionPublishParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "publish") + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { publishHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val replaceHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun replace( + params: PreferenceSectionReplaceParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0)) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { replaceHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/preferencesections/TopicService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/preferencesections/TopicService.kt new file mode 100644 index 0000000..fc0d220 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/preferencesections/TopicService.kt @@ -0,0 +1,339 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.preferencesections + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponseFor +import com.courier.models.preferencesections.PreferenceTopicGetResponse +import com.courier.models.preferencesections.PreferenceTopicListResponse +import com.courier.models.preferencesections.topics.TopicArchiveParams +import com.courier.models.preferencesections.topics.TopicCreateParams +import com.courier.models.preferencesections.topics.TopicListParams +import com.courier.models.preferencesections.topics.TopicReplaceParams +import com.courier.models.preferencesections.topics.TopicRetrieveParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface TopicService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): TopicService + + /** + * Create a subscription preference topic inside a section. Fails with 404 if the section does + * not exist. The topic id is generated and returned. + */ + fun create(sectionId: String, params: TopicCreateParams): PreferenceTopicGetResponse = + create(sectionId, params, RequestOptions.none()) + + /** @see create */ + fun create( + sectionId: String, + params: TopicCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceTopicGetResponse = + create(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see create */ + fun create(params: TopicCreateParams): PreferenceTopicGetResponse = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: TopicCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceTopicGetResponse + + /** + * Retrieve a topic within a section. Returns 404 if the section does not exist, the topic does + * not exist, or the topic belongs to a different section. + */ + fun retrieve(topicId: String, params: TopicRetrieveParams): PreferenceTopicGetResponse = + retrieve(topicId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + topicId: String, + params: TopicRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceTopicGetResponse = + retrieve(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: TopicRetrieveParams): PreferenceTopicGetResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: TopicRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceTopicGetResponse + + /** List the topics in a preference section. */ + fun list(sectionId: String): PreferenceTopicListResponse = + list(sectionId, TopicListParams.none()) + + /** @see list */ + fun list( + sectionId: String, + params: TopicListParams = TopicListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceTopicListResponse = + list(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see list */ + fun list( + sectionId: String, + params: TopicListParams = TopicListParams.none(), + ): PreferenceTopicListResponse = list(sectionId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: TopicListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceTopicListResponse + + /** @see list */ + fun list(params: TopicListParams): PreferenceTopicListResponse = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(sectionId: String, requestOptions: RequestOptions): PreferenceTopicListResponse = + list(sectionId, TopicListParams.none(), requestOptions) + + /** Archive a topic and remove it from its section. Same 404 rules as GET. */ + fun archive(topicId: String, params: TopicArchiveParams) = + archive(topicId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + topicId: String, + params: TopicArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ) = archive(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see archive */ + fun archive(params: TopicArchiveParams) = archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(params: TopicArchiveParams, requestOptions: RequestOptions = RequestOptions.none()) + + /** + * Replace a topic within a section. Full document replacement; missing optional fields are + * cleared. Same 404 rules as GET. + */ + fun replace(topicId: String, params: TopicReplaceParams): PreferenceTopicGetResponse = + replace(topicId, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + topicId: String, + params: TopicReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceTopicGetResponse = + replace(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see replace */ + fun replace(params: TopicReplaceParams): PreferenceTopicGetResponse = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: TopicReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreferenceTopicGetResponse + + /** A view of [TopicService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): TopicService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /preferences/sections/{section_id}/topics`, but is + * otherwise the same as [TopicService.create]. + */ + @MustBeClosed + fun create( + sectionId: String, + params: TopicCreateParams, + ): HttpResponseFor = + create(sectionId, params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + sectionId: String, + params: TopicCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + create(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see create */ + @MustBeClosed + fun create(params: TopicCreateParams): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: TopicCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get + * /preferences/sections/{section_id}/topics/{topic_id}`, but is otherwise the same as + * [TopicService.retrieve]. + */ + @MustBeClosed + fun retrieve( + topicId: String, + params: TopicRetrieveParams, + ): HttpResponseFor = + retrieve(topicId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + topicId: String, + params: TopicRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: TopicRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: TopicRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /preferences/sections/{section_id}/topics`, but is + * otherwise the same as [TopicService.list]. + */ + @MustBeClosed + fun list(sectionId: String): HttpResponseFor = + list(sectionId, TopicListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + sectionId: String, + params: TopicListParams = TopicListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + list(params.toBuilder().sectionId(sectionId).build(), requestOptions) + + /** @see list */ + @MustBeClosed + fun list( + sectionId: String, + params: TopicListParams = TopicListParams.none(), + ): HttpResponseFor = + list(sectionId, params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: TopicListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list(params: TopicListParams): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + sectionId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + list(sectionId, TopicListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete + * /preferences/sections/{section_id}/topics/{topic_id}`, but is otherwise the same as + * [TopicService.archive]. + */ + @MustBeClosed + fun archive(topicId: String, params: TopicArchiveParams): HttpResponse = + archive(topicId, params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + topicId: String, + params: TopicArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = archive(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see archive */ + @MustBeClosed + fun archive(params: TopicArchiveParams): HttpResponse = + archive(params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + params: TopicArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** + * Returns a raw HTTP response for `put + * /preferences/sections/{section_id}/topics/{topic_id}`, but is otherwise the same as + * [TopicService.replace]. + */ + @MustBeClosed + fun replace( + topicId: String, + params: TopicReplaceParams, + ): HttpResponseFor = + replace(topicId, params, RequestOptions.none()) + + /** @see replace */ + @MustBeClosed + fun replace( + topicId: String, + params: TopicReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + replace(params.toBuilder().topicId(topicId).build(), requestOptions) + + /** @see replace */ + @MustBeClosed + fun replace(params: TopicReplaceParams): HttpResponseFor = + replace(params, RequestOptions.none()) + + /** @see replace */ + @MustBeClosed + fun replace( + params: TopicReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/preferencesections/TopicServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/preferencesections/TopicServiceImpl.kt new file mode 100644 index 0000000..da17bdf --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/preferencesections/TopicServiceImpl.kt @@ -0,0 +1,252 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.preferencesections + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.checkRequired +import com.courier.core.handlers.emptyHandler +import com.courier.core.handlers.errorBodyHandler +import com.courier.core.handlers.errorHandler +import com.courier.core.handlers.jsonHandler +import com.courier.core.http.HttpMethod +import com.courier.core.http.HttpRequest +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponse.Handler +import com.courier.core.http.HttpResponseFor +import com.courier.core.http.json +import com.courier.core.http.parseable +import com.courier.core.prepare +import com.courier.models.preferencesections.PreferenceTopicGetResponse +import com.courier.models.preferencesections.PreferenceTopicListResponse +import com.courier.models.preferencesections.topics.TopicArchiveParams +import com.courier.models.preferencesections.topics.TopicCreateParams +import com.courier.models.preferencesections.topics.TopicListParams +import com.courier.models.preferencesections.topics.TopicReplaceParams +import com.courier.models.preferencesections.topics.TopicRetrieveParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class TopicServiceImpl internal constructor(private val clientOptions: ClientOptions) : + TopicService { + + private val withRawResponse: TopicService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): TopicService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): TopicService = + TopicServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: TopicCreateParams, + requestOptions: RequestOptions, + ): PreferenceTopicGetResponse = + // post /preferences/sections/{section_id}/topics + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve( + params: TopicRetrieveParams, + requestOptions: RequestOptions, + ): PreferenceTopicGetResponse = + // get /preferences/sections/{section_id}/topics/{topic_id} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list( + params: TopicListParams, + requestOptions: RequestOptions, + ): PreferenceTopicListResponse = + // get /preferences/sections/{section_id}/topics + withRawResponse().list(params, requestOptions).parse() + + override fun archive(params: TopicArchiveParams, requestOptions: RequestOptions) { + // delete /preferences/sections/{section_id}/topics/{topic_id} + withRawResponse().archive(params, requestOptions) + } + + override fun replace( + params: TopicReplaceParams, + requestOptions: RequestOptions, + ): PreferenceTopicGetResponse = + // put /preferences/sections/{section_id}/topics/{topic_id} + withRawResponse().replace(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + TopicService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): TopicService.WithRawResponse = + TopicServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: TopicCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0), "topics") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: TopicRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("topicId", params.topicId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "preferences", + "sections", + params._pathParam(0), + "topics", + params._pathParam(1), + ) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: TopicListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sectionId", params.sectionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("preferences", "sections", params._pathParam(0), "topics") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val archiveHandler: Handler = emptyHandler() + + override fun archive( + params: TopicArchiveParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("topicId", params.topicId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "preferences", + "sections", + params._pathParam(0), + "topics", + params._pathParam(1), + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response.use { archiveHandler.handle(it) } + } + } + + private val replaceHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun replace( + params: TopicReplaceParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("topicId", params.topicId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "preferences", + "sections", + params._pathParam(0), + "topics", + params._pathParam(1), + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { replaceHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionArchiveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionArchiveParamsTest.kt new file mode 100644 index 0000000..b7911be --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionArchiveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceSectionArchiveParamsTest { + + @Test + fun create() { + PreferenceSectionArchiveParams.builder().sectionId("section_id").build() + } + + @Test + fun pathParams() { + val params = PreferenceSectionArchiveParams.builder().sectionId("section_id").build() + + assertThat(params._pathParam(0)).isEqualTo("section_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateParamsTest.kt new file mode 100644 index 0000000..8bc3563 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateParamsTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.models.ChannelClassification +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceSectionCreateParamsTest { + + @Test + fun create() { + PreferenceSectionCreateParams.builder() + .preferenceSectionCreateRequest( + PreferenceSectionCreateRequest.builder() + .name("Account Notifications") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + .build() + } + + @Test + fun body() { + val params = + PreferenceSectionCreateParams.builder() + .preferenceSectionCreateRequest( + PreferenceSectionCreateRequest.builder() + .name("Account Notifications") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + PreferenceSectionCreateRequest.builder() + .name("Account Notifications") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + PreferenceSectionCreateParams.builder() + .preferenceSectionCreateRequest( + PreferenceSectionCreateRequest.builder().name("Account Notifications").build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + PreferenceSectionCreateRequest.builder().name("Account Notifications").build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateRequestTest.kt new file mode 100644 index 0000000..16d611f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionCreateRequestTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.jsonMapper +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceSectionCreateRequestTest { + + @Test + fun create() { + val preferenceSectionCreateRequest = + PreferenceSectionCreateRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + + assertThat(preferenceSectionCreateRequest.name()).isEqualTo("name") + assertThat(preferenceSectionCreateRequest.hasCustomRouting()).contains(true) + assertThat(preferenceSectionCreateRequest.routingOptions().getOrNull()) + .containsExactly(ChannelClassification.DIRECT_MESSAGE) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val preferenceSectionCreateRequest = + PreferenceSectionCreateRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + + val roundtrippedPreferenceSectionCreateRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(preferenceSectionCreateRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreferenceSectionCreateRequest) + .isEqualTo(preferenceSectionCreateRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionGetResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionGetResponseTest.kt new file mode 100644 index 0000000..2e69f86 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionGetResponseTest.kt @@ -0,0 +1,120 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceSectionGetResponseTest { + + @Test + fun create() { + val preferenceSectionGetResponse = + PreferenceSectionGetResponse.builder() + .id("id") + .created("created") + .hasCustomRouting(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .addTopic( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + .creator("creator") + .updated("updated") + .updater("updater") + .build() + + assertThat(preferenceSectionGetResponse.id()).isEqualTo("id") + assertThat(preferenceSectionGetResponse.created()).isEqualTo("created") + assertThat(preferenceSectionGetResponse.hasCustomRouting()).isEqualTo(true) + assertThat(preferenceSectionGetResponse.name()).isEqualTo("name") + assertThat(preferenceSectionGetResponse.routingOptions()) + .containsExactly(ChannelClassification.DIRECT_MESSAGE) + assertThat(preferenceSectionGetResponse.topics()) + .containsExactly( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + assertThat(preferenceSectionGetResponse.creator()).contains("creator") + assertThat(preferenceSectionGetResponse.updated()).contains("updated") + assertThat(preferenceSectionGetResponse.updater()).contains("updater") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val preferenceSectionGetResponse = + PreferenceSectionGetResponse.builder() + .id("id") + .created("created") + .hasCustomRouting(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .addTopic( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + .creator("creator") + .updated("updated") + .updater("updater") + .build() + + val roundtrippedPreferenceSectionGetResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(preferenceSectionGetResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreferenceSectionGetResponse).isEqualTo(preferenceSectionGetResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionListParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionListParamsTest.kt new file mode 100644 index 0000000..48d6261 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionListParamsTest.kt @@ -0,0 +1,13 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import org.junit.jupiter.api.Test + +internal class PreferenceSectionListParamsTest { + + @Test + fun create() { + PreferenceSectionListParams.builder().build() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionListResponseTest.kt new file mode 100644 index 0000000..e4a0fa1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionListResponseTest.kt @@ -0,0 +1,138 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceSectionListResponseTest { + + @Test + fun create() { + val preferenceSectionListResponse = + PreferenceSectionListResponse.builder() + .addResult( + PreferenceSectionGetResponse.builder() + .id("id") + .created("created") + .hasCustomRouting(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .addTopic( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference( + PreferenceTopicGetResponse.AllowedPreference.SNOOZE + ) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + .creator("creator") + .updated("updated") + .updater("updater") + .build() + ) + .build() + + assertThat(preferenceSectionListResponse.results()) + .containsExactly( + PreferenceSectionGetResponse.builder() + .id("id") + .created("created") + .hasCustomRouting(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .addTopic( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference( + PreferenceTopicGetResponse.AllowedPreference.SNOOZE + ) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + .creator("creator") + .updated("updated") + .updater("updater") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val preferenceSectionListResponse = + PreferenceSectionListResponse.builder() + .addResult( + PreferenceSectionGetResponse.builder() + .id("id") + .created("created") + .hasCustomRouting(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .addTopic( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference( + PreferenceTopicGetResponse.AllowedPreference.SNOOZE + ) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + .creator("creator") + .updated("updated") + .updater("updater") + .build() + ) + .build() + + val roundtrippedPreferenceSectionListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(preferenceSectionListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreferenceSectionListResponse) + .isEqualTo(preferenceSectionListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionPublishParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionPublishParamsTest.kt new file mode 100644 index 0000000..2c0dca9 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionPublishParamsTest.kt @@ -0,0 +1,13 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import org.junit.jupiter.api.Test + +internal class PreferenceSectionPublishParamsTest { + + @Test + fun create() { + PreferenceSectionPublishParams.builder().build() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceParamsTest.kt new file mode 100644 index 0000000..2e8bc5e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceParamsTest.kt @@ -0,0 +1,80 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.models.ChannelClassification +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceSectionReplaceParamsTest { + + @Test + fun create() { + PreferenceSectionReplaceParams.builder() + .sectionId("section_id") + .preferenceSectionReplaceRequest( + PreferenceSectionReplaceRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + PreferenceSectionReplaceParams.builder() + .sectionId("section_id") + .preferenceSectionReplaceRequest( + PreferenceSectionReplaceRequest.builder().name("name").build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("section_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + PreferenceSectionReplaceParams.builder() + .sectionId("section_id") + .preferenceSectionReplaceRequest( + PreferenceSectionReplaceRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + PreferenceSectionReplaceRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + PreferenceSectionReplaceParams.builder() + .sectionId("section_id") + .preferenceSectionReplaceRequest( + PreferenceSectionReplaceRequest.builder().name("name").build() + ) + .build() + + val body = params._body() + + assertThat(body).isEqualTo(PreferenceSectionReplaceRequest.builder().name("name").build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceRequestTest.kt new file mode 100644 index 0000000..7917ee2 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionReplaceRequestTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.jsonMapper +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceSectionReplaceRequestTest { + + @Test + fun create() { + val preferenceSectionReplaceRequest = + PreferenceSectionReplaceRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + + assertThat(preferenceSectionReplaceRequest.name()).isEqualTo("name") + assertThat(preferenceSectionReplaceRequest.hasCustomRouting()).contains(true) + assertThat(preferenceSectionReplaceRequest.routingOptions().getOrNull()) + .containsExactly(ChannelClassification.DIRECT_MESSAGE) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val preferenceSectionReplaceRequest = + PreferenceSectionReplaceRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + + val roundtrippedPreferenceSectionReplaceRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(preferenceSectionReplaceRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreferenceSectionReplaceRequest) + .isEqualTo(preferenceSectionReplaceRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionRetrieveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionRetrieveParamsTest.kt new file mode 100644 index 0000000..eecea46 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceSectionRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceSectionRetrieveParamsTest { + + @Test + fun create() { + PreferenceSectionRetrieveParams.builder().sectionId("section_id").build() + } + + @Test + fun pathParams() { + val params = PreferenceSectionRetrieveParams.builder().sectionId("section_id").build() + + assertThat(params._pathParam(0)).isEqualTo("section_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicCreateRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicCreateRequestTest.kt new file mode 100644 index 0000000..ff697c3 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicCreateRequestTest.kt @@ -0,0 +1,72 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceTopicCreateRequestTest { + + @Test + fun create() { + val preferenceTopicCreateRequest = + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference(PreferenceTopicCreateRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicCreateRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + + assertThat(preferenceTopicCreateRequest.defaultStatus()) + .isEqualTo(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + assertThat(preferenceTopicCreateRequest.name()).isEqualTo("name") + assertThat(preferenceTopicCreateRequest.allowedPreferences().getOrNull()) + .containsExactly(PreferenceTopicCreateRequest.AllowedPreference.SNOOZE) + assertThat(preferenceTopicCreateRequest.includeUnsubscribeHeader()).contains(true) + assertThat(preferenceTopicCreateRequest.routingOptions().getOrNull()) + .containsExactly(ChannelClassification.DIRECT_MESSAGE) + assertThat(preferenceTopicCreateRequest.topicData()) + .contains( + PreferenceTopicCreateRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val preferenceTopicCreateRequest = + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference(PreferenceTopicCreateRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicCreateRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + + val roundtrippedPreferenceTopicCreateRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(preferenceTopicCreateRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreferenceTopicCreateRequest).isEqualTo(preferenceTopicCreateRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicGetResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicGetResponseTest.kt new file mode 100644 index 0000000..755d78e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicGetResponseTest.kt @@ -0,0 +1,86 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceTopicGetResponseTest { + + @Test + fun create() { + val preferenceTopicGetResponse = + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + + assertThat(preferenceTopicGetResponse.id()).isEqualTo("id") + assertThat(preferenceTopicGetResponse.allowedPreferences()) + .containsExactly(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + assertThat(preferenceTopicGetResponse.created()).isEqualTo("created") + assertThat(preferenceTopicGetResponse.defaultStatus()) + .isEqualTo(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + assertThat(preferenceTopicGetResponse.includeUnsubscribeHeader()).isEqualTo(true) + assertThat(preferenceTopicGetResponse.name()).isEqualTo("name") + assertThat(preferenceTopicGetResponse.routingOptions()) + .containsExactly(ChannelClassification.DIRECT_MESSAGE) + assertThat(preferenceTopicGetResponse.topicData()) + .isEqualTo( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(preferenceTopicGetResponse.updated()).isEqualTo("updated") + assertThat(preferenceTopicGetResponse.creator()).contains("creator") + assertThat(preferenceTopicGetResponse.updater()).contains("updater") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val preferenceTopicGetResponse = + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + + val roundtrippedPreferenceTopicGetResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(preferenceTopicGetResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreferenceTopicGetResponse).isEqualTo(preferenceTopicGetResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicListResponseTest.kt new file mode 100644 index 0000000..f1367f3 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicListResponseTest.kt @@ -0,0 +1,95 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceTopicListResponseTest { + + @Test + fun create() { + val preferenceTopicListResponse = + PreferenceTopicListResponse.builder() + .addResult( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + .build() + + assertThat(preferenceTopicListResponse.results()) + .containsExactly( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val preferenceTopicListResponse = + PreferenceTopicListResponse.builder() + .addResult( + PreferenceTopicGetResponse.builder() + .id("id") + .addAllowedPreference(PreferenceTopicGetResponse.AllowedPreference.SNOOZE) + .created("created") + .defaultStatus(PreferenceTopicGetResponse.DefaultStatus.OPTED_OUT) + .includeUnsubscribeHeader(true) + .name("name") + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicGetResponse.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .updated("updated") + .creator("creator") + .updater("updater") + .build() + ) + .build() + + val roundtrippedPreferenceTopicListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(preferenceTopicListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreferenceTopicListResponse).isEqualTo(preferenceTopicListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicReplaceRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicReplaceRequestTest.kt new file mode 100644 index 0000000..6a174aa --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PreferenceTopicReplaceRequestTest.kt @@ -0,0 +1,73 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.ChannelClassification +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreferenceTopicReplaceRequestTest { + + @Test + fun create() { + val preferenceTopicReplaceRequest = + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference(PreferenceTopicReplaceRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicReplaceRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + + assertThat(preferenceTopicReplaceRequest.defaultStatus()) + .isEqualTo(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + assertThat(preferenceTopicReplaceRequest.name()).isEqualTo("name") + assertThat(preferenceTopicReplaceRequest.allowedPreferences().getOrNull()) + .containsExactly(PreferenceTopicReplaceRequest.AllowedPreference.SNOOZE) + assertThat(preferenceTopicReplaceRequest.includeUnsubscribeHeader()).contains(true) + assertThat(preferenceTopicReplaceRequest.routingOptions().getOrNull()) + .containsExactly(ChannelClassification.DIRECT_MESSAGE) + assertThat(preferenceTopicReplaceRequest.topicData()) + .contains( + PreferenceTopicReplaceRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val preferenceTopicReplaceRequest = + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference(PreferenceTopicReplaceRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicReplaceRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + + val roundtrippedPreferenceTopicReplaceRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(preferenceTopicReplaceRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreferenceTopicReplaceRequest) + .isEqualTo(preferenceTopicReplaceRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PublishPreferencesResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PublishPreferencesResponseTest.kt new file mode 100644 index 0000000..9d5eebb --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/PublishPreferencesResponseTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PublishPreferencesResponseTest { + + @Test + fun create() { + val publishPreferencesResponse = + PublishPreferencesResponse.builder() + .pageId("page_id") + .publishedAt("published_at") + .publishedVersion(0.0) + .previewUrl("preview_url") + .publishedBy("published_by") + .build() + + assertThat(publishPreferencesResponse.pageId()).isEqualTo("page_id") + assertThat(publishPreferencesResponse.publishedAt()).isEqualTo("published_at") + assertThat(publishPreferencesResponse.publishedVersion()).isEqualTo(0.0) + assertThat(publishPreferencesResponse.previewUrl()).contains("preview_url") + assertThat(publishPreferencesResponse.publishedBy()).contains("published_by") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val publishPreferencesResponse = + PublishPreferencesResponse.builder() + .pageId("page_id") + .publishedAt("published_at") + .publishedVersion(0.0) + .previewUrl("preview_url") + .publishedBy("published_by") + .build() + + val roundtrippedPublishPreferencesResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(publishPreferencesResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPublishPreferencesResponse).isEqualTo(publishPreferencesResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicArchiveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicArchiveParamsTest.kt new file mode 100644 index 0000000..550bada --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicArchiveParamsTest.kt @@ -0,0 +1,25 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class TopicArchiveParamsTest { + + @Test + fun create() { + TopicArchiveParams.builder().sectionId("section_id").topicId("topic_id").build() + } + + @Test + fun pathParams() { + val params = + TopicArchiveParams.builder().sectionId("section_id").topicId("topic_id").build() + + assertThat(params._pathParam(0)).isEqualTo("section_id") + assertThat(params._pathParam(1)).isEqualTo("topic_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicCreateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicCreateParamsTest.kt new file mode 100644 index 0000000..2344ab1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicCreateParamsTest.kt @@ -0,0 +1,115 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import com.courier.core.JsonValue +import com.courier.models.ChannelClassification +import com.courier.models.preferencesections.PreferenceTopicCreateRequest +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class TopicCreateParamsTest { + + @Test + fun create() { + TopicCreateParams.builder() + .sectionId("section_id") + .preferenceTopicCreateRequest( + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("Marketing") + .addAllowedPreference(PreferenceTopicCreateRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicCreateRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + TopicCreateParams.builder() + .sectionId("section_id") + .preferenceTopicCreateRequest( + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("Marketing") + .build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("section_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + TopicCreateParams.builder() + .sectionId("section_id") + .preferenceTopicCreateRequest( + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("Marketing") + .addAllowedPreference(PreferenceTopicCreateRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicCreateRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("Marketing") + .addAllowedPreference(PreferenceTopicCreateRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicCreateRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + TopicCreateParams.builder() + .sectionId("section_id") + .preferenceTopicCreateRequest( + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("Marketing") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("Marketing") + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicListParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicListParamsTest.kt new file mode 100644 index 0000000..6dffeab --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicListParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class TopicListParamsTest { + + @Test + fun create() { + TopicListParams.builder().sectionId("section_id").build() + } + + @Test + fun pathParams() { + val params = TopicListParams.builder().sectionId("section_id").build() + + assertThat(params._pathParam(0)).isEqualTo("section_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicReplaceParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicReplaceParamsTest.kt new file mode 100644 index 0000000..e2718a2 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicReplaceParamsTest.kt @@ -0,0 +1,122 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import com.courier.core.JsonValue +import com.courier.models.ChannelClassification +import com.courier.models.preferencesections.PreferenceTopicReplaceRequest +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class TopicReplaceParamsTest { + + @Test + fun create() { + TopicReplaceParams.builder() + .sectionId("section_id") + .topicId("topic_id") + .preferenceTopicReplaceRequest( + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference(PreferenceTopicReplaceRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicReplaceRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + TopicReplaceParams.builder() + .sectionId("section_id") + .topicId("topic_id") + .preferenceTopicReplaceRequest( + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("section_id") + assertThat(params._pathParam(1)).isEqualTo("topic_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun body() { + val params = + TopicReplaceParams.builder() + .sectionId("section_id") + .topicId("topic_id") + .preferenceTopicReplaceRequest( + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference( + PreferenceTopicReplaceRequest.AllowedPreference.SNOOZE + ) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicReplaceRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference(PreferenceTopicReplaceRequest.AllowedPreference.SNOOZE) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicReplaceRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + TopicReplaceParams.builder() + .sectionId("section_id") + .topicId("topic_id") + .preferenceTopicReplaceRequest( + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicRetrieveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicRetrieveParamsTest.kt new file mode 100644 index 0000000..46efdfe --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/preferencesections/topics/TopicRetrieveParamsTest.kt @@ -0,0 +1,25 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.preferencesections.topics + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class TopicRetrieveParamsTest { + + @Test + fun create() { + TopicRetrieveParams.builder().sectionId("section_id").topicId("topic_id").build() + } + + @Test + fun pathParams() { + val params = + TopicRetrieveParams.builder().sectionId("section_id").topicId("topic_id").build() + + assertThat(params._pathParam(0)).isEqualTo("section_id") + assertThat(params._pathParam(1)).isEqualTo("topic_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/PreferenceSectionServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/PreferenceSectionServiceAsyncTest.kt new file mode 100644 index 0000000..32a153e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/PreferenceSectionServiceAsyncTest.kt @@ -0,0 +1,105 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async + +import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.models.ChannelClassification +import com.courier.models.preferencesections.PreferenceSectionCreateRequest +import com.courier.models.preferencesections.PreferenceSectionReplaceParams +import com.courier.models.preferencesections.PreferenceSectionReplaceRequest +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class PreferenceSectionServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val preferenceSectionServiceAsync = client.preferenceSections() + + val preferenceSectionGetResponseFuture = + preferenceSectionServiceAsync.create( + PreferenceSectionCreateRequest.builder() + .name("Account Notifications") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + + val preferenceSectionGetResponse = preferenceSectionGetResponseFuture.get() + preferenceSectionGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val preferenceSectionServiceAsync = client.preferenceSections() + + val preferenceSectionGetResponseFuture = + preferenceSectionServiceAsync.retrieve("section_id") + + val preferenceSectionGetResponse = preferenceSectionGetResponseFuture.get() + preferenceSectionGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val preferenceSectionServiceAsync = client.preferenceSections() + + val preferenceSectionListResponseFuture = preferenceSectionServiceAsync.list() + + val preferenceSectionListResponse = preferenceSectionListResponseFuture.get() + preferenceSectionListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val preferenceSectionServiceAsync = client.preferenceSections() + + val future = preferenceSectionServiceAsync.archive("section_id") + + val response = future.get() + } + + @Disabled("Mock server tests are disabled") + @Test + fun publish() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val preferenceSectionServiceAsync = client.preferenceSections() + + val publishPreferencesResponseFuture = preferenceSectionServiceAsync.publish() + + val publishPreferencesResponse = publishPreferencesResponseFuture.get() + publishPreferencesResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun replace() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val preferenceSectionServiceAsync = client.preferenceSections() + + val preferenceSectionGetResponseFuture = + preferenceSectionServiceAsync.replace( + PreferenceSectionReplaceParams.builder() + .sectionId("section_id") + .preferenceSectionReplaceRequest( + PreferenceSectionReplaceRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + .build() + ) + + val preferenceSectionGetResponse = preferenceSectionGetResponseFuture.get() + preferenceSectionGetResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/preferencesections/TopicServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/preferencesections/TopicServiceAsyncTest.kt new file mode 100644 index 0000000..76bd4b1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/preferencesections/TopicServiceAsyncTest.kt @@ -0,0 +1,126 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.preferencesections + +import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.core.JsonValue +import com.courier.models.ChannelClassification +import com.courier.models.preferencesections.PreferenceTopicCreateRequest +import com.courier.models.preferencesections.PreferenceTopicReplaceRequest +import com.courier.models.preferencesections.topics.TopicArchiveParams +import com.courier.models.preferencesections.topics.TopicCreateParams +import com.courier.models.preferencesections.topics.TopicReplaceParams +import com.courier.models.preferencesections.topics.TopicRetrieveParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class TopicServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val topicServiceAsync = client.preferenceSections().topics() + + val preferenceTopicGetResponseFuture = + topicServiceAsync.create( + TopicCreateParams.builder() + .sectionId("section_id") + .preferenceTopicCreateRequest( + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("Marketing") + .addAllowedPreference( + PreferenceTopicCreateRequest.AllowedPreference.SNOOZE + ) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicCreateRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .build() + ) + + val preferenceTopicGetResponse = preferenceTopicGetResponseFuture.get() + preferenceTopicGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val topicServiceAsync = client.preferenceSections().topics() + + val preferenceTopicGetResponseFuture = + topicServiceAsync.retrieve( + TopicRetrieveParams.builder().sectionId("section_id").topicId("topic_id").build() + ) + + val preferenceTopicGetResponse = preferenceTopicGetResponseFuture.get() + preferenceTopicGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val topicServiceAsync = client.preferenceSections().topics() + + val preferenceTopicListResponseFuture = topicServiceAsync.list("section_id") + + val preferenceTopicListResponse = preferenceTopicListResponseFuture.get() + preferenceTopicListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val topicServiceAsync = client.preferenceSections().topics() + + val future = + topicServiceAsync.archive( + TopicArchiveParams.builder().sectionId("section_id").topicId("topic_id").build() + ) + + val response = future.get() + } + + @Disabled("Mock server tests are disabled") + @Test + fun replace() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val topicServiceAsync = client.preferenceSections().topics() + + val preferenceTopicGetResponseFuture = + topicServiceAsync.replace( + TopicReplaceParams.builder() + .sectionId("section_id") + .topicId("topic_id") + .preferenceTopicReplaceRequest( + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference( + PreferenceTopicReplaceRequest.AllowedPreference.SNOOZE + ) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicReplaceRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .build() + ) + + val preferenceTopicGetResponse = preferenceTopicGetResponseFuture.get() + preferenceTopicGetResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/PreferenceSectionServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/PreferenceSectionServiceTest.kt new file mode 100644 index 0000000..bfe7a64 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/PreferenceSectionServiceTest.kt @@ -0,0 +1,97 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking + +import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.models.ChannelClassification +import com.courier.models.preferencesections.PreferenceSectionCreateRequest +import com.courier.models.preferencesections.PreferenceSectionReplaceParams +import com.courier.models.preferencesections.PreferenceSectionReplaceRequest +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class PreferenceSectionServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val preferenceSectionService = client.preferenceSections() + + val preferenceSectionGetResponse = + preferenceSectionService.create( + PreferenceSectionCreateRequest.builder() + .name("Account Notifications") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + + preferenceSectionGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val preferenceSectionService = client.preferenceSections() + + val preferenceSectionGetResponse = preferenceSectionService.retrieve("section_id") + + preferenceSectionGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val preferenceSectionService = client.preferenceSections() + + val preferenceSectionListResponse = preferenceSectionService.list() + + preferenceSectionListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val preferenceSectionService = client.preferenceSections() + + preferenceSectionService.archive("section_id") + } + + @Disabled("Mock server tests are disabled") + @Test + fun publish() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val preferenceSectionService = client.preferenceSections() + + val publishPreferencesResponse = preferenceSectionService.publish() + + publishPreferencesResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun replace() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val preferenceSectionService = client.preferenceSections() + + val preferenceSectionGetResponse = + preferenceSectionService.replace( + PreferenceSectionReplaceParams.builder() + .sectionId("section_id") + .preferenceSectionReplaceRequest( + PreferenceSectionReplaceRequest.builder() + .name("name") + .hasCustomRouting(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .build() + ) + .build() + ) + + preferenceSectionGetResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/preferencesections/TopicServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/preferencesections/TopicServiceTest.kt new file mode 100644 index 0000000..f7ee355 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/preferencesections/TopicServiceTest.kt @@ -0,0 +1,119 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.preferencesections + +import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.core.JsonValue +import com.courier.models.ChannelClassification +import com.courier.models.preferencesections.PreferenceTopicCreateRequest +import com.courier.models.preferencesections.PreferenceTopicReplaceRequest +import com.courier.models.preferencesections.topics.TopicArchiveParams +import com.courier.models.preferencesections.topics.TopicCreateParams +import com.courier.models.preferencesections.topics.TopicReplaceParams +import com.courier.models.preferencesections.topics.TopicRetrieveParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class TopicServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val topicService = client.preferenceSections().topics() + + val preferenceTopicGetResponse = + topicService.create( + TopicCreateParams.builder() + .sectionId("section_id") + .preferenceTopicCreateRequest( + PreferenceTopicCreateRequest.builder() + .defaultStatus(PreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT) + .name("Marketing") + .addAllowedPreference( + PreferenceTopicCreateRequest.AllowedPreference.SNOOZE + ) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicCreateRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .build() + ) + + preferenceTopicGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val topicService = client.preferenceSections().topics() + + val preferenceTopicGetResponse = + topicService.retrieve( + TopicRetrieveParams.builder().sectionId("section_id").topicId("topic_id").build() + ) + + preferenceTopicGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val topicService = client.preferenceSections().topics() + + val preferenceTopicListResponse = topicService.list("section_id") + + preferenceTopicListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val topicService = client.preferenceSections().topics() + + topicService.archive( + TopicArchiveParams.builder().sectionId("section_id").topicId("topic_id").build() + ) + } + + @Disabled("Mock server tests are disabled") + @Test + fun replace() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val topicService = client.preferenceSections().topics() + + val preferenceTopicGetResponse = + topicService.replace( + TopicReplaceParams.builder() + .sectionId("section_id") + .topicId("topic_id") + .preferenceTopicReplaceRequest( + PreferenceTopicReplaceRequest.builder() + .defaultStatus(PreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT) + .name("name") + .addAllowedPreference( + PreferenceTopicReplaceRequest.AllowedPreference.SNOOZE + ) + .includeUnsubscribeHeader(true) + .addRoutingOption(ChannelClassification.DIRECT_MESSAGE) + .topicData( + PreferenceTopicReplaceRequest.TopicData.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .build() + ) + + preferenceTopicGetResponse.validate() + } +} diff --git a/courier-java-proguard-test/src/test/kotlin/com/courier/proguard/ProGuardCompatibilityTest.kt b/courier-java-proguard-test/src/test/kotlin/com/courier/proguard/ProGuardCompatibilityTest.kt index 5f8e6a7..9f8bf1d 100644 --- a/courier-java-proguard-test/src/test/kotlin/com/courier/proguard/ProGuardCompatibilityTest.kt +++ b/courier-java-proguard-test/src/test/kotlin/com/courier/proguard/ProGuardCompatibilityTest.kt @@ -66,6 +66,7 @@ internal class ProGuardCompatibilityTest { assertThat(client.requests()).isNotNull() assertThat(client.notifications()).isNotNull() assertThat(client.routingStrategies()).isNotNull() + assertThat(client.preferenceSections()).isNotNull() assertThat(client.profiles()).isNotNull() assertThat(client.tenants()).isNotNull() assertThat(client.translations()).isNotNull() From 9c77be70d0b9ddcec55d6d103951fa6307e0a920 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 22:15:38 +0000 Subject: [PATCH 2/2] release: 4.18.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ build.gradle.kts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 9e5024f..052d78b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.17.0" + ".": "4.18.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 40350a3..efe1483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 4.18.0 (2026-06-24) + +Full Changelog: [v4.17.0...v4.18.0](https://github.com/trycourier/courier-java/compare/v4.17.0...v4.18.0) + +### Features + +* **preferences:** workspace preference sections & nested topics endpoints ([a2e9d20](https://github.com/trycourier/courier-java/commit/a2e9d20128590a3a1487ef3ac17a53c647d9ea14)) + ## 4.17.0 (2026-06-23) Full Changelog: [v4.16.0...v4.17.0](https://github.com/trycourier/courier-java/compare/v4.16.0...v4.17.0) diff --git a/build.gradle.kts b/build.gradle.kts index ceaf13c..9853d04 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.courier" - version = "4.17.0" // x-release-please-version + version = "4.18.0" // x-release-please-version } subprojects {