diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7046597..c9acbd5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,14 @@ name: CI on: push: - branches-ignore: - - 'generated' - - 'codegen/**' - - 'integrated/**' - - 'stl-preview-head/**' - - 'stl-preview-base/**' + branches: + - '**' + - '!integrated/**' + - '!stl-preview-head/**' + - '!stl-preview-base/**' + - '!generated' + - '!codegen/**' + - 'codegen/stl/**' pull_request: branches-ignore: - 'stl-preview-head/**' @@ -17,7 +19,7 @@ jobs: timeout-minutes: 15 name: lint runs-on: ${{ github.repository == 'stainless-sdks/courier-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - uses: actions/checkout@v6 @@ -44,7 +46,7 @@ jobs: contents: read id-token: write runs-on: ${{ github.repository == 'stainless-sdks/courier-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - uses: actions/checkout@v6 diff --git a/.gitignore b/.gitignore index b1346e6d..90b85e94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .prism.log +.stdy.log .gradle .idea .kotlin diff --git a/.release-please-manifest.json b/.release-please-manifest.json index ad56a78c..a43b15a4 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.10.0" + ".": "4.11.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 75c12180..5c25f67e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 83 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier%2Fcourier-19330fca8fa9bbae835ec9d9f83b37b3df364d9b462090b9623bfc9b6eae99c2.yml -openapi_spec_hash: 0bc6889464c9ac2542b4837f569c1837 -config_hash: 1ae49ed522c8423378d9463cdd0fb880 +configured_endpoints: 94 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier%2Fcourier-52f1d2a99d3f91acc4753b05aeef4cc6e570d8e9a8c0a590a810a8d09d19688e.yml +openapi_spec_hash: 61caa60478d63f17515378910dd53b52 +config_hash: 65650c7f96740a3d80de689137a790b2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 712ef68f..6106d920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,35 @@ # Changelog +## 4.11.0 (2026-03-31) + +Full Changelog: [v4.10.0...v4.11.0](https://github.com/trycourier/courier-java/compare/v4.10.0...v4.11.0) + +### Features + +* **api:** add create/retrieve/archive/publish/replace methods, event_id param to notifications ([d0341ec](https://github.com/trycourier/courier-java/commit/d0341ecd91cd175c1fbd252f3f5caa4961a38a11)) +* **api:** add ElementalHtmlNodeWithType model, rename unionMember7 to htmlNodeWithType ([dd35a82](https://github.com/trycourier/courier-java/commit/dd35a82df01f09cf775a2a27640d76acc745ea07)) +* **api:** add routing strategies resource ([d2930ec](https://github.com/trycourier/courier-java/commit/d2930ec12c8d161ba14c4bc4e4c7b86fa8fdb450)) +* **api:** add UnionMember7 variant to ElementalNode ([7427c73](https://github.com/trycourier/courier-java/commit/7427c73d38e46ed9ef2a5535ab4f5de8422e962a)) + + +### Bug Fixes + +* **client:** allow updating header/query affecting fields in `toBuilder()` ([ed456e5](https://github.com/trycourier/courier-java/commit/ed456e5be6b63dd0c16ddf1e5c90dde476d4d7e5)) + + +### Chores + +* **ci:** skip lint on metadata-only changes ([2b3cd27](https://github.com/trycourier/courier-java/commit/2b3cd2798e31d09d6e0d329e3bb46f45a73c9aac)) +* **internal:** bump ktfmt ([affb7da](https://github.com/trycourier/courier-java/commit/affb7dae80ab5957a15a0b497dcf1afd3146eec7)) +* **internal:** tweak CI branches ([1bd9068](https://github.com/trycourier/courier-java/commit/1bd906869c298547c59c2ffbc0f0ef0e37958206)) +* **internal:** update gitignore ([d801bca](https://github.com/trycourier/courier-java/commit/d801bca833d04aa2adb2f9bb4df7b6777cfb022a)) +* **internal:** update retry delay tests ([e3ecdf0](https://github.com/trycourier/courier-java/commit/e3ecdf0b1b898a83eb234cb289db18e51cfd8982)) + + +### Documentation + +* sync README from mintlify-docs (2026-03-23 19:31 UTC) ([#95](https://github.com/trycourier/courier-java/issues/95)) ([8efc854](https://github.com/trycourier/courier-java/commit/8efc8542cbe37b8ba7673d53a37995625e574785)) + ## 4.10.0 (2026-03-12) Full Changelog: [v4.9.1...v4.10.0](https://github.com/trycourier/courier-java/compare/v4.9.1...v4.10.0) diff --git a/build.gradle.kts b/build.gradle.kts index 653fe829..16f27348 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.courier" - version = "4.10.0" // x-release-please-version + version = "4.11.0" // x-release-please-version } subprojects { diff --git a/buildSrc/src/main/kotlin/courier.kotlin.gradle.kts b/buildSrc/src/main/kotlin/courier.kotlin.gradle.kts index 9de64f25..28ed4760 100644 --- a/buildSrc/src/main/kotlin/courier.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/courier.kotlin.gradle.kts @@ -40,7 +40,7 @@ tasks.withType().configureEach { val ktfmt by configurations.creating dependencies { - ktfmt("com.facebook:ktfmt:0.56") + ktfmt("com.facebook:ktfmt:0.61") } fun registerKtfmt( 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 3f4207eb..4e1fe814 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 @@ -16,6 +16,7 @@ import com.courier.services.blocking.MessageService import com.courier.services.blocking.NotificationService import com.courier.services.blocking.ProfileService import com.courier.services.blocking.RequestService +import com.courier.services.blocking.RoutingStrategyService import com.courier.services.blocking.SendService import com.courier.services.blocking.TenantService import com.courier.services.blocking.TranslationService @@ -84,6 +85,8 @@ interface CourierClient { fun notifications(): NotificationService + fun routingStrategies(): RoutingStrategyService + fun profiles(): ProfileService fun tenants(): TenantService @@ -141,6 +144,8 @@ interface CourierClient { fun notifications(): NotificationService.WithRawResponse + fun routingStrategies(): RoutingStrategyService.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 facdb00c..ed65e6eb 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 @@ -16,6 +16,7 @@ import com.courier.services.async.MessageServiceAsync import com.courier.services.async.NotificationServiceAsync import com.courier.services.async.ProfileServiceAsync import com.courier.services.async.RequestServiceAsync +import com.courier.services.async.RoutingStrategyServiceAsync import com.courier.services.async.SendServiceAsync import com.courier.services.async.TenantServiceAsync import com.courier.services.async.TranslationServiceAsync @@ -84,6 +85,8 @@ interface CourierClientAsync { fun notifications(): NotificationServiceAsync + fun routingStrategies(): RoutingStrategyServiceAsync + fun profiles(): ProfileServiceAsync fun tenants(): TenantServiceAsync @@ -145,6 +148,8 @@ interface CourierClientAsync { fun notifications(): NotificationServiceAsync.WithRawResponse + fun routingStrategies(): RoutingStrategyServiceAsync.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 a540243c..f48aeb10 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 @@ -30,6 +30,8 @@ import com.courier.services.async.ProfileServiceAsync import com.courier.services.async.ProfileServiceAsyncImpl import com.courier.services.async.RequestServiceAsync import com.courier.services.async.RequestServiceAsyncImpl +import com.courier.services.async.RoutingStrategyServiceAsync +import com.courier.services.async.RoutingStrategyServiceAsyncImpl import com.courier.services.async.SendServiceAsync import com.courier.services.async.SendServiceAsyncImpl import com.courier.services.async.TenantServiceAsync @@ -101,6 +103,10 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier NotificationServiceAsyncImpl(clientOptionsWithUserAgent) } + private val routingStrategies: RoutingStrategyServiceAsync by lazy { + RoutingStrategyServiceAsyncImpl(clientOptionsWithUserAgent) + } + private val profiles: ProfileServiceAsync by lazy { ProfileServiceAsyncImpl(clientOptionsWithUserAgent) } @@ -148,6 +154,8 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier override fun notifications(): NotificationServiceAsync = notifications + override fun routingStrategies(): RoutingStrategyServiceAsync = routingStrategies + override fun profiles(): ProfileServiceAsync = profiles override fun tenants(): TenantServiceAsync = tenants @@ -213,6 +221,10 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier NotificationServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val routingStrategies: RoutingStrategyServiceAsync.WithRawResponse by lazy { + RoutingStrategyServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val profiles: ProfileServiceAsync.WithRawResponse by lazy { ProfileServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -262,6 +274,9 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier override fun notifications(): NotificationServiceAsync.WithRawResponse = notifications + override fun routingStrategies(): RoutingStrategyServiceAsync.WithRawResponse = + routingStrategies + 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 2ab15a6c..2dd962d9 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 @@ -30,6 +30,8 @@ import com.courier.services.blocking.ProfileService import com.courier.services.blocking.ProfileServiceImpl import com.courier.services.blocking.RequestService import com.courier.services.blocking.RequestServiceImpl +import com.courier.services.blocking.RoutingStrategyService +import com.courier.services.blocking.RoutingStrategyServiceImpl import com.courier.services.blocking.SendService import com.courier.services.blocking.SendServiceImpl import com.courier.services.blocking.TenantService @@ -91,6 +93,10 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien NotificationServiceImpl(clientOptionsWithUserAgent) } + private val routingStrategies: RoutingStrategyService by lazy { + RoutingStrategyServiceImpl(clientOptionsWithUserAgent) + } + private val profiles: ProfileService by lazy { ProfileServiceImpl(clientOptionsWithUserAgent) } private val tenants: TenantService by lazy { TenantServiceImpl(clientOptionsWithUserAgent) } @@ -134,6 +140,8 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien override fun notifications(): NotificationService = notifications + override fun routingStrategies(): RoutingStrategyService = routingStrategies + override fun profiles(): ProfileService = profiles override fun tenants(): TenantService = tenants @@ -199,6 +207,10 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien NotificationServiceImpl.WithRawResponseImpl(clientOptions) } + private val routingStrategies: RoutingStrategyService.WithRawResponse by lazy { + RoutingStrategyServiceImpl.WithRawResponseImpl(clientOptions) + } + private val profiles: ProfileService.WithRawResponse by lazy { ProfileServiceImpl.WithRawResponseImpl(clientOptions) } @@ -248,6 +260,8 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien override fun notifications(): NotificationService.WithRawResponse = notifications + override fun routingStrategies(): RoutingStrategyService.WithRawResponse = routingStrategies + override fun profiles(): ProfileService.WithRawResponse = profiles override fun tenants(): TenantService.WithRawResponse = tenants diff --git a/courier-java-core/src/main/kotlin/com/courier/core/ClientOptions.kt b/courier-java-core/src/main/kotlin/com/courier/core/ClientOptions.kt index 122fde64..bee20967 100644 --- a/courier-java-core/src/main/kotlin/com/courier/core/ClientOptions.kt +++ b/courier-java-core/src/main/kotlin/com/courier/core/ClientOptions.kt @@ -403,13 +403,14 @@ private constructor( headers.put("X-Stainless-Runtime", "JRE") headers.put("X-Stainless-Runtime-Version", getJavaVersion()) headers.put("X-Stainless-Kotlin-Version", KotlinVersion.CURRENT.toString()) + // We replace after all the default headers to allow end-users to overwrite them. + headers.replaceAll(this.headers.build()) + queryParams.replaceAll(this.queryParams.build()) apiKey.let { if (!it.isEmpty()) { - headers.put("Authorization", "Bearer $it") + headers.replace("Authorization", "Bearer $it") } } - headers.replaceAll(this.headers.build()) - queryParams.replaceAll(this.queryParams.build()) return ClientOptions( httpClient, diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Channel.kt b/courier-java-core/src/main/kotlin/com/courier/models/Channel.kt new file mode 100644 index 00000000..0e6cb9bd --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Channel.kt @@ -0,0 +1,656 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +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.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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class Channel +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val brandId: JsonField, + private val if_: JsonField, + private val metadata: JsonField, + private val override: JsonField, + private val providers: JsonField>, + private val routingMethod: JsonField, + private val timeouts: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("brand_id") @ExcludeMissing brandId: JsonField = JsonMissing.of(), + @JsonProperty("if") @ExcludeMissing if_: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("override") @ExcludeMissing override: JsonField = JsonMissing.of(), + @JsonProperty("providers") + @ExcludeMissing + providers: JsonField> = JsonMissing.of(), + @JsonProperty("routing_method") + @ExcludeMissing + routingMethod: JsonField = JsonMissing.of(), + @JsonProperty("timeouts") @ExcludeMissing timeouts: JsonField = JsonMissing.of(), + ) : this(brandId, if_, metadata, override, providers, routingMethod, timeouts, mutableMapOf()) + + /** + * Brand id used for rendering. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun brandId(): Optional = brandId.getOptional("brand_id") + + /** + * JS conditional with access to data/profile. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun if_(): Optional = if_.getOptional("if") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Channel specific overrides. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun override(): Optional = override.getOptional("override") + + /** + * Providers enabled for this channel. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun providers(): Optional> = providers.getOptional("providers") + + /** + * Defaults to `single`. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun routingMethod(): Optional = routingMethod.getOptional("routing_method") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun timeouts(): Optional = timeouts.getOptional("timeouts") + + /** + * Returns the raw JSON value of [brandId]. + * + * Unlike [brandId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("brand_id") @ExcludeMissing fun _brandId(): JsonField = brandId + + /** + * Returns the raw JSON value of [if_]. + * + * Unlike [if_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("if") @ExcludeMissing fun _if_(): JsonField = if_ + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [override]. + * + * Unlike [override], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("override") @ExcludeMissing fun _override(): JsonField = override + + /** + * Returns the raw JSON value of [providers]. + * + * Unlike [providers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("providers") @ExcludeMissing fun _providers(): JsonField> = providers + + /** + * Returns the raw JSON value of [routingMethod]. + * + * Unlike [routingMethod], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing_method") + @ExcludeMissing + fun _routingMethod(): JsonField = routingMethod + + /** + * Returns the raw JSON value of [timeouts]. + * + * Unlike [timeouts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("timeouts") @ExcludeMissing fun _timeouts(): JsonField = timeouts + + @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 [Channel]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Channel]. */ + class Builder internal constructor() { + + private var brandId: JsonField = JsonMissing.of() + private var if_: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var override: JsonField = JsonMissing.of() + private var providers: JsonField>? = null + private var routingMethod: JsonField = JsonMissing.of() + private var timeouts: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(channel: Channel) = apply { + brandId = channel.brandId + if_ = channel.if_ + metadata = channel.metadata + override = channel.override + providers = channel.providers.map { it.toMutableList() } + routingMethod = channel.routingMethod + timeouts = channel.timeouts + additionalProperties = channel.additionalProperties.toMutableMap() + } + + /** Brand id used for rendering. */ + fun brandId(brandId: String?) = brandId(JsonField.ofNullable(brandId)) + + /** Alias for calling [Builder.brandId] with `brandId.orElse(null)`. */ + fun brandId(brandId: Optional) = brandId(brandId.getOrNull()) + + /** + * Sets [Builder.brandId] to an arbitrary JSON value. + * + * You should usually call [Builder.brandId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun brandId(brandId: JsonField) = apply { this.brandId = brandId } + + /** JS conditional with access to data/profile. */ + fun if_(if_: String?) = if_(JsonField.ofNullable(if_)) + + /** Alias for calling [Builder.if_] with `if_.orElse(null)`. */ + fun if_(if_: Optional) = if_(if_.getOrNull()) + + /** + * Sets [Builder.if_] to an arbitrary JSON value. + * + * You should usually call [Builder.if_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun if_(if_: JsonField) = apply { this.if_ = if_ } + + fun metadata(metadata: ChannelMetadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [ChannelMetadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** Channel specific overrides. */ + fun override(override: Override?) = override(JsonField.ofNullable(override)) + + /** Alias for calling [Builder.override] with `override.orElse(null)`. */ + fun override(override: Optional) = override(override.getOrNull()) + + /** + * Sets [Builder.override] to an arbitrary JSON value. + * + * You should usually call [Builder.override] with a well-typed [Override] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun override(override: JsonField) = apply { this.override = override } + + /** Providers enabled for this channel. */ + fun providers(providers: List?) = providers(JsonField.ofNullable(providers)) + + /** Alias for calling [Builder.providers] with `providers.orElse(null)`. */ + fun providers(providers: Optional>) = providers(providers.getOrNull()) + + /** + * Sets [Builder.providers] to an arbitrary JSON value. + * + * You should usually call [Builder.providers] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun providers(providers: JsonField>) = apply { + this.providers = providers.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [providers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addProvider(provider: String) = apply { + providers = + (providers ?: JsonField.of(mutableListOf())).also { + checkKnown("providers", it).add(provider) + } + } + + /** Defaults to `single`. */ + fun routingMethod(routingMethod: RoutingMethod?) = + routingMethod(JsonField.ofNullable(routingMethod)) + + /** Alias for calling [Builder.routingMethod] with `routingMethod.orElse(null)`. */ + fun routingMethod(routingMethod: Optional) = + routingMethod(routingMethod.getOrNull()) + + /** + * Sets [Builder.routingMethod] to an arbitrary JSON value. + * + * You should usually call [Builder.routingMethod] with a well-typed [RoutingMethod] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun routingMethod(routingMethod: JsonField) = apply { + this.routingMethod = routingMethod + } + + fun timeouts(timeouts: Timeouts?) = timeouts(JsonField.ofNullable(timeouts)) + + /** Alias for calling [Builder.timeouts] with `timeouts.orElse(null)`. */ + fun timeouts(timeouts: Optional) = timeouts(timeouts.getOrNull()) + + /** + * Sets [Builder.timeouts] to an arbitrary JSON value. + * + * You should usually call [Builder.timeouts] with a well-typed [Timeouts] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun timeouts(timeouts: JsonField) = apply { this.timeouts = timeouts } + + 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 [Channel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Channel = + Channel( + brandId, + if_, + metadata, + override, + (providers ?: JsonMissing.of()).map { it.toImmutable() }, + routingMethod, + timeouts, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Channel = apply { + if (validated) { + return@apply + } + + brandId() + if_() + metadata().ifPresent { it.validate() } + override().ifPresent { it.validate() } + providers() + routingMethod().ifPresent { it.validate() } + timeouts().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 = + (if (brandId.asKnown().isPresent) 1 else 0) + + (if (if_.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (override.asKnown().getOrNull()?.validity() ?: 0) + + (providers.asKnown().getOrNull()?.size ?: 0) + + (routingMethod.asKnown().getOrNull()?.validity() ?: 0) + + (timeouts.asKnown().getOrNull()?.validity() ?: 0) + + /** Channel specific overrides. */ + class Override + @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 [Override]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Override]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(override: Override) = apply { + additionalProperties = override.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 [Override]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Override = Override(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Override = 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 Override && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Override{additionalProperties=$additionalProperties}" + } + + /** Defaults to `single`. */ + class RoutingMethod @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 ALL = of("all") + + @JvmField val SINGLE = of("single") + + @JvmStatic fun of(value: String) = RoutingMethod(JsonField.of(value)) + } + + /** An enum containing [RoutingMethod]'s known values. */ + enum class Known { + ALL, + SINGLE, + } + + /** + * An enum containing [RoutingMethod]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [RoutingMethod] 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 { + ALL, + SINGLE, + /** + * An enum member indicating that [RoutingMethod] 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) { + ALL -> Value.ALL + SINGLE -> Value.SINGLE + 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) { + ALL -> Known.ALL + SINGLE -> Known.SINGLE + else -> throw CourierInvalidDataException("Unknown RoutingMethod: $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 + + fun validate(): RoutingMethod = 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 RoutingMethod && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Channel && + brandId == other.brandId && + if_ == other.if_ && + metadata == other.metadata && + override == other.override && + providers == other.providers && + routingMethod == other.routingMethod && + timeouts == other.timeouts && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + brandId, + if_, + metadata, + override, + providers, + routingMethod, + timeouts, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Channel{brandId=$brandId, if_=$if_, metadata=$metadata, override=$override, providers=$providers, routingMethod=$routingMethod, timeouts=$timeouts, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/ChannelMetadata.kt b/courier-java-core/src/main/kotlin/com/courier/models/ChannelMetadata.kt new file mode 100644 index 00000000..4fafde66 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/ChannelMetadata.kt @@ -0,0 +1,156 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +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 + +class ChannelMetadata +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val utm: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("utm") @ExcludeMissing utm: JsonField = JsonMissing.of() + ) : this(utm, mutableMapOf()) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun utm(): Optional = utm.getOptional("utm") + + /** + * Returns the raw JSON value of [utm]. + * + * Unlike [utm], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("utm") @ExcludeMissing fun _utm(): JsonField = utm + + @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 [ChannelMetadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChannelMetadata]. */ + class Builder internal constructor() { + + private var utm: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(channelMetadata: ChannelMetadata) = apply { + utm = channelMetadata.utm + additionalProperties = channelMetadata.additionalProperties.toMutableMap() + } + + fun utm(utm: Utm?) = utm(JsonField.ofNullable(utm)) + + /** Alias for calling [Builder.utm] with `utm.orElse(null)`. */ + fun utm(utm: Optional) = utm(utm.getOrNull()) + + /** + * Sets [Builder.utm] to an arbitrary JSON value. + * + * You should usually call [Builder.utm] with a well-typed [Utm] value instead. This method + * is primarily for setting the field to an undocumented or not yet supported value. + */ + fun utm(utm: JsonField) = apply { this.utm = utm } + + 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 [ChannelMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChannelMetadata = ChannelMetadata(utm, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ChannelMetadata = apply { + if (validated) { + return@apply + } + + utm().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 = (utm.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChannelMetadata && + utm == other.utm && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(utm, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChannelMetadata{utm=$utm, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/ElementalContent.kt b/courier-java-core/src/main/kotlin/com/courier/models/ElementalContent.kt index e3659f80..037a7b41 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/ElementalContent.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/ElementalContent.kt @@ -176,6 +176,12 @@ private constructor( fun addElement(quoteNodeWithType: ElementalQuoteNodeWithType) = addElement(ElementalNode.ofQuoteNodeWithType(quoteNodeWithType)) + /** + * Alias for calling [addElement] with `ElementalNode.ofHtmlNodeWithType(htmlNodeWithType)`. + */ + fun addElement(htmlNodeWithType: ElementalHtmlNodeWithType) = + addElement(ElementalNode.ofHtmlNodeWithType(htmlNodeWithType)) + /** For example, "2022-01-01" */ fun version(version: String) = version(JsonField.of(version)) diff --git a/courier-java-core/src/main/kotlin/com/courier/models/ElementalHtmlNodeWithType.kt b/courier-java-core/src/main/kotlin/com/courier/models/ElementalHtmlNodeWithType.kt new file mode 100644 index 00000000..ad21b6ed --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/ElementalHtmlNodeWithType.kt @@ -0,0 +1,441 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +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.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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class ElementalHtmlNodeWithType +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val channels: JsonField>, + private val if_: JsonField, + private val loop: JsonField, + private val ref: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("channels") + @ExcludeMissing + channels: JsonField> = JsonMissing.of(), + @JsonProperty("if") @ExcludeMissing if_: JsonField = JsonMissing.of(), + @JsonProperty("loop") @ExcludeMissing loop: JsonField = JsonMissing.of(), + @JsonProperty("ref") @ExcludeMissing ref: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(channels, if_, loop, ref, type, mutableMapOf()) + + fun toElementalBaseNode(): ElementalBaseNode = + ElementalBaseNode.builder().channels(channels).if_(if_).loop(loop).ref(ref).build() + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun channels(): Optional> = channels.getOptional("channels") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun if_(): Optional = if_.getOptional("if") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun loop(): Optional = loop.getOptional("loop") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun ref(): Optional = ref.getOptional("ref") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [channels]. + * + * Unlike [channels], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channels") @ExcludeMissing fun _channels(): JsonField> = channels + + /** + * Returns the raw JSON value of [if_]. + * + * Unlike [if_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("if") @ExcludeMissing fun _if_(): JsonField = if_ + + /** + * Returns the raw JSON value of [loop]. + * + * Unlike [loop], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("loop") @ExcludeMissing fun _loop(): JsonField = loop + + /** + * Returns the raw JSON value of [ref]. + * + * Unlike [ref], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("ref") @ExcludeMissing fun _ref(): JsonField = ref + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @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 [ElementalHtmlNodeWithType]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ElementalHtmlNodeWithType]. */ + class Builder internal constructor() { + + private var channels: JsonField>? = null + private var if_: JsonField = JsonMissing.of() + private var loop: JsonField = JsonMissing.of() + private var ref: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(elementalHtmlNodeWithType: ElementalHtmlNodeWithType) = apply { + channels = elementalHtmlNodeWithType.channels.map { it.toMutableList() } + if_ = elementalHtmlNodeWithType.if_ + loop = elementalHtmlNodeWithType.loop + ref = elementalHtmlNodeWithType.ref + type = elementalHtmlNodeWithType.type + additionalProperties = elementalHtmlNodeWithType.additionalProperties.toMutableMap() + } + + fun channels(channels: List?) = channels(JsonField.ofNullable(channels)) + + /** Alias for calling [Builder.channels] with `channels.orElse(null)`. */ + fun channels(channels: Optional>) = channels(channels.getOrNull()) + + /** + * Sets [Builder.channels] to an arbitrary JSON value. + * + * You should usually call [Builder.channels] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun channels(channels: JsonField>) = apply { + this.channels = channels.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [channels]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addChannel(channel: String) = apply { + channels = + (channels ?: JsonField.of(mutableListOf())).also { + checkKnown("channels", it).add(channel) + } + } + + fun if_(if_: String?) = if_(JsonField.ofNullable(if_)) + + /** Alias for calling [Builder.if_] with `if_.orElse(null)`. */ + fun if_(if_: Optional) = if_(if_.getOrNull()) + + /** + * Sets [Builder.if_] to an arbitrary JSON value. + * + * You should usually call [Builder.if_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun if_(if_: JsonField) = apply { this.if_ = if_ } + + fun loop(loop: String?) = loop(JsonField.ofNullable(loop)) + + /** Alias for calling [Builder.loop] with `loop.orElse(null)`. */ + fun loop(loop: Optional) = loop(loop.getOrNull()) + + /** + * Sets [Builder.loop] to an arbitrary JSON value. + * + * You should usually call [Builder.loop] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun loop(loop: JsonField) = apply { this.loop = loop } + + fun ref(ref: String?) = ref(JsonField.ofNullable(ref)) + + /** Alias for calling [Builder.ref] with `ref.orElse(null)`. */ + fun ref(ref: Optional) = ref(ref.getOrNull()) + + /** + * Sets [Builder.ref] to an arbitrary JSON value. + * + * You should usually call [Builder.ref] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun ref(ref: JsonField) = apply { this.ref = ref } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + 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 [ElementalHtmlNodeWithType]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ElementalHtmlNodeWithType = + ElementalHtmlNodeWithType( + (channels ?: JsonMissing.of()).map { it.toImmutable() }, + if_, + loop, + ref, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ElementalHtmlNodeWithType = apply { + if (validated) { + return@apply + } + + channels() + if_() + loop() + ref() + type().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 = + (channels.asKnown().getOrNull()?.size ?: 0) + + (if (if_.asKnown().isPresent) 1 else 0) + + (if (loop.asKnown().isPresent) 1 else 0) + + (if (ref.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Type @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 HTML = of("html") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + HTML + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] 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 { + HTML, + /** An enum member indicating that [Type] 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) { + HTML -> Value.HTML + 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) { + HTML -> Known.HTML + else -> throw CourierInvalidDataException("Unknown Type: $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 + + fun validate(): Type = 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 Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ElementalHtmlNodeWithType && + channels == other.channels && + if_ == other.if_ && + loop == other.loop && + ref == other.ref && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(channels, if_, loop, ref, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ElementalHtmlNodeWithType{channels=$channels, if_=$if_, loop=$loop, ref=$ref, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/ElementalNode.kt b/courier-java-core/src/main/kotlin/com/courier/models/ElementalNode.kt index fdca3746..86580b8e 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/ElementalNode.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/ElementalNode.kt @@ -40,6 +40,7 @@ private constructor( private val actionNodeWithType: ElementalActionNodeWithType? = null, private val dividerNodeWithType: ElementalDividerNodeWithType? = null, private val quoteNodeWithType: ElementalQuoteNodeWithType? = null, + private val htmlNodeWithType: ElementalHtmlNodeWithType? = null, private val _json: JsonValue? = null, ) { @@ -75,6 +76,9 @@ private constructor( fun quoteNodeWithType(): Optional = Optional.ofNullable(quoteNodeWithType) + fun htmlNodeWithType(): Optional = + Optional.ofNullable(htmlNodeWithType) + fun isTextNodeWithType(): Boolean = textNodeWithType != null fun isMetaNodeWithType(): Boolean = metaNodeWithType != null @@ -89,6 +93,8 @@ private constructor( fun isQuoteNodeWithType(): Boolean = quoteNodeWithType != null + fun isHtmlNodeWithType(): Boolean = htmlNodeWithType != null + fun asTextNodeWithType(): ElementalTextNodeWithType = textNodeWithType.getOrThrow("textNodeWithType") @@ -121,6 +127,9 @@ private constructor( fun asQuoteNodeWithType(): ElementalQuoteNodeWithType = quoteNodeWithType.getOrThrow("quoteNodeWithType") + fun asHtmlNodeWithType(): ElementalHtmlNodeWithType = + htmlNodeWithType.getOrThrow("htmlNodeWithType") + fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = @@ -132,6 +141,7 @@ private constructor( actionNodeWithType != null -> visitor.visitActionNodeWithType(actionNodeWithType) dividerNodeWithType != null -> visitor.visitDividerNodeWithType(dividerNodeWithType) quoteNodeWithType != null -> visitor.visitQuoteNodeWithType(quoteNodeWithType) + htmlNodeWithType != null -> visitor.visitHtmlNodeWithType(htmlNodeWithType) else -> visitor.unknown(_json) } @@ -177,6 +187,10 @@ private constructor( override fun visitQuoteNodeWithType(quoteNodeWithType: ElementalQuoteNodeWithType) { quoteNodeWithType.validate() } + + override fun visitHtmlNodeWithType(htmlNodeWithType: ElementalHtmlNodeWithType) { + htmlNodeWithType.validate() + } } ) validated = true @@ -223,6 +237,9 @@ private constructor( override fun visitQuoteNodeWithType(quoteNodeWithType: ElementalQuoteNodeWithType) = quoteNodeWithType.validity() + override fun visitHtmlNodeWithType(htmlNodeWithType: ElementalHtmlNodeWithType) = + htmlNodeWithType.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -239,7 +256,8 @@ private constructor( imageNodeWithType == other.imageNodeWithType && actionNodeWithType == other.actionNodeWithType && dividerNodeWithType == other.dividerNodeWithType && - quoteNodeWithType == other.quoteNodeWithType + quoteNodeWithType == other.quoteNodeWithType && + htmlNodeWithType == other.htmlNodeWithType } override fun hashCode(): Int = @@ -251,6 +269,7 @@ private constructor( actionNodeWithType, dividerNodeWithType, quoteNodeWithType, + htmlNodeWithType, ) override fun toString(): String = @@ -262,6 +281,7 @@ private constructor( actionNodeWithType != null -> "ElementalNode{actionNodeWithType=$actionNodeWithType}" dividerNodeWithType != null -> "ElementalNode{dividerNodeWithType=$dividerNodeWithType}" quoteNodeWithType != null -> "ElementalNode{quoteNodeWithType=$quoteNodeWithType}" + htmlNodeWithType != null -> "ElementalNode{htmlNodeWithType=$htmlNodeWithType}" _json != null -> "ElementalNode{_unknown=$_json}" else -> throw IllegalStateException("Invalid ElementalNode") } @@ -307,6 +327,10 @@ private constructor( @JvmStatic fun ofQuoteNodeWithType(quoteNodeWithType: ElementalQuoteNodeWithType) = ElementalNode(quoteNodeWithType = quoteNodeWithType) + + @JvmStatic + fun ofHtmlNodeWithType(htmlNodeWithType: ElementalHtmlNodeWithType) = + ElementalNode(htmlNodeWithType = htmlNodeWithType) } /** @@ -340,6 +364,8 @@ private constructor( fun visitQuoteNodeWithType(quoteNodeWithType: ElementalQuoteNodeWithType): T + fun visitHtmlNodeWithType(htmlNodeWithType: ElementalHtmlNodeWithType): T + /** * Maps an unknown variant of [ElementalNode] to a value of type [T]. * @@ -382,6 +408,9 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { ElementalNode(quoteNodeWithType = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + ElementalNode(htmlNodeWithType = it, _json = json) + }, ) .filterNotNull() .allMaxBy { it.validity() } @@ -415,6 +444,7 @@ private constructor( value.dividerNodeWithType != null -> generator.writeObject(value.dividerNodeWithType) value.quoteNodeWithType != null -> generator.writeObject(value.quoteNodeWithType) + value.htmlNodeWithType != null -> generator.writeObject(value.htmlNodeWithType) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid ElementalNode") } diff --git a/courier-java-core/src/main/kotlin/com/courier/models/MessageChannels.kt b/courier-java-core/src/main/kotlin/com/courier/models/MessageChannels.kt new file mode 100644 index 00000000..b685599d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/MessageChannels.kt @@ -0,0 +1,109 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonValue +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonCreator +import java.util.Objects + +class MessageChannels +@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 [MessageChannels]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MessageChannels]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(messageChannels: MessageChannels) = apply { + additionalProperties = messageChannels.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 [MessageChannels]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): MessageChannels = MessageChannels(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): MessageChannels = 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 MessageChannels && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "MessageChannels{additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/MessageProviders.kt b/courier-java-core/src/main/kotlin/com/courier/models/MessageProviders.kt new file mode 100644 index 00000000..00aab85b --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/MessageProviders.kt @@ -0,0 +1,109 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonValue +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonCreator +import java.util.Objects + +class MessageProviders +@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 [MessageProviders]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MessageProviders]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(messageProviders: MessageProviders) = apply { + additionalProperties = messageProviders.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 [MessageProviders]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): MessageProviders = MessageProviders(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): MessageProviders = 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 MessageProviders && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "MessageProviders{additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/MessageProvidersType.kt b/courier-java-core/src/main/kotlin/com/courier/models/MessageProvidersType.kt new file mode 100644 index 00000000..fb44a55f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/MessageProvidersType.kt @@ -0,0 +1,382 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class MessageProvidersType +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val if_: JsonField, + private val metadata: JsonField, + private val override: JsonField, + private val timeouts: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("if") @ExcludeMissing if_: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("override") @ExcludeMissing override: JsonField = JsonMissing.of(), + @JsonProperty("timeouts") @ExcludeMissing timeouts: JsonField = JsonMissing.of(), + ) : this(if_, metadata, override, timeouts, mutableMapOf()) + + /** + * JS conditional with access to data/profile. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun if_(): Optional = if_.getOptional("if") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Provider-specific overrides. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun override(): Optional = override.getOptional("override") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun timeouts(): Optional = timeouts.getOptional("timeouts") + + /** + * Returns the raw JSON value of [if_]. + * + * Unlike [if_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("if") @ExcludeMissing fun _if_(): JsonField = if_ + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [override]. + * + * Unlike [override], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("override") @ExcludeMissing fun _override(): JsonField = override + + /** + * Returns the raw JSON value of [timeouts]. + * + * Unlike [timeouts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("timeouts") @ExcludeMissing fun _timeouts(): JsonField = timeouts + + @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 [MessageProvidersType]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MessageProvidersType]. */ + class Builder internal constructor() { + + private var if_: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var override: JsonField = JsonMissing.of() + private var timeouts: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(messageProvidersType: MessageProvidersType) = apply { + if_ = messageProvidersType.if_ + metadata = messageProvidersType.metadata + override = messageProvidersType.override + timeouts = messageProvidersType.timeouts + additionalProperties = messageProvidersType.additionalProperties.toMutableMap() + } + + /** JS conditional with access to data/profile. */ + fun if_(if_: String?) = if_(JsonField.ofNullable(if_)) + + /** Alias for calling [Builder.if_] with `if_.orElse(null)`. */ + fun if_(if_: Optional) = if_(if_.getOrNull()) + + /** + * Sets [Builder.if_] to an arbitrary JSON value. + * + * You should usually call [Builder.if_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun if_(if_: JsonField) = apply { this.if_ = if_ } + + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** Provider-specific overrides. */ + fun override(override: Override?) = override(JsonField.ofNullable(override)) + + /** Alias for calling [Builder.override] with `override.orElse(null)`. */ + fun override(override: Optional) = override(override.getOrNull()) + + /** + * Sets [Builder.override] to an arbitrary JSON value. + * + * You should usually call [Builder.override] with a well-typed [Override] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun override(override: JsonField) = apply { this.override = override } + + fun timeouts(timeouts: Long?) = timeouts(JsonField.ofNullable(timeouts)) + + /** + * Alias for [Builder.timeouts]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun timeouts(timeouts: Long) = timeouts(timeouts as Long?) + + /** Alias for calling [Builder.timeouts] with `timeouts.orElse(null)`. */ + fun timeouts(timeouts: Optional) = timeouts(timeouts.getOrNull()) + + /** + * Sets [Builder.timeouts] to an arbitrary JSON value. + * + * You should usually call [Builder.timeouts] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun timeouts(timeouts: JsonField) = apply { this.timeouts = timeouts } + + 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 [MessageProvidersType]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): MessageProvidersType = + MessageProvidersType( + if_, + metadata, + override, + timeouts, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MessageProvidersType = apply { + if (validated) { + return@apply + } + + if_() + metadata().ifPresent { it.validate() } + override().ifPresent { it.validate() } + timeouts() + 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 (if_.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (override.asKnown().getOrNull()?.validity() ?: 0) + + (if (timeouts.asKnown().isPresent) 1 else 0) + + /** Provider-specific overrides. */ + class Override + @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 [Override]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Override]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(override: Override) = apply { + additionalProperties = override.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 [Override]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Override = Override(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Override = 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 Override && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Override{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MessageProvidersType && + if_ == other.if_ && + metadata == other.metadata && + override == other.override && + timeouts == other.timeouts && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(if_, metadata, override, timeouts, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MessageProvidersType{if_=$if_, metadata=$metadata, override=$override, timeouts=$timeouts, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Metadata.kt b/courier-java-core/src/main/kotlin/com/courier/models/Metadata.kt new file mode 100644 index 00000000..850328ce --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Metadata.kt @@ -0,0 +1,155 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +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 + +class Metadata +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val utm: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("utm") @ExcludeMissing utm: JsonField = JsonMissing.of() + ) : this(utm, mutableMapOf()) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun utm(): Optional = utm.getOptional("utm") + + /** + * Returns the raw JSON value of [utm]. + * + * Unlike [utm], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("utm") @ExcludeMissing fun _utm(): JsonField = utm + + @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 [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var utm: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + utm = metadata.utm + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun utm(utm: Utm?) = utm(JsonField.ofNullable(utm)) + + /** Alias for calling [Builder.utm] with `utm.orElse(null)`. */ + fun utm(utm: Optional) = utm(utm.getOrNull()) + + /** + * Sets [Builder.utm] to an arbitrary JSON value. + * + * You should usually call [Builder.utm] with a well-typed [Utm] value instead. This method + * is primarily for setting the field to an undocumented or not yet supported value. + */ + fun utm(utm: JsonField) = apply { this.utm = utm } + + 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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(utm, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + utm().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 = (utm.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && + utm == other.utm && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(utm, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{utm=$utm, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Timeouts.kt b/courier-java-core/src/main/kotlin/com/courier/models/Timeouts.kt new file mode 100644 index 00000000..0fab8081 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Timeouts.kt @@ -0,0 +1,204 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +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 + +class Timeouts +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val channel: JsonField, + private val provider: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("channel") @ExcludeMissing channel: JsonField = JsonMissing.of(), + @JsonProperty("provider") @ExcludeMissing provider: JsonField = JsonMissing.of(), + ) : this(channel, provider, mutableMapOf()) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun channel(): Optional = channel.getOptional("channel") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun provider(): Optional = provider.getOptional("provider") + + /** + * Returns the raw JSON value of [channel]. + * + * Unlike [channel], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channel") @ExcludeMissing fun _channel(): JsonField = channel + + /** + * Returns the raw JSON value of [provider]. + * + * Unlike [provider], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonField = provider + + @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 [Timeouts]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Timeouts]. */ + class Builder internal constructor() { + + private var channel: JsonField = JsonMissing.of() + private var provider: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(timeouts: Timeouts) = apply { + channel = timeouts.channel + provider = timeouts.provider + additionalProperties = timeouts.additionalProperties.toMutableMap() + } + + fun channel(channel: Long?) = channel(JsonField.ofNullable(channel)) + + /** + * Alias for [Builder.channel]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun channel(channel: Long) = channel(channel as Long?) + + /** Alias for calling [Builder.channel] with `channel.orElse(null)`. */ + fun channel(channel: Optional) = channel(channel.getOrNull()) + + /** + * Sets [Builder.channel] to an arbitrary JSON value. + * + * You should usually call [Builder.channel] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun channel(channel: JsonField) = apply { this.channel = channel } + + fun provider(provider: Long?) = provider(JsonField.ofNullable(provider)) + + /** + * Alias for [Builder.provider]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun provider(provider: Long) = provider(provider as Long?) + + /** Alias for calling [Builder.provider] with `provider.orElse(null)`. */ + fun provider(provider: Optional) = provider(provider.getOrNull()) + + /** + * Sets [Builder.provider] to an arbitrary JSON value. + * + * You should usually call [Builder.provider] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun provider(provider: JsonField) = apply { this.provider = provider } + + 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 [Timeouts]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Timeouts = Timeouts(channel, provider, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Timeouts = apply { + if (validated) { + return@apply + } + + channel() + provider() + 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 (channel.asKnown().isPresent) 1 else 0) + (if (provider.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Timeouts && + channel == other.channel && + provider == other.provider && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(channel, provider, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Timeouts{channel=$channel, provider=$provider, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationArchiveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationArchiveParams.kt new file mode 100644 index 00000000..d27b7f60 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationArchiveParams.kt @@ -0,0 +1,232 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 notification template. */ +class NotificationArchiveParams +private constructor( + private val id: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** 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(): NotificationArchiveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [NotificationArchiveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationArchiveParams]. */ + class Builder internal constructor() { + + private var id: 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(notificationArchiveParams: NotificationArchiveParams) = apply { + id = notificationArchiveParams.id + additionalHeaders = notificationArchiveParams.additionalHeaders.toBuilder() + additionalQueryParams = notificationArchiveParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + notificationArchiveParams.additionalBodyProperties.toMutableMap() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.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 [NotificationArchiveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): NotificationArchiveParams = + NotificationArchiveParams( + id, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + 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 NotificationArchiveParams && + id == other.id && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(id, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "NotificationArchiveParams{id=$id, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationCreateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationCreateParams.kt new file mode 100644 index 00000000..8c1ebbd1 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationCreateParams.kt @@ -0,0 +1,214 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 notification template. Requires all fields in the notification object. Templates are + * created in draft state by default. + */ +class NotificationCreateParams +private constructor( + private val notificationTemplateCreateRequest: NotificationTemplateCreateRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Request body for creating a notification template. */ + fun notificationTemplateCreateRequest(): NotificationTemplateCreateRequest = + notificationTemplateCreateRequest + + fun _additionalBodyProperties(): Map = + notificationTemplateCreateRequest._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 [NotificationCreateParams]. + * + * The following fields are required: + * ```java + * .notificationTemplateCreateRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationCreateParams]. */ + class Builder internal constructor() { + + private var notificationTemplateCreateRequest: NotificationTemplateCreateRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(notificationCreateParams: NotificationCreateParams) = apply { + notificationTemplateCreateRequest = + notificationCreateParams.notificationTemplateCreateRequest + additionalHeaders = notificationCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = notificationCreateParams.additionalQueryParams.toBuilder() + } + + /** Request body for creating a notification template. */ + fun notificationTemplateCreateRequest( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest + ) = apply { this.notificationTemplateCreateRequest = notificationTemplateCreateRequest } + + 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 [NotificationCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .notificationTemplateCreateRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationCreateParams = + NotificationCreateParams( + checkRequired( + "notificationTemplateCreateRequest", + notificationTemplateCreateRequest, + ), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): NotificationTemplateCreateRequest = notificationTemplateCreateRequest + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationCreateParams && + notificationTemplateCreateRequest == other.notificationTemplateCreateRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(notificationTemplateCreateRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "NotificationCreateParams{notificationTemplateCreateRequest=$notificationTemplateCreateRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListParams.kt index 96d1ad00..6e86a5b2 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListParams.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListParams.kt @@ -9,17 +9,23 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull +/** List notification templates in your workspace. */ class NotificationListParams private constructor( private val cursor: String?, + private val eventId: String?, private val notes: Boolean?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { + /** Opaque pagination cursor from a previous response. Omit for the first page. */ fun cursor(): Optional = Optional.ofNullable(cursor) - /** Retrieve the notes from the Notification template settings. */ + /** Filter to templates linked to this event map ID. */ + fun eventId(): Optional = Optional.ofNullable(eventId) + + /** Include template notes in the response. Only applies to legacy templates. */ fun notes(): Optional = Optional.ofNullable(notes) /** Additional headers to send with the request. */ @@ -42,6 +48,7 @@ private constructor( class Builder internal constructor() { private var cursor: String? = null + private var eventId: String? = null private var notes: Boolean? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @@ -49,17 +56,25 @@ private constructor( @JvmSynthetic internal fun from(notificationListParams: NotificationListParams) = apply { cursor = notificationListParams.cursor + eventId = notificationListParams.eventId notes = notificationListParams.notes additionalHeaders = notificationListParams.additionalHeaders.toBuilder() additionalQueryParams = notificationListParams.additionalQueryParams.toBuilder() } + /** Opaque pagination cursor from a previous response. Omit for the first page. */ fun cursor(cursor: String?) = apply { this.cursor = cursor } /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) - /** Retrieve the notes from the Notification template settings. */ + /** Filter to templates linked to this event map ID. */ + fun eventId(eventId: String?) = apply { this.eventId = eventId } + + /** Alias for calling [Builder.eventId] with `eventId.orElse(null)`. */ + fun eventId(eventId: Optional) = eventId(eventId.getOrNull()) + + /** Include template notes in the response. Only applies to legacy templates. */ fun notes(notes: Boolean?) = apply { this.notes = notes } /** @@ -178,6 +193,7 @@ private constructor( fun build(): NotificationListParams = NotificationListParams( cursor, + eventId, notes, additionalHeaders.build(), additionalQueryParams.build(), @@ -190,6 +206,7 @@ private constructor( QueryParams.builder() .apply { cursor?.let { put("cursor", it) } + eventId?.let { put("event_id", it) } notes?.let { put("notes", it.toString()) } putAll(additionalQueryParams) } @@ -202,14 +219,15 @@ private constructor( return other is NotificationListParams && cursor == other.cursor && + eventId == other.eventId && notes == other.notes && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams } override fun hashCode(): Int = - Objects.hash(cursor, notes, additionalHeaders, additionalQueryParams) + Objects.hash(cursor, eventId, notes, additionalHeaders, additionalQueryParams) override fun toString() = - "NotificationListParams{cursor=$cursor, notes=$notes, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "NotificationListParams{cursor=$cursor, eventId=$eventId, notes=$notes, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListResponse.kt index 6746aadd..65dd898b 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListResponse.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListResponse.kt @@ -2,12 +2,16 @@ package com.courier.models.notifications +import com.courier.core.BaseDeserializer +import com.courier.core.BaseSerializer import com.courier.core.ExcludeMissing import com.courier.core.JsonField import com.courier.core.JsonMissing import com.courier.core.JsonValue +import com.courier.core.allMaxBy import com.courier.core.checkKnown import com.courier.core.checkRequired +import com.courier.core.getOrThrow import com.courier.core.toImmutable import com.courier.errors.CourierInvalidDataException import com.courier.models.MessageRouting @@ -16,6 +20,13 @@ 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 com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Collections import java.util.Objects import java.util.Optional @@ -42,6 +53,8 @@ private constructor( fun paging(): Paging = paging.getRequired("paging") /** + * Notification templates in this workspace. + * * @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). */ @@ -111,6 +124,7 @@ private constructor( */ fun paging(paging: JsonField) = apply { this.paging = paging } + /** Notification templates in this workspace. */ fun results(results: List) = results(JsonField.of(results)) /** @@ -136,6 +150,17 @@ private constructor( } } + /** Alias for calling [addResult] with `Result.ofNotification(notification)`. */ + fun addResult(notification: Result.Notification) = + addResult(Result.ofNotification(notification)) + + /** + * Alias for calling [addResult] with + * `Result.ofNotificationTemplateSummary(notificationTemplateSummary)`. + */ + fun addResult(notificationTemplateSummary: NotificationTemplateSummary) = + addResult(Result.ofNotificationTemplateSummary(notificationTemplateSummary)) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -206,475 +231,383 @@ private constructor( (paging.asKnown().getOrNull()?.validity() ?: 0) + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + /** V2 (CDS) template summary returned in list responses. */ + @JsonDeserialize(using = Result.Deserializer::class) + @JsonSerialize(using = Result.Serializer::class) class Result - @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val id: JsonField, - private val createdAt: JsonField, - private val eventIds: JsonField>, - private val note: JsonField, - private val routing: JsonField, - private val topicId: JsonField, - private val updatedAt: JsonField, - private val tags: JsonField, - private val title: JsonField, - private val additionalProperties: MutableMap, + private val notification: Notification? = null, + private val notificationTemplateSummary: NotificationTemplateSummary? = null, + private val _json: JsonValue? = null, ) { - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("created_at") - @ExcludeMissing - createdAt: JsonField = JsonMissing.of(), - @JsonProperty("event_ids") - @ExcludeMissing - eventIds: JsonField> = JsonMissing.of(), - @JsonProperty("note") @ExcludeMissing note: JsonField = JsonMissing.of(), - @JsonProperty("routing") - @ExcludeMissing - routing: JsonField = JsonMissing.of(), - @JsonProperty("topic_id") @ExcludeMissing topicId: JsonField = JsonMissing.of(), - @JsonProperty("updated_at") - @ExcludeMissing - updatedAt: JsonField = JsonMissing.of(), - @JsonProperty("tags") @ExcludeMissing tags: JsonField = JsonMissing.of(), - @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), - ) : this( - id, - createdAt, - eventIds, - note, - routing, - topicId, - updatedAt, - tags, - title, - mutableMapOf(), - ) + fun notification(): Optional = Optional.ofNullable(notification) - /** - * @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") + /** V2 (CDS) template summary returned in list responses. */ + fun notificationTemplateSummary(): Optional = + Optional.ofNullable(notificationTemplateSummary) - /** - * @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 createdAt(): Long = createdAt.getRequired("created_at") + fun isNotification(): Boolean = notification != null - /** - * Array of event IDs associated with this notification - * - * @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 eventIds(): List = eventIds.getRequired("event_ids") + fun isNotificationTemplateSummary(): Boolean = notificationTemplateSummary != null - /** - * @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 note(): String = note.getRequired("note") + fun asNotification(): Notification = notification.getOrThrow("notification") - /** - * @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 routing(): MessageRouting = routing.getRequired("routing") + /** V2 (CDS) template summary returned in list responses. */ + fun asNotificationTemplateSummary(): NotificationTemplateSummary = + notificationTemplateSummary.getOrThrow("notificationTemplateSummary") - /** - * @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 topicId(): String = topicId.getRequired("topic_id") + fun _json(): Optional = Optional.ofNullable(_json) - /** - * @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 updatedAt(): Long = updatedAt.getRequired("updated_at") + fun accept(visitor: Visitor): T = + when { + notification != null -> visitor.visitNotification(notification) + notificationTemplateSummary != null -> + visitor.visitNotificationTemplateSummary(notificationTemplateSummary) + else -> visitor.unknown(_json) + } - /** - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun tags(): Optional = tags.getOptional("tags") + private var validated: Boolean = false - /** - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun title(): Optional = title.getOptional("title") + fun validate(): Result = apply { + if (validated) { + return@apply + } - /** - * 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 + accept( + object : Visitor { + override fun visitNotification(notification: Notification) { + notification.validate() + } - /** - * Returns the raw JSON value of [createdAt]. - * - * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + override fun visitNotificationTemplateSummary( + notificationTemplateSummary: NotificationTemplateSummary + ) { + notificationTemplateSummary.validate() + } + } + ) + validated = true + } - /** - * Returns the raw JSON value of [eventIds]. - * - * Unlike [eventIds], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("event_ids") - @ExcludeMissing - fun _eventIds(): JsonField> = eventIds + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } /** - * Returns the raw JSON value of [note]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * Unlike [note], this method doesn't throw if the JSON field has an unexpected type. + * Used for best match union deserialization. */ - @JsonProperty("note") @ExcludeMissing fun _note(): JsonField = note + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitNotification(notification: Notification) = + notification.validity() - /** - * Returns the raw JSON value of [routing]. - * - * Unlike [routing], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("routing") @ExcludeMissing fun _routing(): JsonField = routing + override fun visitNotificationTemplateSummary( + notificationTemplateSummary: NotificationTemplateSummary + ) = notificationTemplateSummary.validity() - /** - * Returns the raw JSON value of [topicId]. - * - * Unlike [topicId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("topic_id") @ExcludeMissing fun _topicId(): JsonField = topicId + override fun unknown(json: JsonValue?) = 0 + } + ) - /** - * Returns the raw JSON value of [updatedAt]. - * - * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("updated_at") @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Returns the raw JSON value of [tags]. - * - * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField = tags + return other is Result && + notification == other.notification && + notificationTemplateSummary == other.notificationTemplateSummary + } - /** - * Returns the raw JSON value of [title]. - * - * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title + override fun hashCode(): Int = Objects.hash(notification, notificationTemplateSummary) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) + override fun toString(): String = + when { + notification != null -> "Result{notification=$notification}" + notificationTemplateSummary != null -> + "Result{notificationTemplateSummary=$notificationTemplateSummary}" + _json != null -> "Result{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Result") + } + + companion object { + + @JvmStatic + fun ofNotification(notification: Notification) = Result(notification = notification) + + /** V2 (CDS) template summary returned in list responses. */ + @JvmStatic + fun ofNotificationTemplateSummary( + notificationTemplateSummary: NotificationTemplateSummary + ) = Result(notificationTemplateSummary = notificationTemplateSummary) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** An interface that defines how to map each variant of [Result] to a value of type [T]. */ + interface Visitor { - fun toBuilder() = Builder().from(this) + fun visitNotification(notification: Notification): T - companion object { + /** V2 (CDS) template summary returned in list responses. */ + fun visitNotificationTemplateSummary( + notificationTemplateSummary: NotificationTemplateSummary + ): T /** - * Returns a mutable builder for constructing an instance of [Result]. + * Maps an unknown variant of [Result] to a value of type [T]. * - * The following fields are required: - * ```java - * .id() - * .createdAt() - * .eventIds() - * .note() - * .routing() - * .topicId() - * .updatedAt() - * ``` + * An instance of [Result] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws CourierInvalidDataException in the default implementation. */ - @JvmStatic fun builder() = Builder() + fun unknown(json: JsonValue?): T { + throw CourierInvalidDataException("Unknown Result: $json") + } } - /** A builder for [Result]. */ - class Builder internal constructor() { + internal class Deserializer : BaseDeserializer(Result::class) { - private var id: JsonField? = null - private var createdAt: JsonField? = null - private var eventIds: JsonField>? = null - private var note: JsonField? = null - private var routing: JsonField? = null - private var topicId: JsonField? = null - private var updatedAt: JsonField? = null - private var tags: JsonField = JsonMissing.of() - private var title: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + override fun ObjectCodec.deserialize(node: JsonNode): Result { + val json = JsonValue.fromJsonNode(node) - @JvmSynthetic - internal fun from(result: Result) = apply { - id = result.id - createdAt = result.createdAt - eventIds = result.eventIds.map { it.toMutableList() } - note = result.note - routing = result.routing - topicId = result.topicId - updatedAt = result.updatedAt - tags = result.tags - title = result.title - additionalProperties = result.additionalProperties.toMutableMap() + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Result(notification = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Result(notificationTemplateSummary = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Result(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Result::class) { + + override fun serialize( + value: Result, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.notification != null -> generator.writeObject(value.notification) + value.notificationTemplateSummary != null -> + generator.writeObject(value.notificationTemplateSummary) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Result") + } } + } - fun id(id: String) = id(JsonField.of(id)) + class Notification + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val eventIds: JsonField>, + private val note: JsonField, + private val routing: JsonField, + private val topicId: JsonField, + private val updatedAt: JsonField, + private val tags: JsonField, + private val title: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("event_ids") + @ExcludeMissing + eventIds: JsonField> = JsonMissing.of(), + @JsonProperty("note") @ExcludeMissing note: JsonField = JsonMissing.of(), + @JsonProperty("routing") + @ExcludeMissing + routing: JsonField = JsonMissing.of(), + @JsonProperty("topic_id") + @ExcludeMissing + topicId: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField = JsonMissing.of(), + @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), + ) : this( + id, + createdAt, + eventIds, + note, + routing, + topicId, + updatedAt, + tags, + title, + mutableMapOf(), + ) /** - * 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. + * @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(id: JsonField) = apply { this.id = id } + fun id(): String = id.getRequired("id") - fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + /** + * @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 createdAt(): Long = createdAt.getRequired("created_at") /** - * Sets [Builder.createdAt] to an arbitrary JSON value. + * Array of event IDs associated with this notification * - * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @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 createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + fun eventIds(): List = eventIds.getRequired("event_ids") - /** Array of event IDs associated with this notification */ - fun eventIds(eventIds: List) = eventIds(JsonField.of(eventIds)) + /** + * @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 note(): String = note.getRequired("note") /** - * Sets [Builder.eventIds] to an arbitrary JSON value. - * - * You should usually call [Builder.eventIds] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @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 eventIds(eventIds: JsonField>) = apply { - this.eventIds = eventIds.map { it.toMutableList() } - } + fun routing(): MessageRouting = routing.getRequired("routing") /** - * Adds a single [String] to [eventIds]. - * - * @throws IllegalStateException if the field was previously set to a non-list. + * @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 addEventId(eventId: String) = apply { - eventIds = - (eventIds ?: JsonField.of(mutableListOf())).also { - checkKnown("eventIds", it).add(eventId) - } - } + fun topicId(): String = topicId.getRequired("topic_id") - fun note(note: String) = note(JsonField.of(note)) + /** + * @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 updatedAt(): Long = updatedAt.getRequired("updated_at") /** - * Sets [Builder.note] to an arbitrary JSON value. - * - * You should usually call [Builder.note] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun note(note: JsonField) = apply { this.note = note } + fun tags(): Optional = tags.getOptional("tags") - fun routing(routing: MessageRouting) = routing(JsonField.of(routing)) + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun title(): Optional = title.getOptional("title") /** - * Sets [Builder.routing] to an arbitrary JSON value. + * Returns the raw JSON value of [id]. * - * You should usually call [Builder.routing] with a well-typed [MessageRouting] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. */ - fun routing(routing: JsonField) = apply { this.routing = routing } - - fun topicId(topicId: String) = topicId(JsonField.of(topicId)) + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id /** - * Sets [Builder.topicId] to an arbitrary JSON value. + * Returns the raw JSON value of [createdAt]. * - * You should usually call [Builder.topicId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun topicId(topicId: JsonField) = apply { this.topicId = topicId } - - fun updatedAt(updatedAt: Long) = updatedAt(JsonField.of(updatedAt)) + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt /** - * Sets [Builder.updatedAt] to an arbitrary JSON value. + * Returns the raw JSON value of [eventIds]. * - * You should usually call [Builder.updatedAt] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [eventIds], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } - - fun tags(tags: Tags?) = tags(JsonField.ofNullable(tags)) - - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional) = tags(tags.getOrNull()) + @JsonProperty("event_ids") + @ExcludeMissing + fun _eventIds(): JsonField> = eventIds /** - * Sets [Builder.tags] to an arbitrary JSON value. + * Returns the raw JSON value of [note]. * - * You should usually call [Builder.tags] with a well-typed [Tags] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [note], this method doesn't throw if the JSON field has an unexpected type. */ - fun tags(tags: JsonField) = apply { this.tags = tags } - - fun title(title: String?) = title(JsonField.ofNullable(title)) - - /** Alias for calling [Builder.title] with `title.orElse(null)`. */ - fun title(title: Optional) = title(title.getOrNull()) + @JsonProperty("note") @ExcludeMissing fun _note(): JsonField = note /** - * Sets [Builder.title] to an arbitrary JSON value. + * Returns the raw JSON value of [routing]. * - * You should usually call [Builder.title] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [routing], this method doesn't throw if the JSON field has an unexpected type. */ - fun title(title: JsonField) = apply { this.title = title } - - 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) - } + @JsonProperty("routing") + @ExcludeMissing + fun _routing(): JsonField = routing /** - * Returns an immutable instance of [Result]. - * - * Further updates to this [Builder] will not mutate the returned instance. + * Returns the raw JSON value of [topicId]. * - * The following fields are required: - * ```java - * .id() - * .createdAt() - * .eventIds() - * .note() - * .routing() - * .topicId() - * .updatedAt() - * ``` - * - * @throws IllegalStateException if any required field is unset. + * Unlike [topicId], this method doesn't throw if the JSON field has an unexpected type. */ - fun build(): Result = - Result( - checkRequired("id", id), - checkRequired("createdAt", createdAt), - checkRequired("eventIds", eventIds).map { it.toImmutable() }, - checkRequired("note", note), - checkRequired("routing", routing), - checkRequired("topicId", topicId), - checkRequired("updatedAt", updatedAt), - tags, - title, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Result = apply { - if (validated) { - return@apply - } - - id() - createdAt() - eventIds() - note() - routing().validate() - topicId() - updatedAt() - tags().ifPresent { it.validate() } - title() - 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 (createdAt.asKnown().isPresent) 1 else 0) + - (eventIds.asKnown().getOrNull()?.size ?: 0) + - (if (note.asKnown().isPresent) 1 else 0) + - (routing.asKnown().getOrNull()?.validity() ?: 0) + - (if (topicId.asKnown().isPresent) 1 else 0) + - (if (updatedAt.asKnown().isPresent) 1 else 0) + - (tags.asKnown().getOrNull()?.validity() ?: 0) + - (if (title.asKnown().isPresent) 1 else 0) - - class Tags - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val data: JsonField>, - private val additionalProperties: MutableMap, - ) { + @JsonProperty("topic_id") @ExcludeMissing fun _topicId(): JsonField = topicId - @JsonCreator - private constructor( - @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of() - ) : this(data, mutableMapOf()) + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt /** - * @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). + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. */ - fun data(): List = data.getRequired("data") + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField = tags /** - * Returns the raw JSON value of [data]. + * Returns the raw JSON value of [title]. * - * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -691,53 +624,170 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Tags]. + * Returns a mutable builder for constructing an instance of [Notification]. * * The following fields are required: * ```java - * .data() + * .id() + * .createdAt() + * .eventIds() + * .note() + * .routing() + * .topicId() + * .updatedAt() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [Tags]. */ + /** A builder for [Notification]. */ class Builder internal constructor() { - private var data: JsonField>? = null + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var eventIds: JsonField>? = null + private var note: JsonField? = null + private var routing: JsonField? = null + private var topicId: JsonField? = null + private var updatedAt: JsonField? = null + private var tags: JsonField = JsonMissing.of() + private var title: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(tags: Tags) = apply { - data = tags.data.map { it.toMutableList() } - additionalProperties = tags.additionalProperties.toMutableMap() + internal fun from(notification: Notification) = apply { + id = notification.id + createdAt = notification.createdAt + eventIds = notification.eventIds.map { it.toMutableList() } + note = notification.note + routing = notification.routing + topicId = notification.topicId + updatedAt = notification.updatedAt + tags = notification.tags + title = notification.title + additionalProperties = notification.additionalProperties.toMutableMap() } - fun data(data: List) = data(JsonField.of(data)) + fun id(id: String) = id(JsonField.of(id)) /** - * Sets [Builder.data] to an arbitrary JSON value. + * Sets [Builder.id] to an arbitrary JSON value. * - * You should usually call [Builder.data] with a well-typed `List` 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 } + + fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Array of event IDs associated with this notification */ + fun eventIds(eventIds: List) = eventIds(JsonField.of(eventIds)) + + /** + * Sets [Builder.eventIds] to an arbitrary JSON value. + * + * You should usually call [Builder.eventIds] with a well-typed `List` value * instead. This method is primarily for setting the field to an undocumented or not * yet supported value. */ - fun data(data: JsonField>) = apply { - this.data = data.map { it.toMutableList() } + fun eventIds(eventIds: JsonField>) = apply { + this.eventIds = eventIds.map { it.toMutableList() } } /** - * Adds a single [Data] to [Builder.data]. + * Adds a single [String] to [eventIds]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addData(data: Data) = apply { - this.data = - (this.data ?: JsonField.of(mutableListOf())).also { - checkKnown("data", it).add(data) + fun addEventId(eventId: String) = apply { + eventIds = + (eventIds ?: JsonField.of(mutableListOf())).also { + checkKnown("eventIds", it).add(eventId) } } + fun note(note: String) = note(JsonField.of(note)) + + /** + * Sets [Builder.note] to an arbitrary JSON value. + * + * You should usually call [Builder.note] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun note(note: JsonField) = apply { this.note = note } + + fun routing(routing: MessageRouting) = routing(JsonField.of(routing)) + + /** + * Sets [Builder.routing] to an arbitrary JSON value. + * + * You should usually call [Builder.routing] with a well-typed [MessageRouting] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun routing(routing: JsonField) = apply { this.routing = routing } + + fun topicId(topicId: String) = topicId(JsonField.of(topicId)) + + /** + * Sets [Builder.topicId] to an arbitrary JSON value. + * + * You should usually call [Builder.topicId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun topicId(topicId: JsonField) = apply { this.topicId = topicId } + + fun updatedAt(updatedAt: Long) = updatedAt(JsonField.of(updatedAt)) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + fun tags(tags: Tags?) = tags(JsonField.ofNullable(tags)) + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional) = tags(tags.getOrNull()) + + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed [Tags] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tags(tags: JsonField) = apply { this.tags = tags } + + fun title(title: String?) = title(JsonField.ofNullable(title)) + + /** Alias for calling [Builder.title] with `title.orElse(null)`. */ + fun title(title: Optional) = title(title.getOrNull()) + + /** + * Sets [Builder.title] to an arbitrary JSON value. + * + * You should usually call [Builder.title] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun title(title: JsonField) = apply { this.title = title } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -761,32 +811,54 @@ private constructor( } /** - * Returns an immutable instance of [Tags]. + * Returns an immutable instance of [Notification]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java - * .data() + * .id() + * .createdAt() + * .eventIds() + * .note() + * .routing() + * .topicId() + * .updatedAt() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): Tags = - Tags( - checkRequired("data", data).map { it.toImmutable() }, + fun build(): Notification = + Notification( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("eventIds", eventIds).map { it.toImmutable() }, + checkRequired("note", note), + checkRequired("routing", routing), + checkRequired("topicId", topicId), + checkRequired("updatedAt", updatedAt), + tags, + title, additionalProperties.toMutableMap(), ) } private var validated: Boolean = false - fun validate(): Tags = apply { + fun validate(): Notification = apply { if (validated) { return@apply } - data().forEach { it.validate() } + id() + createdAt() + eventIds() + note() + routing().validate() + topicId() + updatedAt() + tags().ifPresent { it.validate() } + title() validated = true } @@ -806,50 +878,44 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - class Data + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (eventIds.asKnown().getOrNull()?.size ?: 0) + + (if (note.asKnown().isPresent) 1 else 0) + + (routing.asKnown().getOrNull()?.validity() ?: 0) + + (if (topicId.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (tags.asKnown().getOrNull()?.validity() ?: 0) + + (if (title.asKnown().isPresent) 1 else 0) + + class Tags @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val id: JsonField, - private val name: JsonField, + private val data: JsonField>, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - ) : this(id, name, 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 id(): String = id.getRequired("id") + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of() + ) : this(data, 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 name(): String = name.getRequired("name") - - /** - * 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 + fun data(): List = data.getRequired("data") /** - * Returns the raw JSON value of [name]. + * Returns the raw JSON value of [data]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * Unlike [data], this method doesn't throw if the JSON field has an unexpected * type. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -866,52 +932,52 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Data]. + * Returns a mutable builder for constructing an instance of [Tags]. * * The following fields are required: * ```java - * .id() - * .name() + * .data() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [Data]. */ + /** A builder for [Tags]. */ class Builder internal constructor() { - private var id: JsonField? = null - private var name: JsonField? = null + private var data: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(data: Data) = apply { - id = data.id - name = data.name - additionalProperties = data.additionalProperties.toMutableMap() + internal fun from(tags: Tags) = apply { + data = tags.data.map { it.toMutableList() } + additionalProperties = tags.additionalProperties.toMutableMap() } - fun id(id: String) = id(JsonField.of(id)) + fun data(data: List) = data(JsonField.of(data)) /** - * Sets [Builder.id] to an arbitrary JSON value. + * Sets [Builder.data] to an arbitrary JSON value. * - * You should usually call [Builder.id] with a well-typed [String] value + * You should usually call [Builder.data] with a well-typed `List` 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 } - - fun name(name: String) = name(JsonField.of(name)) + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } /** - * Sets [Builder.name] to an arbitrary JSON value. + * Adds a single [Data] to [Builder.data]. * - * 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. + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun name(name: JsonField) = apply { this.name = name } + fun addData(data: Data) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -936,35 +1002,32 @@ private constructor( } /** - * Returns an immutable instance of [Data]. + * Returns an immutable instance of [Tags]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java - * .id() - * .name() + * .data() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): Data = - Data( - checkRequired("id", id), - checkRequired("name", name), + fun build(): Tags = + Tags( + checkRequired("data", data).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } private var validated: Boolean = false - fun validate(): Data = apply { + fun validate(): Tags = apply { if (validated) { return@apply } - id() - name() + data().forEach { it.validate() } validated = true } @@ -984,26 +1047,230 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (id.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, 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 id(): String = id.getRequired("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 name(): String = name.getRequired("name") + + /** + * 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 [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @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 [Data]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + id = data.id + name = data.name + additionalProperties = data.additionalProperties.toMutableMap() + } + + 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 } + + 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 } + + 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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Data = + Data( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Data = apply { + if (validated) { + return@apply + } + + id() + name() + 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 (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Data{id=$id, name=$name, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is Data && - id == other.id && - name == other.name && + return other is Tags && + data == other.data && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(id, name, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Data{id=$id, name=$name, additionalProperties=$additionalProperties}" + "Tags{data=$data, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1011,55 +1278,39 @@ private constructor( return true } - return other is Tags && - data == other.data && + return other is Notification && + id == other.id && + createdAt == other.createdAt && + eventIds == other.eventIds && + note == other.note && + routing == other.routing && + topicId == other.topicId && + updatedAt == other.updatedAt && + tags == other.tags && + title == other.title && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Tags{data=$data, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + eventIds, + note, + routing, + topicId, + updatedAt, + tags, + title, + additionalProperties, + ) } - return other is Result && - id == other.id && - createdAt == other.createdAt && - eventIds == other.eventIds && - note == other.note && - routing == other.routing && - topicId == other.topicId && - updatedAt == other.updatedAt && - tags == other.tags && - title == other.title && - additionalProperties == other.additionalProperties - } + override fun hashCode(): Int = hashCode - private val hashCode: Int by lazy { - Objects.hash( - id, - createdAt, - eventIds, - note, - routing, - topicId, - updatedAt, - tags, - title, - additionalProperties, - ) + override fun toString() = + "Notification{id=$id, createdAt=$createdAt, eventIds=$eventIds, note=$note, routing=$routing, topicId=$topicId, updatedAt=$updatedAt, tags=$tags, title=$title, additionalProperties=$additionalProperties}" } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Result{id=$id, createdAt=$createdAt, eventIds=$eventIds, note=$note, routing=$routing, topicId=$topicId, updatedAt=$updatedAt, tags=$tags, title=$title, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListVersionsParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListVersionsParams.kt new file mode 100644 index 00000000..c0080835 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationListVersionsParams.kt @@ -0,0 +1,239 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 versions of a notification template. */ +class NotificationListVersionsParams +private constructor( + private val id: String?, + private val cursor: String?, + private val limit: Long?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** Opaque pagination cursor from a previous response. Omit for the first page. */ + fun cursor(): Optional = Optional.ofNullable(cursor) + + /** Maximum number of versions to return per page. Default 10, max 10. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** 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(): NotificationListVersionsParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [NotificationListVersionsParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationListVersionsParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var cursor: String? = null + private var limit: Long? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(notificationListVersionsParams: NotificationListVersionsParams) = apply { + id = notificationListVersionsParams.id + cursor = notificationListVersionsParams.cursor + limit = notificationListVersionsParams.limit + additionalHeaders = notificationListVersionsParams.additionalHeaders.toBuilder() + additionalQueryParams = notificationListVersionsParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + /** Opaque pagination cursor from a previous response. Omit for the first page. */ + fun cursor(cursor: String?) = apply { this.cursor = cursor } + + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + + /** Maximum number of versions to return per page. Default 10, max 10. */ + fun limit(limit: Long?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.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 [NotificationListVersionsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): NotificationListVersionsParams = + NotificationListVersionsParams( + id, + cursor, + limit, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + cursor?.let { put("cursor", it) } + limit?.let { put("limit", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationListVersionsParams && + id == other.id && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(id, cursor, limit, additionalHeaders, additionalQueryParams) + + override fun toString() = + "NotificationListVersionsParams{id=$id, cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationPublishParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationPublishParams.kt new file mode 100644 index 00000000..0aa7a978 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationPublishParams.kt @@ -0,0 +1,241 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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.immutableEmptyMap +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Publish a notification template. Publishes the current draft by default. Pass a version in the + * request body to publish a specific historical version. + */ +class NotificationPublishParams +private constructor( + private val id: String?, + private val notificationTemplatePublishRequest: NotificationTemplatePublishRequest?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** + * Optional request body for publishing a notification template. Omit or send an empty object to + * publish the current draft. + */ + fun notificationTemplatePublishRequest(): Optional = + Optional.ofNullable(notificationTemplatePublishRequest) + + fun _additionalBodyProperties(): Map = + notificationTemplatePublishRequest?._additionalProperties() ?: immutableEmptyMap() + + /** 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(): NotificationPublishParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [NotificationPublishParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationPublishParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var notificationTemplatePublishRequest: NotificationTemplatePublishRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(notificationPublishParams: NotificationPublishParams) = apply { + id = notificationPublishParams.id + notificationTemplatePublishRequest = + notificationPublishParams.notificationTemplatePublishRequest + additionalHeaders = notificationPublishParams.additionalHeaders.toBuilder() + additionalQueryParams = notificationPublishParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + /** + * Optional request body for publishing a notification template. Omit or send an empty + * object to publish the current draft. + */ + fun notificationTemplatePublishRequest( + notificationTemplatePublishRequest: NotificationTemplatePublishRequest? + ) = apply { this.notificationTemplatePublishRequest = notificationTemplatePublishRequest } + + /** + * Alias for calling [Builder.notificationTemplatePublishRequest] with + * `notificationTemplatePublishRequest.orElse(null)`. + */ + fun notificationTemplatePublishRequest( + notificationTemplatePublishRequest: Optional + ) = notificationTemplatePublishRequest(notificationTemplatePublishRequest.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 [NotificationPublishParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): NotificationPublishParams = + NotificationPublishParams( + id, + notificationTemplatePublishRequest, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Optional = + Optional.ofNullable(notificationTemplatePublishRequest) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + 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 NotificationPublishParams && + id == other.id && + notificationTemplatePublishRequest == other.notificationTemplatePublishRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + id, + notificationTemplatePublishRequest, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "NotificationPublishParams{id=$id, notificationTemplatePublishRequest=$notificationTemplatePublishRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationReplaceParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationReplaceParams.kt new file mode 100644 index 00000000..3a935803 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationReplaceParams.kt @@ -0,0 +1,242 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 notification template. All fields are required. */ +class NotificationReplaceParams +private constructor( + private val id: String?, + private val notificationTemplateUpdateRequest: NotificationTemplateUpdateRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** + * Request body for replacing a notification template. Same shape as create. All fields required + * (PUT = full replacement). + */ + fun notificationTemplateUpdateRequest(): NotificationTemplateUpdateRequest = + notificationTemplateUpdateRequest + + fun _additionalBodyProperties(): Map = + notificationTemplateUpdateRequest._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 [NotificationReplaceParams]. + * + * The following fields are required: + * ```java + * .notificationTemplateUpdateRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationReplaceParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var notificationTemplateUpdateRequest: NotificationTemplateUpdateRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(notificationReplaceParams: NotificationReplaceParams) = apply { + id = notificationReplaceParams.id + notificationTemplateUpdateRequest = + notificationReplaceParams.notificationTemplateUpdateRequest + additionalHeaders = notificationReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = notificationReplaceParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + /** + * Request body for replacing a notification template. Same shape as create. All fields + * required (PUT = full replacement). + */ + fun notificationTemplateUpdateRequest( + notificationTemplateUpdateRequest: NotificationTemplateUpdateRequest + ) = apply { this.notificationTemplateUpdateRequest = notificationTemplateUpdateRequest } + + 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 [NotificationReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .notificationTemplateUpdateRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationReplaceParams = + NotificationReplaceParams( + id, + checkRequired( + "notificationTemplateUpdateRequest", + notificationTemplateUpdateRequest, + ), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): NotificationTemplateUpdateRequest = notificationTemplateUpdateRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + 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 NotificationReplaceParams && + id == other.id && + notificationTemplateUpdateRequest == other.notificationTemplateUpdateRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + id, + notificationTemplateUpdateRequest, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "NotificationReplaceParams{id=$id, notificationTemplateUpdateRequest=$notificationTemplateUpdateRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationRetrieveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationRetrieveParams.kt new file mode 100644 index 00000000..448f14d4 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationRetrieveParams.kt @@ -0,0 +1,225 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 notification template by ID. Returns the published version by default. Pass + * version=draft to retrieve an unpublished template. + */ +class NotificationRetrieveParams +private constructor( + private val id: String?, + private val version: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** + * Version to retrieve. One of "draft", "published", or a version string like "v001". Defaults + * to "published". + */ + fun version(): Optional = Optional.ofNullable(version) + + /** 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(): NotificationRetrieveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [NotificationRetrieveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationRetrieveParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var version: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(notificationRetrieveParams: NotificationRetrieveParams) = apply { + id = notificationRetrieveParams.id + version = notificationRetrieveParams.version + additionalHeaders = notificationRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = notificationRetrieveParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + /** + * Version to retrieve. One of "draft", "published", or a version string like "v001". + * Defaults to "published". + */ + fun version(version: String?) = apply { this.version = version } + + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.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 [NotificationRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): NotificationRetrieveParams = + NotificationRetrieveParams( + id, + version, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + version?.let { put("version", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationRetrieveParams && + id == other.id && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(id, version, additionalHeaders, additionalQueryParams) + + override fun toString() = + "NotificationRetrieveParams{id=$id, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateCreateRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateCreateRequest.kt new file mode 100644 index 00000000..37991db3 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateCreateRequest.kt @@ -0,0 +1,361 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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.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 + +/** Request body for creating a notification template. */ +class NotificationTemplateCreateRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val notification: JsonField, + private val state: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("notification") + @ExcludeMissing + notification: JsonField = JsonMissing.of(), + @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), + ) : this(notification, state, mutableMapOf()) + + /** + * Full document shape used in POST and PUT request bodies, and returned inside the GET response + * envelope. + * + * @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 notification(): NotificationTemplatePayload = notification.getRequired("notification") + + /** + * Template state after creation. Case-insensitive input, normalized to uppercase in the + * response. Defaults to "DRAFT". + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun state(): Optional = state.getOptional("state") + + /** + * Returns the raw JSON value of [notification]. + * + * Unlike [notification], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("notification") + @ExcludeMissing + fun _notification(): JsonField = notification + + /** + * Returns the raw JSON value of [state]. + * + * Unlike [state], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("state") @ExcludeMissing fun _state(): JsonField = state + + @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 + * [NotificationTemplateCreateRequest]. + * + * The following fields are required: + * ```java + * .notification() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationTemplateCreateRequest]. */ + class Builder internal constructor() { + + private var notification: JsonField? = null + private var state: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationTemplateCreateRequest: NotificationTemplateCreateRequest) = + apply { + notification = notificationTemplateCreateRequest.notification + state = notificationTemplateCreateRequest.state + additionalProperties = + notificationTemplateCreateRequest.additionalProperties.toMutableMap() + } + + /** + * Full document shape used in POST and PUT request bodies, and returned inside the GET + * response envelope. + */ + fun notification(notification: NotificationTemplatePayload) = + notification(JsonField.of(notification)) + + /** + * Sets [Builder.notification] to an arbitrary JSON value. + * + * You should usually call [Builder.notification] with a well-typed + * [NotificationTemplatePayload] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun notification(notification: JsonField) = apply { + this.notification = notification + } + + /** + * Template state after creation. Case-insensitive input, normalized to uppercase in the + * response. Defaults to "DRAFT". + */ + fun state(state: State) = state(JsonField.of(state)) + + /** + * Sets [Builder.state] to an arbitrary JSON value. + * + * You should usually call [Builder.state] with a well-typed [State] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun state(state: JsonField) = apply { this.state = state } + + 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 [NotificationTemplateCreateRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .notification() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationTemplateCreateRequest = + NotificationTemplateCreateRequest( + checkRequired("notification", notification), + state, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NotificationTemplateCreateRequest = apply { + if (validated) { + return@apply + } + + notification().validate() + state().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 = + (notification.asKnown().getOrNull()?.validity() ?: 0) + + (state.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Template state after creation. Case-insensitive input, normalized to uppercase in the + * response. Defaults to "DRAFT". + */ + class State @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 DRAFT = of("DRAFT") + + @JvmField val PUBLISHED = of("PUBLISHED") + + @JvmStatic fun of(value: String) = State(JsonField.of(value)) + } + + /** An enum containing [State]'s known values. */ + enum class Known { + DRAFT, + PUBLISHED, + } + + /** + * An enum containing [State]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [State] 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 { + DRAFT, + PUBLISHED, + /** An enum member indicating that [State] 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) { + DRAFT -> Value.DRAFT + PUBLISHED -> Value.PUBLISHED + 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) { + DRAFT -> Known.DRAFT + PUBLISHED -> Known.PUBLISHED + else -> throw CourierInvalidDataException("Unknown State: $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 + + fun validate(): State = 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 State && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationTemplateCreateRequest && + notification == other.notification && + state == other.state && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(notification, state, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationTemplateCreateRequest{notification=$notification, state=$state, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateGetResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateGetResponse.kt new file mode 100644 index 00000000..5fecbc80 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateGetResponse.kt @@ -0,0 +1,963 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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.ElementalContent +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 + +/** + * Envelope response for GET /notifications/{id}. The notification object mirrors the POST/PUT input + * shape. Nullable fields return null when unset. + */ +class NotificationTemplateGetResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val created: JsonField, + private val creator: JsonField, + private val notification: JsonField, + private val state: JsonField, + private val updated: JsonField, + private val updater: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("created") @ExcludeMissing created: JsonField = JsonMissing.of(), + @JsonProperty("creator") @ExcludeMissing creator: JsonField = JsonMissing.of(), + @JsonProperty("notification") + @ExcludeMissing + notification: JsonField = JsonMissing.of(), + @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), + @JsonProperty("updated") @ExcludeMissing updated: JsonField = JsonMissing.of(), + @JsonProperty("updater") @ExcludeMissing updater: JsonField = JsonMissing.of(), + ) : this(created, creator, notification, state, updated, updater, mutableMapOf()) + + /** + * Epoch milliseconds when the template 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(): Long = created.getRequired("created") + + /** + * User ID of the creator. + * + * @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 creator(): String = creator.getRequired("creator") + + /** + * Full document shape used in POST and PUT request bodies, and returned inside the GET response + * envelope. + * + * @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 notification(): Notification = notification.getRequired("notification") + + /** + * The template state. Always uppercase. + * + * @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 state(): State = state.getRequired("state") + + /** + * Epoch milliseconds of 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") + + /** + * User 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 [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 [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 [notification]. + * + * Unlike [notification], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("notification") + @ExcludeMissing + fun _notification(): JsonField = notification + + /** + * Returns the raw JSON value of [state]. + * + * Unlike [state], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("state") @ExcludeMissing fun _state(): JsonField = state + + /** + * 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 + * [NotificationTemplateGetResponse]. + * + * The following fields are required: + * ```java + * .created() + * .creator() + * .notification() + * .state() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationTemplateGetResponse]. */ + class Builder internal constructor() { + + private var created: JsonField? = null + private var creator: JsonField? = null + private var notification: JsonField? = null + private var state: JsonField? = null + private var updated: JsonField = JsonMissing.of() + private var updater: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationTemplateGetResponse: NotificationTemplateGetResponse) = + apply { + created = notificationTemplateGetResponse.created + creator = notificationTemplateGetResponse.creator + notification = notificationTemplateGetResponse.notification + state = notificationTemplateGetResponse.state + updated = notificationTemplateGetResponse.updated + updater = notificationTemplateGetResponse.updater + additionalProperties = + notificationTemplateGetResponse.additionalProperties.toMutableMap() + } + + /** Epoch milliseconds when the template was created. */ + fun created(created: Long) = created(JsonField.of(created)) + + /** + * Sets [Builder.created] to an arbitrary JSON value. + * + * You should usually call [Builder.created] with a well-typed [Long] 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 } + + /** User ID of the creator. */ + fun creator(creator: String) = creator(JsonField.of(creator)) + + /** + * 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 } + + /** + * Full document shape used in POST and PUT request bodies, and returned inside the GET + * response envelope. + */ + fun notification(notification: Notification) = notification(JsonField.of(notification)) + + /** + * Sets [Builder.notification] to an arbitrary JSON value. + * + * You should usually call [Builder.notification] with a well-typed [Notification] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun notification(notification: JsonField) = apply { + this.notification = notification + } + + /** The template state. Always uppercase. */ + fun state(state: State) = state(JsonField.of(state)) + + /** + * Sets [Builder.state] to an arbitrary JSON value. + * + * You should usually call [Builder.state] with a well-typed [State] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun state(state: JsonField) = apply { this.state = state } + + /** Epoch milliseconds of last update. */ + fun updated(updated: Long) = updated(JsonField.of(updated)) + + /** + * Sets [Builder.updated] to an arbitrary JSON value. + * + * You should usually call [Builder.updated] with a well-typed [Long] 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 } + + /** User ID of the last updater. */ + fun updater(updater: String) = updater(JsonField.of(updater)) + + /** + * 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 [NotificationTemplateGetResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .created() + * .creator() + * .notification() + * .state() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationTemplateGetResponse = + NotificationTemplateGetResponse( + checkRequired("created", created), + checkRequired("creator", creator), + checkRequired("notification", notification), + checkRequired("state", state), + updated, + updater, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NotificationTemplateGetResponse = apply { + if (validated) { + return@apply + } + + created() + creator() + notification().validate() + state().validate() + 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 (created.asKnown().isPresent) 1 else 0) + + (if (creator.asKnown().isPresent) 1 else 0) + + (notification.asKnown().getOrNull()?.validity() ?: 0) + + (state.asKnown().getOrNull()?.validity() ?: 0) + + (if (updated.asKnown().isPresent) 1 else 0) + + (if (updater.asKnown().isPresent) 1 else 0) + + /** + * Full document shape used in POST and PUT request bodies, and returned inside the GET response + * envelope. + */ + class Notification + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val brand: JsonField, + private val content: JsonField, + private val name: JsonField, + private val routing: JsonField, + private val subscription: JsonField, + private val tags: JsonField>, + private val id: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("brand") + @ExcludeMissing + brand: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("routing") + @ExcludeMissing + routing: JsonField = JsonMissing.of(), + @JsonProperty("subscription") + @ExcludeMissing + subscription: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + ) : this(brand, content, name, routing, subscription, tags, id, mutableMapOf()) + + fun toNotificationTemplatePayload(): NotificationTemplatePayload = + NotificationTemplatePayload.builder() + .brand(brand) + .content(content) + .name(name) + .routing(routing) + .subscription(subscription) + .tags(tags) + .build() + + /** + * Brand reference, or null for no brand. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun brand(): Optional = brand.getOptional("brand") + + /** + * Elemental content definition. + * + * @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 content(): ElementalContent = content.getRequired("content") + + /** + * Display name for the template. + * + * @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") + + /** + * Routing strategy reference, or null for none. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun routing(): Optional = + routing.getOptional("routing") + + /** + * Subscription topic reference, or null for none. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subscription(): Optional = + subscription.getOptional("subscription") + + /** + * Tags for categorization. Send empty array for none. + * + * @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 tags(): List = tags.getRequired("tags") + + /** + * The template 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") + + /** + * Returns the raw JSON value of [brand]. + * + * Unlike [brand], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("brand") + @ExcludeMissing + fun _brand(): JsonField = brand + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") + @ExcludeMissing + fun _content(): JsonField = content + + /** + * 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 [routing]. + * + * Unlike [routing], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing") + @ExcludeMissing + fun _routing(): JsonField = routing + + /** + * Returns the raw JSON value of [subscription]. + * + * Unlike [subscription], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subscription") + @ExcludeMissing + fun _subscription(): JsonField = subscription + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + /** + * 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 + + @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 [Notification]. + * + * The following fields are required: + * ```java + * .brand() + * .content() + * .name() + * .routing() + * .subscription() + * .tags() + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Notification]. */ + class Builder internal constructor() { + + private var brand: JsonField? = null + private var content: JsonField? = null + private var name: JsonField? = null + private var routing: JsonField? = null + private var subscription: JsonField? = null + private var tags: JsonField>? = null + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notification: Notification) = apply { + brand = notification.brand + content = notification.content + name = notification.name + routing = notification.routing + subscription = notification.subscription + tags = notification.tags.map { it.toMutableList() } + id = notification.id + additionalProperties = notification.additionalProperties.toMutableMap() + } + + /** Brand reference, or null for no brand. */ + fun brand(brand: NotificationTemplatePayload.Brand?) = + brand(JsonField.ofNullable(brand)) + + /** Alias for calling [Builder.brand] with `brand.orElse(null)`. */ + fun brand(brand: Optional) = brand(brand.getOrNull()) + + /** + * Sets [Builder.brand] to an arbitrary JSON value. + * + * You should usually call [Builder.brand] with a well-typed + * [NotificationTemplatePayload.Brand] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun brand(brand: JsonField) = apply { + this.brand = brand + } + + /** Elemental content definition. */ + fun content(content: ElementalContent) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [ElementalContent] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** Display name for the template. */ + 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 } + + /** Routing strategy reference, or null for none. */ + fun routing(routing: NotificationTemplatePayload.Routing?) = + routing(JsonField.ofNullable(routing)) + + /** Alias for calling [Builder.routing] with `routing.orElse(null)`. */ + fun routing(routing: Optional) = + routing(routing.getOrNull()) + + /** + * Sets [Builder.routing] to an arbitrary JSON value. + * + * You should usually call [Builder.routing] with a well-typed + * [NotificationTemplatePayload.Routing] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun routing(routing: JsonField) = apply { + this.routing = routing + } + + /** Subscription topic reference, or null for none. */ + fun subscription(subscription: NotificationTemplatePayload.Subscription?) = + subscription(JsonField.ofNullable(subscription)) + + /** Alias for calling [Builder.subscription] with `subscription.orElse(null)`. */ + fun subscription(subscription: Optional) = + subscription(subscription.getOrNull()) + + /** + * Sets [Builder.subscription] to an arbitrary JSON value. + * + * You should usually call [Builder.subscription] with a well-typed + * [NotificationTemplatePayload.Subscription] value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun subscription(subscription: JsonField) = + apply { + this.subscription = subscription + } + + /** Tags for categorization. Send empty array for none. */ + fun tags(tags: List) = tags(JsonField.of(tags)) + + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = + (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } + + /** The template 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 } + + 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 [Notification]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .brand() + * .content() + * .name() + * .routing() + * .subscription() + * .tags() + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Notification = + Notification( + checkRequired("brand", brand), + checkRequired("content", content), + checkRequired("name", name), + checkRequired("routing", routing), + checkRequired("subscription", subscription), + checkRequired("tags", tags).map { it.toImmutable() }, + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Notification = apply { + if (validated) { + return@apply + } + + brand().ifPresent { it.validate() } + content().validate() + name() + routing().ifPresent { it.validate() } + subscription().ifPresent { it.validate() } + tags() + id() + 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 = + (brand.asKnown().getOrNull()?.validity() ?: 0) + + (content.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (routing.asKnown().getOrNull()?.validity() ?: 0) + + (subscription.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + + (if (id.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Notification && + brand == other.brand && + content == other.content && + name == other.name && + routing == other.routing && + subscription == other.subscription && + tags == other.tags && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + brand, + content, + name, + routing, + subscription, + tags, + id, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Notification{brand=$brand, content=$content, name=$name, routing=$routing, subscription=$subscription, tags=$tags, id=$id, additionalProperties=$additionalProperties}" + } + + /** The template state. Always uppercase. */ + class State @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 DRAFT = of("DRAFT") + + @JvmField val PUBLISHED = of("PUBLISHED") + + @JvmStatic fun of(value: String) = State(JsonField.of(value)) + } + + /** An enum containing [State]'s known values. */ + enum class Known { + DRAFT, + PUBLISHED, + } + + /** + * An enum containing [State]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [State] 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 { + DRAFT, + PUBLISHED, + /** An enum member indicating that [State] 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) { + DRAFT -> Value.DRAFT + PUBLISHED -> Value.PUBLISHED + 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) { + DRAFT -> Known.DRAFT + PUBLISHED -> Known.PUBLISHED + else -> throw CourierInvalidDataException("Unknown State: $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 + + fun validate(): State = 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 State && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationTemplateGetResponse && + created == other.created && + creator == other.creator && + notification == other.notification && + state == other.state && + updated == other.updated && + updater == other.updater && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(created, creator, notification, state, updated, updater, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationTemplateGetResponse{created=$created, creator=$creator, notification=$notification, state=$state, updated=$updated, updater=$updater, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateMutationResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateMutationResponse.kt new file mode 100644 index 00000000..89c0a043 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateMutationResponse.kt @@ -0,0 +1,503 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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.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 kotlin.jvm.optionals.getOrNull + +/** Response returned by POST and PUT operations. */ +class NotificationTemplateMutationResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val notification: JsonField, + private val state: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("notification") + @ExcludeMissing + notification: JsonField = JsonMissing.of(), + @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), + ) : this(notification, state, 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 notification(): Notification = notification.getRequired("notification") + + /** + * The template state after the operation. Always uppercase. + * + * @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 state(): State = state.getRequired("state") + + /** + * Returns the raw JSON value of [notification]. + * + * Unlike [notification], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("notification") + @ExcludeMissing + fun _notification(): JsonField = notification + + /** + * Returns the raw JSON value of [state]. + * + * Unlike [state], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("state") @ExcludeMissing fun _state(): JsonField = state + + @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 + * [NotificationTemplateMutationResponse]. + * + * The following fields are required: + * ```java + * .notification() + * .state() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationTemplateMutationResponse]. */ + class Builder internal constructor() { + + private var notification: JsonField? = null + private var state: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + notificationTemplateMutationResponse: NotificationTemplateMutationResponse + ) = apply { + notification = notificationTemplateMutationResponse.notification + state = notificationTemplateMutationResponse.state + additionalProperties = + notificationTemplateMutationResponse.additionalProperties.toMutableMap() + } + + fun notification(notification: Notification) = notification(JsonField.of(notification)) + + /** + * Sets [Builder.notification] to an arbitrary JSON value. + * + * You should usually call [Builder.notification] with a well-typed [Notification] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun notification(notification: JsonField) = apply { + this.notification = notification + } + + /** The template state after the operation. Always uppercase. */ + fun state(state: State) = state(JsonField.of(state)) + + /** + * Sets [Builder.state] to an arbitrary JSON value. + * + * You should usually call [Builder.state] with a well-typed [State] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun state(state: JsonField) = apply { this.state = state } + + 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 [NotificationTemplateMutationResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .notification() + * .state() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationTemplateMutationResponse = + NotificationTemplateMutationResponse( + checkRequired("notification", notification), + checkRequired("state", state), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NotificationTemplateMutationResponse = apply { + if (validated) { + return@apply + } + + notification().validate() + state().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 = + (notification.asKnown().getOrNull()?.validity() ?: 0) + + (state.asKnown().getOrNull()?.validity() ?: 0) + + class Notification + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() + ) : this(id, mutableMapOf()) + + /** + * The ID of the created or updated template. + * + * @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") + + /** + * 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 + + @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 [Notification]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Notification]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notification: Notification) = apply { + id = notification.id + additionalProperties = notification.additionalProperties.toMutableMap() + } + + /** The ID of the created or updated template. */ + 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 } + + 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 [Notification]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Notification = + Notification(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Notification = apply { + if (validated) { + return@apply + } + + id() + 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) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Notification && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Notification{id=$id, additionalProperties=$additionalProperties}" + } + + /** The template state after the operation. Always uppercase. */ + class State @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 DRAFT = of("DRAFT") + + @JvmField val PUBLISHED = of("PUBLISHED") + + @JvmStatic fun of(value: String) = State(JsonField.of(value)) + } + + /** An enum containing [State]'s known values. */ + enum class Known { + DRAFT, + PUBLISHED, + } + + /** + * An enum containing [State]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [State] 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 { + DRAFT, + PUBLISHED, + /** An enum member indicating that [State] 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) { + DRAFT -> Value.DRAFT + PUBLISHED -> Value.PUBLISHED + 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) { + DRAFT -> Known.DRAFT + PUBLISHED -> Known.PUBLISHED + else -> throw CourierInvalidDataException("Unknown State: $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 + + fun validate(): State = 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 State && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationTemplateMutationResponse && + notification == other.notification && + state == other.state && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(notification, state, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationTemplateMutationResponse{notification=$notification, state=$state, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplatePayload.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplatePayload.kt new file mode 100644 index 00000000..95c08055 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplatePayload.kt @@ -0,0 +1,866 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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.ElementalContent +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 + +/** + * Full document shape used in POST and PUT request bodies, and returned inside the GET response + * envelope. + */ +class NotificationTemplatePayload +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val brand: JsonField, + private val content: JsonField, + private val name: JsonField, + private val routing: JsonField, + private val subscription: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("brand") @ExcludeMissing brand: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("routing") @ExcludeMissing routing: JsonField = JsonMissing.of(), + @JsonProperty("subscription") + @ExcludeMissing + subscription: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(brand, content, name, routing, subscription, tags, mutableMapOf()) + + /** + * Brand reference, or null for no brand. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun brand(): Optional = brand.getOptional("brand") + + /** + * Elemental content definition. + * + * @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 content(): ElementalContent = content.getRequired("content") + + /** + * Display name for the template. + * + * @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") + + /** + * Routing strategy reference, or null for none. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun routing(): Optional = routing.getOptional("routing") + + /** + * Subscription topic reference, or null for none. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subscription(): Optional = subscription.getOptional("subscription") + + /** + * Tags for categorization. Send empty array for none. + * + * @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 tags(): List = tags.getRequired("tags") + + /** + * Returns the raw JSON value of [brand]. + * + * Unlike [brand], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("brand") @ExcludeMissing fun _brand(): JsonField = brand + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * 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 [routing]. + * + * Unlike [routing], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing") @ExcludeMissing fun _routing(): JsonField = routing + + /** + * Returns the raw JSON value of [subscription]. + * + * Unlike [subscription], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("subscription") + @ExcludeMissing + fun _subscription(): JsonField = subscription + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + @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 [NotificationTemplatePayload]. + * + * The following fields are required: + * ```java + * .brand() + * .content() + * .name() + * .routing() + * .subscription() + * .tags() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationTemplatePayload]. */ + class Builder internal constructor() { + + private var brand: JsonField? = null + private var content: JsonField? = null + private var name: JsonField? = null + private var routing: JsonField? = null + private var subscription: JsonField? = null + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationTemplatePayload: NotificationTemplatePayload) = apply { + brand = notificationTemplatePayload.brand + content = notificationTemplatePayload.content + name = notificationTemplatePayload.name + routing = notificationTemplatePayload.routing + subscription = notificationTemplatePayload.subscription + tags = notificationTemplatePayload.tags.map { it.toMutableList() } + additionalProperties = notificationTemplatePayload.additionalProperties.toMutableMap() + } + + /** Brand reference, or null for no brand. */ + fun brand(brand: Brand?) = brand(JsonField.ofNullable(brand)) + + /** Alias for calling [Builder.brand] with `brand.orElse(null)`. */ + fun brand(brand: Optional) = brand(brand.getOrNull()) + + /** + * Sets [Builder.brand] to an arbitrary JSON value. + * + * You should usually call [Builder.brand] with a well-typed [Brand] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun brand(brand: JsonField) = apply { this.brand = brand } + + /** Elemental content definition. */ + fun content(content: ElementalContent) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [ElementalContent] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** Display name for the template. */ + 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 } + + /** Routing strategy reference, or null for none. */ + fun routing(routing: Routing?) = routing(JsonField.ofNullable(routing)) + + /** Alias for calling [Builder.routing] with `routing.orElse(null)`. */ + fun routing(routing: Optional) = routing(routing.getOrNull()) + + /** + * Sets [Builder.routing] to an arbitrary JSON value. + * + * You should usually call [Builder.routing] with a well-typed [Routing] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun routing(routing: JsonField) = apply { this.routing = routing } + + /** Subscription topic reference, or null for none. */ + fun subscription(subscription: Subscription?) = + subscription(JsonField.ofNullable(subscription)) + + /** Alias for calling [Builder.subscription] with `subscription.orElse(null)`. */ + fun subscription(subscription: Optional) = + subscription(subscription.getOrNull()) + + /** + * Sets [Builder.subscription] to an arbitrary JSON value. + * + * You should usually call [Builder.subscription] with a well-typed [Subscription] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun subscription(subscription: JsonField) = apply { + this.subscription = subscription + } + + /** Tags for categorization. Send empty array for none. */ + fun tags(tags: List) = tags(JsonField.of(tags)) + + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } + + 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 [NotificationTemplatePayload]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .brand() + * .content() + * .name() + * .routing() + * .subscription() + * .tags() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationTemplatePayload = + NotificationTemplatePayload( + checkRequired("brand", brand), + checkRequired("content", content), + checkRequired("name", name), + checkRequired("routing", routing), + checkRequired("subscription", subscription), + checkRequired("tags", tags).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NotificationTemplatePayload = apply { + if (validated) { + return@apply + } + + brand().ifPresent { it.validate() } + content().validate() + name() + routing().ifPresent { it.validate() } + subscription().ifPresent { it.validate() } + tags() + 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 = + (brand.asKnown().getOrNull()?.validity() ?: 0) + + (content.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (routing.asKnown().getOrNull()?.validity() ?: 0) + + (subscription.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + + /** Brand reference, or null for no brand. */ + class Brand + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() + ) : this(id, 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 id(): String = id.getRequired("id") + + /** + * 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 + + @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 [Brand]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Brand]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(brand: Brand) = apply { + id = brand.id + additionalProperties = brand.additionalProperties.toMutableMap() + } + + 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 } + + 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 [Brand]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Brand = Brand(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Brand = apply { + if (validated) { + return@apply + } + + id() + 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) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Brand && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Brand{id=$id, additionalProperties=$additionalProperties}" + } + + /** Routing strategy reference, or null for none. */ + class Routing + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val strategyId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("strategy_id") + @ExcludeMissing + strategyId: JsonField = JsonMissing.of() + ) : this(strategyId, 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 strategyId(): String = strategyId.getRequired("strategy_id") + + /** + * Returns the raw JSON value of [strategyId]. + * + * Unlike [strategyId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("strategy_id") + @ExcludeMissing + fun _strategyId(): JsonField = strategyId + + @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 [Routing]. + * + * The following fields are required: + * ```java + * .strategyId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Routing]. */ + class Builder internal constructor() { + + private var strategyId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(routing: Routing) = apply { + strategyId = routing.strategyId + additionalProperties = routing.additionalProperties.toMutableMap() + } + + fun strategyId(strategyId: String) = strategyId(JsonField.of(strategyId)) + + /** + * Sets [Builder.strategyId] to an arbitrary JSON value. + * + * You should usually call [Builder.strategyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun strategyId(strategyId: JsonField) = apply { this.strategyId = strategyId } + + 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 [Routing]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .strategyId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Routing = + Routing( + checkRequired("strategyId", strategyId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Routing = apply { + if (validated) { + return@apply + } + + strategyId() + 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 (strategyId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Routing && + strategyId == other.strategyId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(strategyId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Routing{strategyId=$strategyId, additionalProperties=$additionalProperties}" + } + + /** Subscription topic reference, or null for none. */ + class Subscription + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val topicId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("topic_id") @ExcludeMissing topicId: JsonField = JsonMissing.of() + ) : this(topicId, 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 topicId(): String = topicId.getRequired("topic_id") + + /** + * Returns the raw JSON value of [topicId]. + * + * Unlike [topicId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("topic_id") @ExcludeMissing fun _topicId(): JsonField = topicId + + @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 [Subscription]. + * + * The following fields are required: + * ```java + * .topicId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Subscription]. */ + class Builder internal constructor() { + + private var topicId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(subscription: Subscription) = apply { + topicId = subscription.topicId + additionalProperties = subscription.additionalProperties.toMutableMap() + } + + fun topicId(topicId: String) = topicId(JsonField.of(topicId)) + + /** + * Sets [Builder.topicId] to an arbitrary JSON value. + * + * You should usually call [Builder.topicId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun topicId(topicId: JsonField) = apply { this.topicId = topicId } + + 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 [Subscription]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .topicId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Subscription = + Subscription(checkRequired("topicId", topicId), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Subscription = apply { + if (validated) { + return@apply + } + + topicId() + 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 (topicId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Subscription && + topicId == other.topicId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(topicId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Subscription{topicId=$topicId, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationTemplatePayload && + brand == other.brand && + content == other.content && + name == other.name && + routing == other.routing && + subscription == other.subscription && + tags == other.tags && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(brand, content, name, routing, subscription, tags, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationTemplatePayload{brand=$brand, content=$content, name=$name, routing=$routing, subscription=$subscription, tags=$tags, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplatePublishRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplatePublishRequest.kt new file mode 100644 index 00000000..03ca91e3 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplatePublishRequest.kt @@ -0,0 +1,165 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +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 + +/** + * Optional request body for publishing a notification template. Omit or send an empty object to + * publish the current draft. + */ +class NotificationTemplatePublishRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val version: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of() + ) : this(version, mutableMapOf()) + + /** + * Historical version to publish (e.g. "v001"). Omit to publish the current draft. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun version(): Optional = version.getOptional("version") + + /** + * Returns the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + + @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 + * [NotificationTemplatePublishRequest]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationTemplatePublishRequest]. */ + class Builder internal constructor() { + + private var version: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationTemplatePublishRequest: NotificationTemplatePublishRequest) = + apply { + version = notificationTemplatePublishRequest.version + additionalProperties = + notificationTemplatePublishRequest.additionalProperties.toMutableMap() + } + + /** Historical version to publish (e.g. "v001"). Omit to publish the current draft. */ + fun version(version: String) = version(JsonField.of(version)) + + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun version(version: JsonField) = apply { this.version = version } + + 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 [NotificationTemplatePublishRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): NotificationTemplatePublishRequest = + NotificationTemplatePublishRequest(version, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): NotificationTemplatePublishRequest = apply { + if (validated) { + return@apply + } + + version() + 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 (version.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationTemplatePublishRequest && + version == other.version && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(version, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationTemplatePublishRequest{version=$version, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateSummary.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateSummary.kt new file mode 100644 index 00000000..554b46f7 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateSummary.kt @@ -0,0 +1,566 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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.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 + +/** V2 (CDS) template summary returned in list responses. */ +class NotificationTemplateSummary +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val created: JsonField, + private val creator: JsonField, + private val name: JsonField, + private val state: JsonField, + private val tags: 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("creator") @ExcludeMissing creator: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + @JsonProperty("updated") @ExcludeMissing updated: JsonField = JsonMissing.of(), + @JsonProperty("updater") @ExcludeMissing updater: JsonField = JsonMissing.of(), + ) : this(id, created, creator, name, state, tags, updated, updater, 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 id(): String = id.getRequired("id") + + /** + * Epoch milliseconds when the template 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(): Long = created.getRequired("created") + + /** + * User ID of the creator. + * + * @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 creator(): String = creator.getRequired("creator") + + /** + * @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") + + /** + * @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 state(): State = state.getRequired("state") + + /** + * @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 tags(): List = tags.getRequired("tags") + + /** + * Epoch milliseconds of 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") + + /** + * User 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 [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 [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 [state]. + * + * Unlike [state], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("state") @ExcludeMissing fun _state(): JsonField = state + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + /** + * 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 [NotificationTemplateSummary]. + * + * The following fields are required: + * ```java + * .id() + * .created() + * .creator() + * .name() + * .state() + * .tags() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationTemplateSummary]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var created: JsonField? = null + private var creator: JsonField? = null + private var name: JsonField? = null + private var state: JsonField? = null + private var tags: JsonField>? = null + private var updated: JsonField = JsonMissing.of() + private var updater: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationTemplateSummary: NotificationTemplateSummary) = apply { + id = notificationTemplateSummary.id + created = notificationTemplateSummary.created + creator = notificationTemplateSummary.creator + name = notificationTemplateSummary.name + state = notificationTemplateSummary.state + tags = notificationTemplateSummary.tags.map { it.toMutableList() } + updated = notificationTemplateSummary.updated + updater = notificationTemplateSummary.updater + additionalProperties = notificationTemplateSummary.additionalProperties.toMutableMap() + } + + 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 } + + /** Epoch milliseconds when the template was created. */ + fun created(created: Long) = created(JsonField.of(created)) + + /** + * Sets [Builder.created] to an arbitrary JSON value. + * + * You should usually call [Builder.created] with a well-typed [Long] 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 } + + /** User ID of the creator. */ + fun creator(creator: String) = creator(JsonField.of(creator)) + + /** + * 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 } + + 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 } + + fun state(state: State) = state(JsonField.of(state)) + + /** + * Sets [Builder.state] to an arbitrary JSON value. + * + * You should usually call [Builder.state] with a well-typed [State] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun state(state: JsonField) = apply { this.state = state } + + fun tags(tags: List) = tags(JsonField.of(tags)) + + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } + + /** Epoch milliseconds of last update. */ + fun updated(updated: Long) = updated(JsonField.of(updated)) + + /** + * Sets [Builder.updated] to an arbitrary JSON value. + * + * You should usually call [Builder.updated] with a well-typed [Long] 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 } + + /** User ID of the last updater. */ + fun updater(updater: String) = updater(JsonField.of(updater)) + + /** + * 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 [NotificationTemplateSummary]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .created() + * .creator() + * .name() + * .state() + * .tags() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationTemplateSummary = + NotificationTemplateSummary( + checkRequired("id", id), + checkRequired("created", created), + checkRequired("creator", creator), + checkRequired("name", name), + checkRequired("state", state), + checkRequired("tags", tags).map { it.toImmutable() }, + updated, + updater, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NotificationTemplateSummary = apply { + if (validated) { + return@apply + } + + id() + created() + creator() + name() + state().validate() + tags() + 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 (creator.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (state.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + + (if (updated.asKnown().isPresent) 1 else 0) + + (if (updater.asKnown().isPresent) 1 else 0) + + class State @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 DRAFT = of("DRAFT") + + @JvmField val PUBLISHED = of("PUBLISHED") + + @JvmStatic fun of(value: String) = State(JsonField.of(value)) + } + + /** An enum containing [State]'s known values. */ + enum class Known { + DRAFT, + PUBLISHED, + } + + /** + * An enum containing [State]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [State] 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 { + DRAFT, + PUBLISHED, + /** An enum member indicating that [State] 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) { + DRAFT -> Value.DRAFT + PUBLISHED -> Value.PUBLISHED + 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) { + DRAFT -> Known.DRAFT + PUBLISHED -> Known.PUBLISHED + else -> throw CourierInvalidDataException("Unknown State: $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 + + fun validate(): State = 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 State && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationTemplateSummary && + id == other.id && + created == other.created && + creator == other.creator && + name == other.name && + state == other.state && + tags == other.tags && + updated == other.updated && + updater == other.updater && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + created, + creator, + name, + state, + tags, + updated, + updater, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationTemplateSummary{id=$id, created=$created, creator=$creator, name=$name, state=$state, tags=$tags, updated=$updated, updater=$updater, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateUpdateRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateUpdateRequest.kt new file mode 100644 index 00000000..7e87677f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateUpdateRequest.kt @@ -0,0 +1,364 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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.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 + +/** + * Request body for replacing a notification template. Same shape as create. All fields required + * (PUT = full replacement). + */ +class NotificationTemplateUpdateRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val notification: JsonField, + private val state: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("notification") + @ExcludeMissing + notification: JsonField = JsonMissing.of(), + @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), + ) : this(notification, state, mutableMapOf()) + + /** + * Full document shape used in POST and PUT request bodies, and returned inside the GET response + * envelope. + * + * @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 notification(): NotificationTemplatePayload = notification.getRequired("notification") + + /** + * Template state after update. Case-insensitive input, normalized to uppercase in the response. + * Defaults to "DRAFT". + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun state(): Optional = state.getOptional("state") + + /** + * Returns the raw JSON value of [notification]. + * + * Unlike [notification], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("notification") + @ExcludeMissing + fun _notification(): JsonField = notification + + /** + * Returns the raw JSON value of [state]. + * + * Unlike [state], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("state") @ExcludeMissing fun _state(): JsonField = state + + @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 + * [NotificationTemplateUpdateRequest]. + * + * The following fields are required: + * ```java + * .notification() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationTemplateUpdateRequest]. */ + class Builder internal constructor() { + + private var notification: JsonField? = null + private var state: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationTemplateUpdateRequest: NotificationTemplateUpdateRequest) = + apply { + notification = notificationTemplateUpdateRequest.notification + state = notificationTemplateUpdateRequest.state + additionalProperties = + notificationTemplateUpdateRequest.additionalProperties.toMutableMap() + } + + /** + * Full document shape used in POST and PUT request bodies, and returned inside the GET + * response envelope. + */ + fun notification(notification: NotificationTemplatePayload) = + notification(JsonField.of(notification)) + + /** + * Sets [Builder.notification] to an arbitrary JSON value. + * + * You should usually call [Builder.notification] with a well-typed + * [NotificationTemplatePayload] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun notification(notification: JsonField) = apply { + this.notification = notification + } + + /** + * Template state after update. Case-insensitive input, normalized to uppercase in the + * response. Defaults to "DRAFT". + */ + fun state(state: State) = state(JsonField.of(state)) + + /** + * Sets [Builder.state] to an arbitrary JSON value. + * + * You should usually call [Builder.state] with a well-typed [State] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun state(state: JsonField) = apply { this.state = state } + + 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 [NotificationTemplateUpdateRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .notification() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationTemplateUpdateRequest = + NotificationTemplateUpdateRequest( + checkRequired("notification", notification), + state, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NotificationTemplateUpdateRequest = apply { + if (validated) { + return@apply + } + + notification().validate() + state().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 = + (notification.asKnown().getOrNull()?.validity() ?: 0) + + (state.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Template state after update. Case-insensitive input, normalized to uppercase in the response. + * Defaults to "DRAFT". + */ + class State @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 DRAFT = of("DRAFT") + + @JvmField val PUBLISHED = of("PUBLISHED") + + @JvmStatic fun of(value: String) = State(JsonField.of(value)) + } + + /** An enum containing [State]'s known values. */ + enum class Known { + DRAFT, + PUBLISHED, + } + + /** + * An enum containing [State]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [State] 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 { + DRAFT, + PUBLISHED, + /** An enum member indicating that [State] 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) { + DRAFT -> Value.DRAFT + PUBLISHED -> Value.PUBLISHED + 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) { + DRAFT -> Known.DRAFT + PUBLISHED -> Known.PUBLISHED + else -> throw CourierInvalidDataException("Unknown State: $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 + + fun validate(): State = 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 State && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationTemplateUpdateRequest && + notification == other.notification && + state == other.state && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(notification, state, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationTemplateUpdateRequest{notification=$notification, state=$state, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateVersionListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateVersionListResponse.kt new file mode 100644 index 00000000..cab84f9d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/NotificationTemplateVersionListResponse.kt @@ -0,0 +1,232 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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.Paging +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 + +class NotificationTemplateVersionListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val paging: JsonField, + private val versions: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("paging") @ExcludeMissing paging: JsonField = JsonMissing.of(), + @JsonProperty("versions") + @ExcludeMissing + versions: JsonField> = JsonMissing.of(), + ) : this(paging, versions, 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 paging(): Paging = paging.getRequired("paging") + + /** + * @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 versions(): List = versions.getRequired("versions") + + /** + * Returns the raw JSON value of [paging]. + * + * Unlike [paging], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("paging") @ExcludeMissing fun _paging(): JsonField = paging + + /** + * Returns the raw JSON value of [versions]. + * + * Unlike [versions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("versions") + @ExcludeMissing + fun _versions(): JsonField> = versions + + @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 + * [NotificationTemplateVersionListResponse]. + * + * The following fields are required: + * ```java + * .paging() + * .versions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationTemplateVersionListResponse]. */ + class Builder internal constructor() { + + private var paging: JsonField? = null + private var versions: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + notificationTemplateVersionListResponse: NotificationTemplateVersionListResponse + ) = apply { + paging = notificationTemplateVersionListResponse.paging + versions = notificationTemplateVersionListResponse.versions.map { it.toMutableList() } + additionalProperties = + notificationTemplateVersionListResponse.additionalProperties.toMutableMap() + } + + fun paging(paging: Paging) = paging(JsonField.of(paging)) + + /** + * Sets [Builder.paging] to an arbitrary JSON value. + * + * You should usually call [Builder.paging] with a well-typed [Paging] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun paging(paging: JsonField) = apply { this.paging = paging } + + fun versions(versions: List) = versions(JsonField.of(versions)) + + /** + * Sets [Builder.versions] to an arbitrary JSON value. + * + * You should usually call [Builder.versions] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun versions(versions: JsonField>) = apply { + this.versions = versions.map { it.toMutableList() } + } + + /** + * Adds a single [VersionNode] to [versions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addVersion(version: VersionNode) = apply { + versions = + (versions ?: JsonField.of(mutableListOf())).also { + checkKnown("versions", it).add(version) + } + } + + 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 [NotificationTemplateVersionListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .paging() + * .versions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationTemplateVersionListResponse = + NotificationTemplateVersionListResponse( + checkRequired("paging", paging), + checkRequired("versions", versions).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NotificationTemplateVersionListResponse = apply { + if (validated) { + return@apply + } + + paging().validate() + versions().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 = + (paging.asKnown().getOrNull()?.validity() ?: 0) + + (versions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationTemplateVersionListResponse && + paging == other.paging && + versions == other.versions && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(paging, versions, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationTemplateVersionListResponse{paging=$paging, versions=$versions, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/VersionNode.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/VersionNode.kt new file mode 100644 index 00000000..a03da177 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/VersionNode.kt @@ -0,0 +1,292 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 + +/** A version entry for a notification template. */ +class VersionNode +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val created: JsonField, + private val creator: JsonField, + private val version: JsonField, + private val hasChanges: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("created") @ExcludeMissing created: JsonField = JsonMissing.of(), + @JsonProperty("creator") @ExcludeMissing creator: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + @JsonProperty("has_changes") + @ExcludeMissing + hasChanges: JsonField = JsonMissing.of(), + ) : this(created, creator, version, hasChanges, mutableMapOf()) + + /** + * Epoch milliseconds when this version 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(): Long = created.getRequired("created") + + /** + * User ID of the version creator. + * + * @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 creator(): String = creator.getRequired("creator") + + /** + * Version identifier. One of "draft", "published:vNNN" (current published version), or "vNNN" + * (historical version). + * + * @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 version(): String = version.getRequired("version") + + /** + * Whether the draft has unpublished changes. Only present on the draft version. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun hasChanges(): Optional = hasChanges.getOptional("has_changes") + + /** + * 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 [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 [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + + /** + * Returns the raw JSON value of [hasChanges]. + * + * Unlike [hasChanges], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_changes") @ExcludeMissing fun _hasChanges(): JsonField = hasChanges + + @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 [VersionNode]. + * + * The following fields are required: + * ```java + * .created() + * .creator() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VersionNode]. */ + class Builder internal constructor() { + + private var created: JsonField? = null + private var creator: JsonField? = null + private var version: JsonField? = null + private var hasChanges: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(versionNode: VersionNode) = apply { + created = versionNode.created + creator = versionNode.creator + version = versionNode.version + hasChanges = versionNode.hasChanges + additionalProperties = versionNode.additionalProperties.toMutableMap() + } + + /** Epoch milliseconds when this version was created. */ + fun created(created: Long) = created(JsonField.of(created)) + + /** + * Sets [Builder.created] to an arbitrary JSON value. + * + * You should usually call [Builder.created] with a well-typed [Long] 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 } + + /** User ID of the version creator. */ + fun creator(creator: String) = creator(JsonField.of(creator)) + + /** + * 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 } + + /** + * Version identifier. One of "draft", "published:vNNN" (current published version), or + * "vNNN" (historical version). + */ + fun version(version: String) = version(JsonField.of(version)) + + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun version(version: JsonField) = apply { this.version = version } + + /** Whether the draft has unpublished changes. Only present on the draft version. */ + fun hasChanges(hasChanges: Boolean) = hasChanges(JsonField.of(hasChanges)) + + /** + * Sets [Builder.hasChanges] to an arbitrary JSON value. + * + * You should usually call [Builder.hasChanges] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun hasChanges(hasChanges: JsonField) = apply { this.hasChanges = hasChanges } + + 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 [VersionNode]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .created() + * .creator() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VersionNode = + VersionNode( + checkRequired("created", created), + checkRequired("creator", creator), + checkRequired("version", version), + hasChanges, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): VersionNode = apply { + if (validated) { + return@apply + } + + created() + creator() + version() + hasChanges() + 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 (created.asKnown().isPresent) 1 else 0) + + (if (creator.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + + (if (hasChanges.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VersionNode && + created == other.created && + creator == other.creator && + version == other.version && + hasChanges == other.hasChanges && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(created, creator, version, hasChanges, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VersionNode{created=$created, creator=$creator, version=$version, hasChanges=$hasChanges, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyArchiveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyArchiveParams.kt new file mode 100644 index 00000000..ffff2889 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyArchiveParams.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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 routing strategy. The strategy must not have associated notification templates. Unlink + * all templates before archiving. + */ +class RoutingStrategyArchiveParams +private constructor( + private val id: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** 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(): RoutingStrategyArchiveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [RoutingStrategyArchiveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyArchiveParams]. */ + class Builder internal constructor() { + + private var id: 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(routingStrategyArchiveParams: RoutingStrategyArchiveParams) = apply { + id = routingStrategyArchiveParams.id + additionalHeaders = routingStrategyArchiveParams.additionalHeaders.toBuilder() + additionalQueryParams = routingStrategyArchiveParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + routingStrategyArchiveParams.additionalBodyProperties.toMutableMap() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.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 [RoutingStrategyArchiveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RoutingStrategyArchiveParams = + RoutingStrategyArchiveParams( + id, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + 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 RoutingStrategyArchiveParams && + id == other.id && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(id, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "RoutingStrategyArchiveParams{id=$id, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateParams.kt new file mode 100644 index 00000000..0d9de2c6 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateParams.kt @@ -0,0 +1,209 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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 routing strategy. Requires a name and routing configuration at minimum. Channels and + * providers default to empty if omitted. + */ +class RoutingStrategyCreateParams +private constructor( + private val routingStrategyCreateRequest: RoutingStrategyCreateRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Request body for creating a routing strategy. */ + fun routingStrategyCreateRequest(): RoutingStrategyCreateRequest = routingStrategyCreateRequest + + fun _additionalBodyProperties(): Map = + routingStrategyCreateRequest._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 [RoutingStrategyCreateParams]. + * + * The following fields are required: + * ```java + * .routingStrategyCreateRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyCreateParams]. */ + class Builder internal constructor() { + + private var routingStrategyCreateRequest: RoutingStrategyCreateRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(routingStrategyCreateParams: RoutingStrategyCreateParams) = apply { + routingStrategyCreateRequest = routingStrategyCreateParams.routingStrategyCreateRequest + additionalHeaders = routingStrategyCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = routingStrategyCreateParams.additionalQueryParams.toBuilder() + } + + /** Request body for creating a routing strategy. */ + fun routingStrategyCreateRequest( + routingStrategyCreateRequest: RoutingStrategyCreateRequest + ) = apply { this.routingStrategyCreateRequest = routingStrategyCreateRequest } + + 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 [RoutingStrategyCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .routingStrategyCreateRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoutingStrategyCreateParams = + RoutingStrategyCreateParams( + checkRequired("routingStrategyCreateRequest", routingStrategyCreateRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): RoutingStrategyCreateRequest = routingStrategyCreateRequest + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoutingStrategyCreateParams && + routingStrategyCreateRequest == other.routingStrategyCreateRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(routingStrategyCreateRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoutingStrategyCreateParams{routingStrategyCreateRequest=$routingStrategyCreateRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateRequest.kt new file mode 100644 index 00000000..34f77e48 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateRequest.kt @@ -0,0 +1,395 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +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 routing strategy. */ +class RoutingStrategyCreateRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val name: JsonField, + private val routing: JsonField, + private val channels: JsonField, + private val description: JsonField, + private val providers: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("routing") + @ExcludeMissing + routing: JsonField = JsonMissing.of(), + @JsonProperty("channels") + @ExcludeMissing + channels: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("providers") + @ExcludeMissing + providers: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(name, routing, channels, description, providers, tags, mutableMapOf()) + + /** + * Human-readable name for the routing strategy. + * + * @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") + + /** + * Routing tree defining channel selection method and order. + * + * @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 routing(): MessageRouting = routing.getRequired("routing") + + /** + * Per-channel delivery configuration. 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 channels(): Optional = channels.getOptional("channels") + + /** + * Optional description of the routing strategy. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Per-provider delivery configuration. 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 providers(): Optional = providers.getOptional("providers") + + /** + * Optional tags for categorization. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tags(): Optional> = tags.getOptional("tags") + + /** + * 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 [routing]. + * + * Unlike [routing], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing") @ExcludeMissing fun _routing(): JsonField = routing + + /** + * Returns the raw JSON value of [channels]. + * + * Unlike [channels], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channels") @ExcludeMissing fun _channels(): JsonField = channels + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [providers]. + * + * Unlike [providers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("providers") + @ExcludeMissing + fun _providers(): JsonField = providers + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + @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 [RoutingStrategyCreateRequest]. + * + * The following fields are required: + * ```java + * .name() + * .routing() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyCreateRequest]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var routing: JsonField? = null + private var channels: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var providers: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(routingStrategyCreateRequest: RoutingStrategyCreateRequest) = apply { + name = routingStrategyCreateRequest.name + routing = routingStrategyCreateRequest.routing + channels = routingStrategyCreateRequest.channels + description = routingStrategyCreateRequest.description + providers = routingStrategyCreateRequest.providers + tags = routingStrategyCreateRequest.tags.map { it.toMutableList() } + additionalProperties = routingStrategyCreateRequest.additionalProperties.toMutableMap() + } + + /** Human-readable name for the routing strategy. */ + 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 } + + /** Routing tree defining channel selection method and order. */ + fun routing(routing: MessageRouting) = routing(JsonField.of(routing)) + + /** + * Sets [Builder.routing] to an arbitrary JSON value. + * + * You should usually call [Builder.routing] with a well-typed [MessageRouting] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun routing(routing: JsonField) = apply { this.routing = routing } + + /** Per-channel delivery configuration. Defaults to empty if omitted. */ + fun channels(channels: MessageChannels?) = channels(JsonField.ofNullable(channels)) + + /** Alias for calling [Builder.channels] with `channels.orElse(null)`. */ + fun channels(channels: Optional) = channels(channels.getOrNull()) + + /** + * Sets [Builder.channels] to an arbitrary JSON value. + * + * You should usually call [Builder.channels] with a well-typed [MessageChannels] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun channels(channels: JsonField) = apply { this.channels = channels } + + /** Optional description of the routing strategy. */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Per-provider delivery configuration. Defaults to empty if omitted. */ + fun providers(providers: MessageProviders?) = providers(JsonField.ofNullable(providers)) + + /** Alias for calling [Builder.providers] with `providers.orElse(null)`. */ + fun providers(providers: Optional) = providers(providers.getOrNull()) + + /** + * Sets [Builder.providers] to an arbitrary JSON value. + * + * You should usually call [Builder.providers] with a well-typed [MessageProviders] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun providers(providers: JsonField) = apply { this.providers = providers } + + /** Optional tags for categorization. */ + fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) + + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } + + 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 [RoutingStrategyCreateRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .routing() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoutingStrategyCreateRequest = + RoutingStrategyCreateRequest( + checkRequired("name", name), + checkRequired("routing", routing), + channels, + description, + providers, + (tags ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RoutingStrategyCreateRequest = apply { + if (validated) { + return@apply + } + + name() + routing().validate() + channels().ifPresent { it.validate() } + description() + providers().ifPresent { it.validate() } + tags() + 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) + + (routing.asKnown().getOrNull()?.validity() ?: 0) + + (channels.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (providers.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoutingStrategyCreateRequest && + name == other.name && + routing == other.routing && + channels == other.channels && + description == other.description && + providers == other.providers && + tags == other.tags && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(name, routing, channels, description, providers, tags, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoutingStrategyCreateRequest{name=$name, routing=$routing, channels=$channels, description=$description, providers=$providers, tags=$tags, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyGetResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyGetResponse.kt new file mode 100644 index 00000000..e21e6de9 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyGetResponse.kt @@ -0,0 +1,608 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +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 + +/** Full routing strategy entity returned by GET. */ +class RoutingStrategyGetResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val channels: JsonField, + private val created: JsonField, + private val creator: JsonField, + private val name: JsonField, + private val providers: JsonField, + private val routing: JsonField, + private val description: JsonField, + private val tags: JsonField>, + private val updated: JsonField, + private val updater: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("channels") + @ExcludeMissing + channels: JsonField = JsonMissing.of(), + @JsonProperty("created") @ExcludeMissing created: JsonField = JsonMissing.of(), + @JsonProperty("creator") @ExcludeMissing creator: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("providers") + @ExcludeMissing + providers: JsonField = JsonMissing.of(), + @JsonProperty("routing") + @ExcludeMissing + routing: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + @JsonProperty("updated") @ExcludeMissing updated: JsonField = JsonMissing.of(), + @JsonProperty("updater") @ExcludeMissing updater: JsonField = JsonMissing.of(), + ) : this( + id, + channels, + created, + creator, + name, + providers, + routing, + description, + tags, + updated, + updater, + mutableMapOf(), + ) + + /** + * The routing strategy ID (rs_ prefix). + * + * @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") + + /** + * Per-channel delivery configuration. 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 channels(): MessageChannels = channels.getRequired("channels") + + /** + * Epoch milliseconds when the strategy 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(): Long = created.getRequired("created") + + /** + * User ID of the creator. + * + * @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 creator(): String = creator.getRequired("creator") + + /** + * 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") + + /** + * Per-provider delivery configuration. 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 providers(): MessageProviders = providers.getRequired("providers") + + /** + * Routing tree defining channel selection method and order. + * + * @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 routing(): MessageRouting = routing.getRequired("routing") + + /** + * Description of the routing strategy. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Tags for categorization. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tags(): Optional> = tags.getOptional("tags") + + /** + * Epoch milliseconds of 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") + + /** + * User 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 [channels]. + * + * Unlike [channels], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channels") @ExcludeMissing fun _channels(): JsonField = channels + + /** + * 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 [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 [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 [providers]. + * + * Unlike [providers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("providers") + @ExcludeMissing + fun _providers(): JsonField = providers + + /** + * Returns the raw JSON value of [routing]. + * + * Unlike [routing], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing") @ExcludeMissing fun _routing(): JsonField = routing + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + /** + * 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 [RoutingStrategyGetResponse]. + * + * The following fields are required: + * ```java + * .id() + * .channels() + * .created() + * .creator() + * .name() + * .providers() + * .routing() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyGetResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var channels: JsonField? = null + private var created: JsonField? = null + private var creator: JsonField? = null + private var name: JsonField? = null + private var providers: JsonField? = null + private var routing: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var updated: JsonField = JsonMissing.of() + private var updater: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(routingStrategyGetResponse: RoutingStrategyGetResponse) = apply { + id = routingStrategyGetResponse.id + channels = routingStrategyGetResponse.channels + created = routingStrategyGetResponse.created + creator = routingStrategyGetResponse.creator + name = routingStrategyGetResponse.name + providers = routingStrategyGetResponse.providers + routing = routingStrategyGetResponse.routing + description = routingStrategyGetResponse.description + tags = routingStrategyGetResponse.tags.map { it.toMutableList() } + updated = routingStrategyGetResponse.updated + updater = routingStrategyGetResponse.updater + additionalProperties = routingStrategyGetResponse.additionalProperties.toMutableMap() + } + + /** The routing strategy ID (rs_ prefix). */ + 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 } + + /** Per-channel delivery configuration. May be empty. */ + fun channels(channels: MessageChannels) = channels(JsonField.of(channels)) + + /** + * Sets [Builder.channels] to an arbitrary JSON value. + * + * You should usually call [Builder.channels] with a well-typed [MessageChannels] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun channels(channels: JsonField) = apply { this.channels = channels } + + /** Epoch milliseconds when the strategy was created. */ + fun created(created: Long) = created(JsonField.of(created)) + + /** + * Sets [Builder.created] to an arbitrary JSON value. + * + * You should usually call [Builder.created] with a well-typed [Long] 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 } + + /** User ID of the creator. */ + fun creator(creator: String) = creator(JsonField.of(creator)) + + /** + * 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 } + + /** 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 } + + /** Per-provider delivery configuration. May be empty. */ + fun providers(providers: MessageProviders) = providers(JsonField.of(providers)) + + /** + * Sets [Builder.providers] to an arbitrary JSON value. + * + * You should usually call [Builder.providers] with a well-typed [MessageProviders] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun providers(providers: JsonField) = apply { this.providers = providers } + + /** Routing tree defining channel selection method and order. */ + fun routing(routing: MessageRouting) = routing(JsonField.of(routing)) + + /** + * Sets [Builder.routing] to an arbitrary JSON value. + * + * You should usually call [Builder.routing] with a well-typed [MessageRouting] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun routing(routing: JsonField) = apply { this.routing = routing } + + /** Description of the routing strategy. */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Tags for categorization. */ + fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) + + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } + + /** Epoch milliseconds of last update. */ + fun updated(updated: Long?) = updated(JsonField.ofNullable(updated)) + + /** + * Alias for [Builder.updated]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun updated(updated: Long) = updated(updated as Long?) + + /** 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 [Long] 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 } + + /** User 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 [RoutingStrategyGetResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .channels() + * .created() + * .creator() + * .name() + * .providers() + * .routing() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoutingStrategyGetResponse = + RoutingStrategyGetResponse( + checkRequired("id", id), + checkRequired("channels", channels), + checkRequired("created", created), + checkRequired("creator", creator), + checkRequired("name", name), + checkRequired("providers", providers), + checkRequired("routing", routing), + description, + (tags ?: JsonMissing.of()).map { it.toImmutable() }, + updated, + updater, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RoutingStrategyGetResponse = apply { + if (validated) { + return@apply + } + + id() + channels().validate() + created() + creator() + name() + providers().validate() + routing().validate() + description() + tags() + 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) + + (channels.asKnown().getOrNull()?.validity() ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (creator.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (providers.asKnown().getOrNull()?.validity() ?: 0) + + (routing.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (tags.asKnown().getOrNull()?.size ?: 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 RoutingStrategyGetResponse && + id == other.id && + channels == other.channels && + created == other.created && + creator == other.creator && + name == other.name && + providers == other.providers && + routing == other.routing && + description == other.description && + tags == other.tags && + updated == other.updated && + updater == other.updater && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + channels, + created, + creator, + name, + providers, + routing, + description, + tags, + updated, + updater, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoutingStrategyGetResponse{id=$id, channels=$channels, created=$created, creator=$creator, name=$name, providers=$providers, routing=$routing, description=$description, tags=$tags, updated=$updated, updater=$updater, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyListParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyListParams.kt new file mode 100644 index 00000000..4ef4a7be --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyListParams.kt @@ -0,0 +1,223 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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 routing strategies in your workspace. Returns metadata only (no routing/channels/providers + * content). Use GET /routing-strategies/{id} for full details. + */ +class RoutingStrategyListParams +private constructor( + private val cursor: String?, + private val limit: Long?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Opaque pagination cursor from a previous response. Omit for the first page. */ + fun cursor(): Optional = Optional.ofNullable(cursor) + + /** Maximum number of results per page. Default 20, max 100. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** 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(): RoutingStrategyListParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [RoutingStrategyListParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyListParams]. */ + class Builder internal constructor() { + + private var cursor: String? = null + private var limit: Long? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(routingStrategyListParams: RoutingStrategyListParams) = apply { + cursor = routingStrategyListParams.cursor + limit = routingStrategyListParams.limit + additionalHeaders = routingStrategyListParams.additionalHeaders.toBuilder() + additionalQueryParams = routingStrategyListParams.additionalQueryParams.toBuilder() + } + + /** Opaque pagination cursor from a previous response. Omit for the first page. */ + fun cursor(cursor: String?) = apply { this.cursor = cursor } + + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + + /** Maximum number of results per page. Default 20, max 100. */ + fun limit(limit: Long?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.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 [RoutingStrategyListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RoutingStrategyListParams = + RoutingStrategyListParams( + cursor, + limit, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + cursor?.let { put("cursor", it) } + limit?.let { put("limit", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoutingStrategyListParams && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoutingStrategyListParams{cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyListResponse.kt new file mode 100644 index 00000000..0f8601d7 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyListResponse.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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.Paging +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 + +/** Paginated list of routing strategy summaries. */ +class RoutingStrategyListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val paging: JsonField, + private val results: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("paging") @ExcludeMissing paging: JsonField = JsonMissing.of(), + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of(), + ) : this(paging, 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 paging(): Paging = paging.getRequired("paging") + + /** + * @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 [paging]. + * + * Unlike [paging], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("paging") @ExcludeMissing fun _paging(): JsonField = paging + + /** + * 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 [RoutingStrategyListResponse]. + * + * The following fields are required: + * ```java + * .paging() + * .results() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyListResponse]. */ + class Builder internal constructor() { + + private var paging: JsonField? = null + private var results: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(routingStrategyListResponse: RoutingStrategyListResponse) = apply { + paging = routingStrategyListResponse.paging + results = routingStrategyListResponse.results.map { it.toMutableList() } + additionalProperties = routingStrategyListResponse.additionalProperties.toMutableMap() + } + + fun paging(paging: Paging) = paging(JsonField.of(paging)) + + /** + * Sets [Builder.paging] to an arbitrary JSON value. + * + * You should usually call [Builder.paging] with a well-typed [Paging] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun paging(paging: JsonField) = apply { this.paging = paging } + + 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 [RoutingStrategySummary] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: RoutingStrategySummary) = 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 [RoutingStrategyListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .paging() + * .results() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoutingStrategyListResponse = + RoutingStrategyListResponse( + checkRequired("paging", paging), + checkRequired("results", results).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RoutingStrategyListResponse = apply { + if (validated) { + return@apply + } + + paging().validate() + 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 = + (paging.asKnown().getOrNull()?.validity() ?: 0) + + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoutingStrategyListResponse && + paging == other.paging && + results == other.results && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(paging, results, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoutingStrategyListResponse{paging=$paging, results=$results, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyMutationResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyMutationResponse.kt new file mode 100644 index 00000000..278eaab6 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyMutationResponse.kt @@ -0,0 +1,177 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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 + +/** Response returned by create and replace operations. */ +class RoutingStrategyMutationResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() + ) : this(id, mutableMapOf()) + + /** + * The routing strategy ID (rs_ prefix). + * + * @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") + + /** + * 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 + + @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 + * [RoutingStrategyMutationResponse]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyMutationResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(routingStrategyMutationResponse: RoutingStrategyMutationResponse) = + apply { + id = routingStrategyMutationResponse.id + additionalProperties = + routingStrategyMutationResponse.additionalProperties.toMutableMap() + } + + /** The routing strategy ID (rs_ prefix). */ + 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 } + + 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 [RoutingStrategyMutationResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoutingStrategyMutationResponse = + RoutingStrategyMutationResponse( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RoutingStrategyMutationResponse = apply { + if (validated) { + return@apply + } + + id() + 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) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoutingStrategyMutationResponse && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoutingStrategyMutationResponse{id=$id, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceParams.kt new file mode 100644 index 00000000..65e5ec00 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceParams.kt @@ -0,0 +1,237 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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 routing strategy. Full document replacement; the caller must send the complete desired + * state. Missing optional fields are cleared. + */ +class RoutingStrategyReplaceParams +private constructor( + private val id: String?, + private val routingStrategyReplaceRequest: RoutingStrategyReplaceRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** + * Request body for replacing a routing strategy. Full document replacement; missing optional + * fields are cleared. + */ + fun routingStrategyReplaceRequest(): RoutingStrategyReplaceRequest = + routingStrategyReplaceRequest + + fun _additionalBodyProperties(): Map = + routingStrategyReplaceRequest._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 [RoutingStrategyReplaceParams]. + * + * The following fields are required: + * ```java + * .routingStrategyReplaceRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyReplaceParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var routingStrategyReplaceRequest: RoutingStrategyReplaceRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(routingStrategyReplaceParams: RoutingStrategyReplaceParams) = apply { + id = routingStrategyReplaceParams.id + routingStrategyReplaceRequest = + routingStrategyReplaceParams.routingStrategyReplaceRequest + additionalHeaders = routingStrategyReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = routingStrategyReplaceParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + /** + * Request body for replacing a routing strategy. Full document replacement; missing + * optional fields are cleared. + */ + fun routingStrategyReplaceRequest( + routingStrategyReplaceRequest: RoutingStrategyReplaceRequest + ) = apply { this.routingStrategyReplaceRequest = routingStrategyReplaceRequest } + + 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 [RoutingStrategyReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .routingStrategyReplaceRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoutingStrategyReplaceParams = + RoutingStrategyReplaceParams( + id, + checkRequired("routingStrategyReplaceRequest", routingStrategyReplaceRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): RoutingStrategyReplaceRequest = routingStrategyReplaceRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + 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 RoutingStrategyReplaceParams && + id == other.id && + routingStrategyReplaceRequest == other.routingStrategyReplaceRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(id, routingStrategyReplaceRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoutingStrategyReplaceParams{id=$id, routingStrategyReplaceRequest=$routingStrategyReplaceRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceRequest.kt new file mode 100644 index 00000000..a390c581 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceRequest.kt @@ -0,0 +1,399 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +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 routing strategy. Full document replacement; missing optional fields + * are cleared. + */ +class RoutingStrategyReplaceRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val name: JsonField, + private val routing: JsonField, + private val channels: JsonField, + private val description: JsonField, + private val providers: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("routing") + @ExcludeMissing + routing: JsonField = JsonMissing.of(), + @JsonProperty("channels") + @ExcludeMissing + channels: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("providers") + @ExcludeMissing + providers: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(name, routing, channels, description, providers, tags, mutableMapOf()) + + /** + * Human-readable name for the routing strategy. + * + * @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") + + /** + * Routing tree defining channel selection method and order. + * + * @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 routing(): MessageRouting = routing.getRequired("routing") + + /** + * Per-channel delivery configuration. Omit to clear. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun channels(): Optional = channels.getOptional("channels") + + /** + * Optional description. Omit or null to clear. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Per-provider delivery configuration. Omit to clear. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun providers(): Optional = providers.getOptional("providers") + + /** + * Optional tags. Omit or null to clear. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tags(): Optional> = tags.getOptional("tags") + + /** + * 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 [routing]. + * + * Unlike [routing], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing") @ExcludeMissing fun _routing(): JsonField = routing + + /** + * Returns the raw JSON value of [channels]. + * + * Unlike [channels], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channels") @ExcludeMissing fun _channels(): JsonField = channels + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [providers]. + * + * Unlike [providers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("providers") + @ExcludeMissing + fun _providers(): JsonField = providers + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + @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 + * [RoutingStrategyReplaceRequest]. + * + * The following fields are required: + * ```java + * .name() + * .routing() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyReplaceRequest]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var routing: JsonField? = null + private var channels: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var providers: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(routingStrategyReplaceRequest: RoutingStrategyReplaceRequest) = apply { + name = routingStrategyReplaceRequest.name + routing = routingStrategyReplaceRequest.routing + channels = routingStrategyReplaceRequest.channels + description = routingStrategyReplaceRequest.description + providers = routingStrategyReplaceRequest.providers + tags = routingStrategyReplaceRequest.tags.map { it.toMutableList() } + additionalProperties = routingStrategyReplaceRequest.additionalProperties.toMutableMap() + } + + /** Human-readable name for the routing strategy. */ + 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 } + + /** Routing tree defining channel selection method and order. */ + fun routing(routing: MessageRouting) = routing(JsonField.of(routing)) + + /** + * Sets [Builder.routing] to an arbitrary JSON value. + * + * You should usually call [Builder.routing] with a well-typed [MessageRouting] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun routing(routing: JsonField) = apply { this.routing = routing } + + /** Per-channel delivery configuration. Omit to clear. */ + fun channels(channels: MessageChannels?) = channels(JsonField.ofNullable(channels)) + + /** Alias for calling [Builder.channels] with `channels.orElse(null)`. */ + fun channels(channels: Optional) = channels(channels.getOrNull()) + + /** + * Sets [Builder.channels] to an arbitrary JSON value. + * + * You should usually call [Builder.channels] with a well-typed [MessageChannels] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun channels(channels: JsonField) = apply { this.channels = channels } + + /** Optional description. Omit or null to clear. */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Per-provider delivery configuration. Omit to clear. */ + fun providers(providers: MessageProviders?) = providers(JsonField.ofNullable(providers)) + + /** Alias for calling [Builder.providers] with `providers.orElse(null)`. */ + fun providers(providers: Optional) = providers(providers.getOrNull()) + + /** + * Sets [Builder.providers] to an arbitrary JSON value. + * + * You should usually call [Builder.providers] with a well-typed [MessageProviders] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun providers(providers: JsonField) = apply { this.providers = providers } + + /** Optional tags. Omit or null to clear. */ + fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) + + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } + + 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 [RoutingStrategyReplaceRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .routing() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoutingStrategyReplaceRequest = + RoutingStrategyReplaceRequest( + checkRequired("name", name), + checkRequired("routing", routing), + channels, + description, + providers, + (tags ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RoutingStrategyReplaceRequest = apply { + if (validated) { + return@apply + } + + name() + routing().validate() + channels().ifPresent { it.validate() } + description() + providers().ifPresent { it.validate() } + tags() + 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) + + (routing.asKnown().getOrNull()?.validity() ?: 0) + + (channels.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (providers.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoutingStrategyReplaceRequest && + name == other.name && + routing == other.routing && + channels == other.channels && + description == other.description && + providers == other.providers && + tags == other.tags && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(name, routing, channels, description, providers, tags, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoutingStrategyReplaceRequest{name=$name, routing=$routing, channels=$channels, description=$description, providers=$providers, tags=$tags, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyRetrieveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyRetrieveParams.kt new file mode 100644 index 00000000..a8ba8e13 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategyRetrieveParams.kt @@ -0,0 +1,199 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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 routing strategy by ID. Returns the full entity including routing content and + * metadata. + */ +class RoutingStrategyRetrieveParams +private constructor( + private val id: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** 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(): RoutingStrategyRetrieveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [RoutingStrategyRetrieveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategyRetrieveParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(routingStrategyRetrieveParams: RoutingStrategyRetrieveParams) = apply { + id = routingStrategyRetrieveParams.id + additionalHeaders = routingStrategyRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = routingStrategyRetrieveParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.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 [RoutingStrategyRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RoutingStrategyRetrieveParams = + RoutingStrategyRetrieveParams( + id, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + 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 RoutingStrategyRetrieveParams && + id == other.id && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(id, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoutingStrategyRetrieveParams{id=$id, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategySummary.kt b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategySummary.kt new file mode 100644 index 00000000..b5834bc8 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/routingstrategies/RoutingStrategySummary.kt @@ -0,0 +1,473 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Routing strategy metadata returned in list responses. Does not include routing/channels/providers + * content. + */ +class RoutingStrategySummary +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val created: JsonField, + private val creator: JsonField, + private val name: JsonField, + private val description: JsonField, + private val tags: 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("creator") @ExcludeMissing creator: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + @JsonProperty("updated") @ExcludeMissing updated: JsonField = JsonMissing.of(), + @JsonProperty("updater") @ExcludeMissing updater: JsonField = JsonMissing.of(), + ) : this(id, created, creator, name, description, tags, updated, updater, mutableMapOf()) + + /** + * The routing strategy ID (rs_ prefix). + * + * @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") + + /** + * Epoch milliseconds when the strategy 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(): Long = created.getRequired("created") + + /** + * User ID of the creator. + * + * @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 creator(): String = creator.getRequired("creator") + + /** + * 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") + + /** + * Description of the routing strategy. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Tags for categorization. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tags(): Optional> = tags.getOptional("tags") + + /** + * Epoch milliseconds of 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") + + /** + * User 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 [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 [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 [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + /** + * 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 [RoutingStrategySummary]. + * + * The following fields are required: + * ```java + * .id() + * .created() + * .creator() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoutingStrategySummary]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var created: JsonField? = null + private var creator: JsonField? = null + private var name: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var updated: JsonField = JsonMissing.of() + private var updater: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(routingStrategySummary: RoutingStrategySummary) = apply { + id = routingStrategySummary.id + created = routingStrategySummary.created + creator = routingStrategySummary.creator + name = routingStrategySummary.name + description = routingStrategySummary.description + tags = routingStrategySummary.tags.map { it.toMutableList() } + updated = routingStrategySummary.updated + updater = routingStrategySummary.updater + additionalProperties = routingStrategySummary.additionalProperties.toMutableMap() + } + + /** The routing strategy ID (rs_ prefix). */ + 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 } + + /** Epoch milliseconds when the strategy was created. */ + fun created(created: Long) = created(JsonField.of(created)) + + /** + * Sets [Builder.created] to an arbitrary JSON value. + * + * You should usually call [Builder.created] with a well-typed [Long] 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 } + + /** User ID of the creator. */ + fun creator(creator: String) = creator(JsonField.of(creator)) + + /** + * 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 } + + /** 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 } + + /** Description of the routing strategy. */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Tags for categorization. */ + fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) + + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } + + /** Epoch milliseconds of last update. */ + fun updated(updated: Long?) = updated(JsonField.ofNullable(updated)) + + /** + * Alias for [Builder.updated]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun updated(updated: Long) = updated(updated as Long?) + + /** 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 [Long] 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 } + + /** User 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 [RoutingStrategySummary]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .created() + * .creator() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoutingStrategySummary = + RoutingStrategySummary( + checkRequired("id", id), + checkRequired("created", created), + checkRequired("creator", creator), + checkRequired("name", name), + description, + (tags ?: JsonMissing.of()).map { it.toImmutable() }, + updated, + updater, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RoutingStrategySummary = apply { + if (validated) { + return@apply + } + + id() + created() + creator() + name() + description() + tags() + 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 (creator.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (tags.asKnown().getOrNull()?.size ?: 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 RoutingStrategySummary && + id == other.id && + created == other.created && + creator == other.creator && + name == other.name && + description == other.description && + tags == other.tags && + updated == other.updated && + updater == other.updater && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + created, + creator, + name, + description, + tags, + updated, + updater, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoutingStrategySummary{id=$id, created=$created, creator=$creator, name=$name, description=$description, tags=$tags, updated=$updated, updater=$updater, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/send/SendMessageParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/send/SendMessageParams.kt index db5cea79..6ab54e4b 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/send/SendMessageParams.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/send/SendMessageParams.kt @@ -23,7 +23,9 @@ import com.courier.models.ElementalContent import com.courier.models.ElementalContentSugar import com.courier.models.ListPatternRecipient import com.courier.models.ListRecipient +import com.courier.models.MessageChannels import com.courier.models.MessageContext +import com.courier.models.MessageProviders import com.courier.models.MessageRouting import com.courier.models.MessageRoutingChannel import com.courier.models.MsTeamsRecipient @@ -444,7 +446,7 @@ private constructor( @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val brandId: JsonField, - private val channels: JsonField, + private val channels: JsonField, private val content: JsonField, private val context: JsonField, private val data: JsonField, @@ -452,7 +454,7 @@ private constructor( private val expiry: JsonField, private val metadata: JsonField, private val preferences: JsonField, - private val providers: JsonField, + private val providers: JsonField, private val routing: JsonField, private val template: JsonField, private val timeout: JsonField, @@ -465,7 +467,7 @@ private constructor( @JsonProperty("brand_id") @ExcludeMissing brandId: JsonField = JsonMissing.of(), @JsonProperty("channels") @ExcludeMissing - channels: JsonField = JsonMissing.of(), + channels: JsonField = JsonMissing.of(), @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), @JsonProperty("context") @ExcludeMissing @@ -481,7 +483,7 @@ private constructor( preferences: JsonField = JsonMissing.of(), @JsonProperty("providers") @ExcludeMissing - providers: JsonField = JsonMissing.of(), + providers: JsonField = JsonMissing.of(), @JsonProperty("routing") @ExcludeMissing routing: JsonField = JsonMissing.of(), @JsonProperty("template") @ExcludeMissing @@ -519,7 +521,7 @@ private constructor( * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun channels(): Optional = channels.getOptional("channels") + fun channels(): Optional = channels.getOptional("channels") /** * Describes content that will work for email, inbox, push, chat, or any channel id. @@ -569,7 +571,7 @@ private constructor( * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun providers(): Optional = providers.getOptional("providers") + fun providers(): Optional = providers.getOptional("providers") /** * Customize which channels/providers Courier may deliver the message through. @@ -611,7 +613,9 @@ private constructor( * * Unlike [channels], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("channels") @ExcludeMissing fun _channels(): JsonField = channels + @JsonProperty("channels") + @ExcludeMissing + fun _channels(): JsonField = channels /** * Returns the raw JSON value of [content]. @@ -671,7 +675,7 @@ private constructor( */ @JsonProperty("providers") @ExcludeMissing - fun _providers(): JsonField = providers + fun _providers(): JsonField = providers /** * Returns the raw JSON value of [routing]. @@ -723,7 +727,7 @@ private constructor( class Builder internal constructor() { private var brandId: JsonField = JsonMissing.of() - private var channels: JsonField = JsonMissing.of() + private var channels: JsonField = JsonMissing.of() private var content: JsonField = JsonMissing.of() private var context: JsonField = JsonMissing.of() private var data: JsonField = JsonMissing.of() @@ -731,7 +735,7 @@ private constructor( private var expiry: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() private var preferences: JsonField = JsonMissing.of() - private var providers: JsonField = JsonMissing.of() + private var providers: JsonField = JsonMissing.of() private var routing: JsonField = JsonMissing.of() private var template: JsonField = JsonMissing.of() private var timeout: JsonField = JsonMissing.of() @@ -775,19 +779,19 @@ private constructor( * Define run-time configuration for channels. Valid ChannelId's: email, sms, push, * inbox, direct_message, banner, webhook. */ - fun channels(channels: Channels?) = channels(JsonField.ofNullable(channels)) + fun channels(channels: MessageChannels?) = channels(JsonField.ofNullable(channels)) /** Alias for calling [Builder.channels] with `channels.orElse(null)`. */ - fun channels(channels: Optional) = channels(channels.getOrNull()) + fun channels(channels: Optional) = channels(channels.getOrNull()) /** * Sets [Builder.channels] to an arbitrary JSON value. * - * You should usually call [Builder.channels] with a well-typed [Channels] value + * You should usually call [Builder.channels] with a well-typed [MessageChannels] value * instead. This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun channels(channels: JsonField) = apply { this.channels = channels } + fun channels(channels: JsonField) = apply { this.channels = channels } /** Describes content that will work for email, inbox, push, chat, or any channel id. */ fun content(content: Content) = content(JsonField.of(content)) @@ -899,19 +903,21 @@ private constructor( this.preferences = preferences } - fun providers(providers: Providers?) = providers(JsonField.ofNullable(providers)) + fun providers(providers: MessageProviders?) = providers(JsonField.ofNullable(providers)) /** Alias for calling [Builder.providers] with `providers.orElse(null)`. */ - fun providers(providers: Optional) = providers(providers.getOrNull()) + fun providers(providers: Optional) = providers(providers.getOrNull()) /** * Sets [Builder.providers] to an arbitrary JSON value. * - * You should usually call [Builder.providers] with a well-typed [Providers] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.providers] with a well-typed [MessageProviders] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. */ - fun providers(providers: JsonField) = apply { this.providers = providers } + fun providers(providers: JsonField) = apply { + this.providers = providers + } /** Customize which channels/providers Courier may deliver the message through. */ fun routing(routing: Routing?) = routing(JsonField.ofNullable(routing)) @@ -1100,112 +1106,6 @@ private constructor( (timeout.asKnown().getOrNull()?.validity() ?: 0) + (to.asKnown().getOrNull()?.validity() ?: 0) - /** - * Define run-time configuration for channels. Valid ChannelId's: email, sms, push, inbox, - * direct_message, banner, webhook. - */ - class Channels - @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 [Channels]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Channels]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(channels: Channels) = apply { - additionalProperties = channels.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 [Channels]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Channels = Channels(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Channels = 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 Channels && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Channels{additionalProperties=$additionalProperties}" - } - /** Describes content that will work for email, inbox, push, chat, or any channel id. */ @JsonDeserialize(using = Content.Deserializer::class) @JsonSerialize(using = Content.Serializer::class) @@ -2591,108 +2491,6 @@ private constructor( "Preferences{subscriptionTopicId=$subscriptionTopicId, additionalProperties=$additionalProperties}" } - class Providers - @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 [Providers]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Providers]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(providers: Providers) = apply { - additionalProperties = providers.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 [Providers]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Providers = Providers(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Providers = 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 Providers && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Providers{additionalProperties=$additionalProperties}" - } - /** Customize which channels/providers Courier may deliver the message through. */ class Routing @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/courier-java-core/src/main/kotlin/com/courier/models/tenants/TenantTemplateInput.kt b/courier-java-core/src/main/kotlin/com/courier/models/tenants/TenantTemplateInput.kt index 4570b92f..5bec0cc7 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/tenants/TenantTemplateInput.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/tenants/TenantTemplateInput.kt @@ -7,9 +7,10 @@ import com.courier.core.JsonField import com.courier.core.JsonMissing import com.courier.core.JsonValue import com.courier.core.checkRequired -import com.courier.core.toImmutable import com.courier.errors.CourierInvalidDataException import com.courier.models.ElementalContent +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders import com.courier.models.MessageRouting import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -25,8 +26,8 @@ class TenantTemplateInput @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val content: JsonField, - private val channels: JsonField, - private val providers: JsonField, + private val channels: JsonField, + private val providers: JsonField, private val routing: JsonField, private val additionalProperties: MutableMap, ) { @@ -36,10 +37,12 @@ private constructor( @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), - @JsonProperty("channels") @ExcludeMissing channels: JsonField = JsonMissing.of(), + @JsonProperty("channels") + @ExcludeMissing + channels: JsonField = JsonMissing.of(), @JsonProperty("providers") @ExcludeMissing - providers: JsonField = JsonMissing.of(), + providers: JsonField = JsonMissing.of(), @JsonProperty("routing") @ExcludeMissing routing: JsonField = JsonMissing.of(), @@ -59,7 +62,7 @@ private constructor( * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun channels(): Optional = channels.getOptional("channels") + fun channels(): Optional = channels.getOptional("channels") /** * Provider-specific delivery configuration for routing to specific email/SMS providers @@ -67,7 +70,7 @@ private constructor( * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun providers(): Optional = providers.getOptional("providers") + fun providers(): Optional = providers.getOptional("providers") /** * Message routing configuration for multi-channel delivery strategies @@ -89,14 +92,16 @@ private constructor( * * Unlike [channels], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("channels") @ExcludeMissing fun _channels(): JsonField = channels + @JsonProperty("channels") @ExcludeMissing fun _channels(): JsonField = channels /** * Returns the raw JSON value of [providers]. * * Unlike [providers], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("providers") @ExcludeMissing fun _providers(): JsonField = providers + @JsonProperty("providers") + @ExcludeMissing + fun _providers(): JsonField = providers /** * Returns the raw JSON value of [routing]. @@ -134,8 +139,8 @@ private constructor( class Builder internal constructor() { private var content: JsonField? = null - private var channels: JsonField = JsonMissing.of() - private var providers: JsonField = JsonMissing.of() + private var channels: JsonField = JsonMissing.of() + private var providers: JsonField = JsonMissing.of() private var routing: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -161,28 +166,28 @@ private constructor( fun content(content: JsonField) = apply { this.content = content } /** Channel-specific delivery configuration (email, SMS, push, etc.) */ - fun channels(channels: Channels) = channels(JsonField.of(channels)) + fun channels(channels: MessageChannels) = channels(JsonField.of(channels)) /** * Sets [Builder.channels] to an arbitrary JSON value. * - * You should usually call [Builder.channels] with a well-typed [Channels] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * You should usually call [Builder.channels] with a well-typed [MessageChannels] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun channels(channels: JsonField) = apply { this.channels = channels } + fun channels(channels: JsonField) = apply { this.channels = channels } /** Provider-specific delivery configuration for routing to specific email/SMS providers */ - fun providers(providers: Providers) = providers(JsonField.of(providers)) + fun providers(providers: MessageProviders) = providers(JsonField.of(providers)) /** * Sets [Builder.providers] to an arbitrary JSON value. * - * You should usually call [Builder.providers] with a well-typed [Providers] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * You should usually call [Builder.providers] with a well-typed [MessageProviders] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun providers(providers: JsonField) = apply { this.providers = providers } + fun providers(providers: JsonField) = apply { this.providers = providers } /** Message routing configuration for multi-channel delivery strategies */ fun routing(routing: MessageRouting) = routing(JsonField.of(routing)) @@ -271,206 +276,6 @@ private constructor( (providers.asKnown().getOrNull()?.validity() ?: 0) + (routing.asKnown().getOrNull()?.validity() ?: 0) - /** Channel-specific delivery configuration (email, SMS, push, etc.) */ - class Channels - @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 [Channels]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Channels]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(channels: Channels) = apply { - additionalProperties = channels.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 [Channels]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Channels = Channels(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Channels = 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 Channels && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Channels{additionalProperties=$additionalProperties}" - } - - /** Provider-specific delivery configuration for routing to specific email/SMS providers */ - class Providers - @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 [Providers]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Providers]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(providers: Providers) = apply { - additionalProperties = providers.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 [Providers]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Providers = Providers(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Providers = 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 Providers && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Providers{additionalProperties=$additionalProperties}" - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsync.kt index 7cb2c3ed..991501ca 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsync.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsync.kt @@ -4,11 +4,22 @@ 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.notifications.NotificationArchiveParams +import com.courier.models.notifications.NotificationCreateParams import com.courier.models.notifications.NotificationGetContent import com.courier.models.notifications.NotificationListParams import com.courier.models.notifications.NotificationListResponse +import com.courier.models.notifications.NotificationListVersionsParams +import com.courier.models.notifications.NotificationPublishParams +import com.courier.models.notifications.NotificationReplaceParams import com.courier.models.notifications.NotificationRetrieveContentParams +import com.courier.models.notifications.NotificationRetrieveParams +import com.courier.models.notifications.NotificationTemplateCreateRequest +import com.courier.models.notifications.NotificationTemplateGetResponse +import com.courier.models.notifications.NotificationTemplateMutationResponse +import com.courier.models.notifications.NotificationTemplateVersionListResponse import com.courier.services.async.notifications.CheckServiceAsync import com.courier.services.async.notifications.DraftServiceAsync import java.util.concurrent.CompletableFuture @@ -32,6 +43,80 @@ interface NotificationServiceAsync { fun checks(): CheckServiceAsync + /** + * Create a notification template. Requires all fields in the notification object. Templates are + * created in draft state by default. + */ + fun create( + params: NotificationCreateParams + ): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: NotificationCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see create */ + fun create( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + create( + NotificationCreateParams.builder() + .notificationTemplateCreateRequest(notificationTemplateCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest + ): CompletableFuture = + create(notificationTemplateCreateRequest, RequestOptions.none()) + + /** + * Retrieve a notification template by ID. Returns the published version by default. Pass + * version=draft to retrieve an unpublished template. + */ + fun retrieve(id: String): CompletableFuture = + retrieve(id, NotificationRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: NotificationRetrieveParams = NotificationRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: NotificationRetrieveParams = NotificationRetrieveParams.none(), + ): CompletableFuture = + retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: NotificationRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve( + params: NotificationRetrieveParams + ): CompletableFuture = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(id, NotificationRetrieveParams.none(), requestOptions) + + /** List notification templates in your workspace. */ fun list(): CompletableFuture = list(NotificationListParams.none()) /** @see list */ @@ -49,6 +134,136 @@ interface NotificationServiceAsync { fun list(requestOptions: RequestOptions): CompletableFuture = list(NotificationListParams.none(), requestOptions) + /** Archive a notification template. */ + fun archive(id: String): CompletableFuture = + archive(id, NotificationArchiveParams.none()) + + /** @see archive */ + fun archive( + id: String, + params: NotificationArchiveParams = NotificationArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = archive(params.toBuilder().id(id).build(), requestOptions) + + /** @see archive */ + fun archive( + id: String, + params: NotificationArchiveParams = NotificationArchiveParams.none(), + ): CompletableFuture = archive(id, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: NotificationArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see archive */ + fun archive(params: NotificationArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(id: String, requestOptions: RequestOptions): CompletableFuture = + archive(id, NotificationArchiveParams.none(), requestOptions) + + /** List versions of a notification template. */ + fun listVersions(id: String): CompletableFuture = + listVersions(id, NotificationListVersionsParams.none()) + + /** @see listVersions */ + fun listVersions( + id: String, + params: NotificationListVersionsParams = NotificationListVersionsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + listVersions(params.toBuilder().id(id).build(), requestOptions) + + /** @see listVersions */ + fun listVersions( + id: String, + params: NotificationListVersionsParams = NotificationListVersionsParams.none(), + ): CompletableFuture = + listVersions(id, params, RequestOptions.none()) + + /** @see listVersions */ + fun listVersions( + params: NotificationListVersionsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see listVersions */ + fun listVersions( + params: NotificationListVersionsParams + ): CompletableFuture = + listVersions(params, RequestOptions.none()) + + /** @see listVersions */ + fun listVersions( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture = + listVersions(id, NotificationListVersionsParams.none(), requestOptions) + + /** + * Publish a notification template. Publishes the current draft by default. Pass a version in + * the request body to publish a specific historical version. + */ + fun publish(id: String): CompletableFuture = + publish(id, NotificationPublishParams.none()) + + /** @see publish */ + fun publish( + id: String, + params: NotificationPublishParams = NotificationPublishParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = publish(params.toBuilder().id(id).build(), requestOptions) + + /** @see publish */ + fun publish( + id: String, + params: NotificationPublishParams = NotificationPublishParams.none(), + ): CompletableFuture = publish(id, params, RequestOptions.none()) + + /** @see publish */ + fun publish( + params: NotificationPublishParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see publish */ + fun publish(params: NotificationPublishParams): CompletableFuture = + publish(params, RequestOptions.none()) + + /** @see publish */ + fun publish(id: String, requestOptions: RequestOptions): CompletableFuture = + publish(id, NotificationPublishParams.none(), requestOptions) + + /** Replace a notification template. All fields are required. */ + fun replace( + id: String, + params: NotificationReplaceParams, + ): CompletableFuture = + replace(id, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + id: String, + params: NotificationReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + replace(params.toBuilder().id(id).build(), requestOptions) + + /** @see replace */ + fun replace( + params: NotificationReplaceParams + ): CompletableFuture = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: NotificationReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + fun retrieveContent(id: String): CompletableFuture = retrieveContent(id, NotificationRetrieveContentParams.none()) @@ -104,6 +319,82 @@ interface NotificationServiceAsync { fun checks(): CheckServiceAsync.WithRawResponse + /** + * Returns a raw HTTP response for `post /notifications`, but is otherwise the same as + * [NotificationServiceAsync.create]. + */ + fun create( + params: NotificationCreateParams + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: NotificationCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see create */ + fun create( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + create( + NotificationCreateParams.builder() + .notificationTemplateCreateRequest(notificationTemplateCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest + ): CompletableFuture> = + create(notificationTemplateCreateRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /notifications/{id}`, but is otherwise the same as + * [NotificationServiceAsync.retrieve]. + */ + fun retrieve( + id: String + ): CompletableFuture> = + retrieve(id, NotificationRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: NotificationRetrieveParams = NotificationRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: NotificationRetrieveParams = NotificationRetrieveParams.none(), + ): CompletableFuture> = + retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: NotificationRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: NotificationRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(id, NotificationRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /notifications`, but is otherwise the same as * [NotificationServiceAsync.list]. @@ -129,6 +420,149 @@ interface NotificationServiceAsync { ): CompletableFuture> = list(NotificationListParams.none(), requestOptions) + /** + * Returns a raw HTTP response for `delete /notifications/{id}`, but is otherwise the same + * as [NotificationServiceAsync.archive]. + */ + fun archive(id: String): CompletableFuture = + archive(id, NotificationArchiveParams.none()) + + /** @see archive */ + fun archive( + id: String, + params: NotificationArchiveParams = NotificationArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archive(params.toBuilder().id(id).build(), requestOptions) + + /** @see archive */ + fun archive( + id: String, + params: NotificationArchiveParams = NotificationArchiveParams.none(), + ): CompletableFuture = archive(id, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: NotificationArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see archive */ + fun archive(params: NotificationArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(id: String, requestOptions: RequestOptions): CompletableFuture = + archive(id, NotificationArchiveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /notifications/{id}/versions`, but is otherwise the + * same as [NotificationServiceAsync.listVersions]. + */ + fun listVersions( + id: String + ): CompletableFuture> = + listVersions(id, NotificationListVersionsParams.none()) + + /** @see listVersions */ + fun listVersions( + id: String, + params: NotificationListVersionsParams = NotificationListVersionsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + listVersions(params.toBuilder().id(id).build(), requestOptions) + + /** @see listVersions */ + fun listVersions( + id: String, + params: NotificationListVersionsParams = NotificationListVersionsParams.none(), + ): CompletableFuture> = + listVersions(id, params, RequestOptions.none()) + + /** @see listVersions */ + fun listVersions( + params: NotificationListVersionsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see listVersions */ + fun listVersions( + params: NotificationListVersionsParams + ): CompletableFuture> = + listVersions(params, RequestOptions.none()) + + /** @see listVersions */ + fun listVersions( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + listVersions(id, NotificationListVersionsParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /notifications/{id}/publish`, but is otherwise the + * same as [NotificationServiceAsync.publish]. + */ + fun publish(id: String): CompletableFuture = + publish(id, NotificationPublishParams.none()) + + /** @see publish */ + fun publish( + id: String, + params: NotificationPublishParams = NotificationPublishParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + publish(params.toBuilder().id(id).build(), requestOptions) + + /** @see publish */ + fun publish( + id: String, + params: NotificationPublishParams = NotificationPublishParams.none(), + ): CompletableFuture = publish(id, params, RequestOptions.none()) + + /** @see publish */ + fun publish( + params: NotificationPublishParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see publish */ + fun publish(params: NotificationPublishParams): CompletableFuture = + publish(params, RequestOptions.none()) + + /** @see publish */ + fun publish(id: String, requestOptions: RequestOptions): CompletableFuture = + publish(id, NotificationPublishParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /notifications/{id}`, but is otherwise the same as + * [NotificationServiceAsync.replace]. + */ + fun replace( + id: String, + params: NotificationReplaceParams, + ): CompletableFuture> = + replace(id, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + id: String, + params: NotificationReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + replace(params.toBuilder().id(id).build(), requestOptions) + + /** @see replace */ + fun replace( + params: NotificationReplaceParams + ): CompletableFuture> = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: NotificationReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get /notifications/{id}/content`, but is otherwise the * same as [NotificationServiceAsync.retrieveContent]. diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsyncImpl.kt index 4a21e0c3..dc2f578a 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsyncImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsyncImpl.kt @@ -5,6 +5,7 @@ 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 @@ -13,12 +14,22 @@ 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.notifications.NotificationArchiveParams +import com.courier.models.notifications.NotificationCreateParams import com.courier.models.notifications.NotificationGetContent import com.courier.models.notifications.NotificationListParams import com.courier.models.notifications.NotificationListResponse +import com.courier.models.notifications.NotificationListVersionsParams +import com.courier.models.notifications.NotificationPublishParams +import com.courier.models.notifications.NotificationReplaceParams import com.courier.models.notifications.NotificationRetrieveContentParams +import com.courier.models.notifications.NotificationRetrieveParams +import com.courier.models.notifications.NotificationTemplateGetResponse +import com.courier.models.notifications.NotificationTemplateMutationResponse +import com.courier.models.notifications.NotificationTemplateVersionListResponse import com.courier.services.async.notifications.CheckServiceAsync import com.courier.services.async.notifications.CheckServiceAsyncImpl import com.courier.services.async.notifications.DraftServiceAsync @@ -47,6 +58,20 @@ class NotificationServiceAsyncImpl internal constructor(private val clientOption override fun checks(): CheckServiceAsync = checks + override fun create( + params: NotificationCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /notifications + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: NotificationRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /notifications/{id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun list( params: NotificationListParams, requestOptions: RequestOptions, @@ -54,6 +79,34 @@ class NotificationServiceAsyncImpl internal constructor(private val clientOption // get /notifications withRawResponse().list(params, requestOptions).thenApply { it.parse() } + override fun archive( + params: NotificationArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /notifications/{id} + withRawResponse().archive(params, requestOptions).thenAccept {} + + override fun listVersions( + params: NotificationListVersionsParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /notifications/{id}/versions + withRawResponse().listVersions(params, requestOptions).thenApply { it.parse() } + + override fun publish( + params: NotificationPublishParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /notifications/{id}/publish + withRawResponse().publish(params, requestOptions).thenAccept {} + + override fun replace( + params: NotificationReplaceParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // put /notifications/{id} + withRawResponse().replace(params, requestOptions).thenApply { it.parse() } + override fun retrieveContent( params: NotificationRetrieveContentParams, requestOptions: RequestOptions, @@ -86,6 +139,70 @@ class NotificationServiceAsyncImpl internal constructor(private val clientOption override fun checks(): CheckServiceAsync.WithRawResponse = checks + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: NotificationCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications") + .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: NotificationRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", 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) @@ -116,6 +233,127 @@ class NotificationServiceAsyncImpl internal constructor(private val clientOption } } + private val archiveHandler: Handler = emptyHandler() + + override fun archive( + params: NotificationArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", 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 listVersionsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listVersions( + params: NotificationListVersionsParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", params._pathParam(0), "versions") + .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 { listVersionsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val publishHandler: Handler = emptyHandler() + + override fun publish( + params: NotificationPublishParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", params._pathParam(0), "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) } + } + } + } + + private val replaceHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun replace( + params: NotificationReplaceParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", 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() + } + } + } + } + } + private val retrieveContentHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/RoutingStrategyServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/RoutingStrategyServiceAsync.kt new file mode 100644 index 00000000..73e241f5 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/RoutingStrategyServiceAsync.kt @@ -0,0 +1,370 @@ +// 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.routingstrategies.RoutingStrategyArchiveParams +import com.courier.models.routingstrategies.RoutingStrategyCreateParams +import com.courier.models.routingstrategies.RoutingStrategyCreateRequest +import com.courier.models.routingstrategies.RoutingStrategyGetResponse +import com.courier.models.routingstrategies.RoutingStrategyListParams +import com.courier.models.routingstrategies.RoutingStrategyListResponse +import com.courier.models.routingstrategies.RoutingStrategyMutationResponse +import com.courier.models.routingstrategies.RoutingStrategyReplaceParams +import com.courier.models.routingstrategies.RoutingStrategyRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface RoutingStrategyServiceAsync { + + /** + * 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): RoutingStrategyServiceAsync + + /** + * Create a routing strategy. Requires a name and routing configuration at minimum. Channels and + * providers default to empty if omitted. + */ + fun create( + params: RoutingStrategyCreateParams + ): CompletableFuture = create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: RoutingStrategyCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see create */ + fun create( + routingStrategyCreateRequest: RoutingStrategyCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + create( + RoutingStrategyCreateParams.builder() + .routingStrategyCreateRequest(routingStrategyCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + routingStrategyCreateRequest: RoutingStrategyCreateRequest + ): CompletableFuture = + create(routingStrategyCreateRequest, RequestOptions.none()) + + /** + * Retrieve a routing strategy by ID. Returns the full entity including routing content and + * metadata. + */ + fun retrieve(id: String): CompletableFuture = + retrieve(id, RoutingStrategyRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: RoutingStrategyRetrieveParams = RoutingStrategyRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: RoutingStrategyRetrieveParams = RoutingStrategyRetrieveParams.none(), + ): CompletableFuture = retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoutingStrategyRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve( + params: RoutingStrategyRetrieveParams + ): CompletableFuture = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(id, RoutingStrategyRetrieveParams.none(), requestOptions) + + /** + * List routing strategies in your workspace. Returns metadata only (no + * routing/channels/providers content). Use GET /routing-strategies/{id} for full details. + */ + fun list(): CompletableFuture = + list(RoutingStrategyListParams.none()) + + /** @see list */ + fun list( + params: RoutingStrategyListParams = RoutingStrategyListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: RoutingStrategyListParams = RoutingStrategyListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(RoutingStrategyListParams.none(), requestOptions) + + /** + * Archive a routing strategy. The strategy must not have associated notification templates. + * Unlink all templates before archiving. + */ + fun archive(id: String): CompletableFuture = + archive(id, RoutingStrategyArchiveParams.none()) + + /** @see archive */ + fun archive( + id: String, + params: RoutingStrategyArchiveParams = RoutingStrategyArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = archive(params.toBuilder().id(id).build(), requestOptions) + + /** @see archive */ + fun archive( + id: String, + params: RoutingStrategyArchiveParams = RoutingStrategyArchiveParams.none(), + ): CompletableFuture = archive(id, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: RoutingStrategyArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see archive */ + fun archive(params: RoutingStrategyArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(id: String, requestOptions: RequestOptions): CompletableFuture = + archive(id, RoutingStrategyArchiveParams.none(), requestOptions) + + /** + * Replace a routing strategy. Full document replacement; the caller must send the complete + * desired state. Missing optional fields are cleared. + */ + fun replace( + id: String, + params: RoutingStrategyReplaceParams, + ): CompletableFuture = + replace(id, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + id: String, + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + replace(params.toBuilder().id(id).build(), requestOptions) + + /** @see replace */ + fun replace( + params: RoutingStrategyReplaceParams + ): CompletableFuture = replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [RoutingStrategyServiceAsync] 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 + ): RoutingStrategyServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /routing-strategies`, but is otherwise the same as + * [RoutingStrategyServiceAsync.create]. + */ + fun create( + params: RoutingStrategyCreateParams + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: RoutingStrategyCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see create */ + fun create( + routingStrategyCreateRequest: RoutingStrategyCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + create( + RoutingStrategyCreateParams.builder() + .routingStrategyCreateRequest(routingStrategyCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + routingStrategyCreateRequest: RoutingStrategyCreateRequest + ): CompletableFuture> = + create(routingStrategyCreateRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /routing-strategies/{id}`, but is otherwise the same + * as [RoutingStrategyServiceAsync.retrieve]. + */ + fun retrieve(id: String): CompletableFuture> = + retrieve(id, RoutingStrategyRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: RoutingStrategyRetrieveParams = RoutingStrategyRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: RoutingStrategyRetrieveParams = RoutingStrategyRetrieveParams.none(), + ): CompletableFuture> = + retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoutingStrategyRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: RoutingStrategyRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(id, RoutingStrategyRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /routing-strategies`, but is otherwise the same as + * [RoutingStrategyServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(RoutingStrategyListParams.none()) + + /** @see list */ + fun list( + params: RoutingStrategyListParams = RoutingStrategyListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: RoutingStrategyListParams = RoutingStrategyListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(RoutingStrategyListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /routing-strategies/{id}`, but is otherwise the + * same as [RoutingStrategyServiceAsync.archive]. + */ + fun archive(id: String): CompletableFuture = + archive(id, RoutingStrategyArchiveParams.none()) + + /** @see archive */ + fun archive( + id: String, + params: RoutingStrategyArchiveParams = RoutingStrategyArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archive(params.toBuilder().id(id).build(), requestOptions) + + /** @see archive */ + fun archive( + id: String, + params: RoutingStrategyArchiveParams = RoutingStrategyArchiveParams.none(), + ): CompletableFuture = archive(id, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: RoutingStrategyArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see archive */ + fun archive(params: RoutingStrategyArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(id: String, requestOptions: RequestOptions): CompletableFuture = + archive(id, RoutingStrategyArchiveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /routing-strategies/{id}`, but is otherwise the same + * as [RoutingStrategyServiceAsync.replace]. + */ + fun replace( + id: String, + params: RoutingStrategyReplaceParams, + ): CompletableFuture> = + replace(id, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + id: String, + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + replace(params.toBuilder().id(id).build(), requestOptions) + + /** @see replace */ + fun replace( + params: RoutingStrategyReplaceParams + ): CompletableFuture> = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/RoutingStrategyServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/RoutingStrategyServiceAsyncImpl.kt new file mode 100644 index 00000000..c0738e53 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/RoutingStrategyServiceAsyncImpl.kt @@ -0,0 +1,249 @@ +// 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.routingstrategies.RoutingStrategyArchiveParams +import com.courier.models.routingstrategies.RoutingStrategyCreateParams +import com.courier.models.routingstrategies.RoutingStrategyGetResponse +import com.courier.models.routingstrategies.RoutingStrategyListParams +import com.courier.models.routingstrategies.RoutingStrategyListResponse +import com.courier.models.routingstrategies.RoutingStrategyMutationResponse +import com.courier.models.routingstrategies.RoutingStrategyReplaceParams +import com.courier.models.routingstrategies.RoutingStrategyRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class RoutingStrategyServiceAsyncImpl +internal constructor(private val clientOptions: ClientOptions) : RoutingStrategyServiceAsync { + + private val withRawResponse: RoutingStrategyServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RoutingStrategyServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions( + modifier: Consumer + ): RoutingStrategyServiceAsync = + RoutingStrategyServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: RoutingStrategyCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /routing-strategies + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: RoutingStrategyRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /routing-strategies/{id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: RoutingStrategyListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /routing-strategies + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun archive( + params: RoutingStrategyArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /routing-strategies/{id} + withRawResponse().archive(params, requestOptions).thenAccept {} + + override fun replace( + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // put /routing-strategies/{id} + withRawResponse().replace(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RoutingStrategyServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RoutingStrategyServiceAsync.WithRawResponse = + RoutingStrategyServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: RoutingStrategyCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies") + .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: RoutingStrategyRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies", 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: RoutingStrategyListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies") + .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: RoutingStrategyArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies", 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 replaceHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun replace( + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies", 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/blocking/NotificationService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationService.kt index b316e37a..18fee24e 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationService.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationService.kt @@ -4,11 +4,22 @@ 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.notifications.NotificationArchiveParams +import com.courier.models.notifications.NotificationCreateParams import com.courier.models.notifications.NotificationGetContent import com.courier.models.notifications.NotificationListParams import com.courier.models.notifications.NotificationListResponse +import com.courier.models.notifications.NotificationListVersionsParams +import com.courier.models.notifications.NotificationPublishParams +import com.courier.models.notifications.NotificationReplaceParams import com.courier.models.notifications.NotificationRetrieveContentParams +import com.courier.models.notifications.NotificationRetrieveParams +import com.courier.models.notifications.NotificationTemplateCreateRequest +import com.courier.models.notifications.NotificationTemplateGetResponse +import com.courier.models.notifications.NotificationTemplateMutationResponse +import com.courier.models.notifications.NotificationTemplateVersionListResponse import com.courier.services.blocking.notifications.CheckService import com.courier.services.blocking.notifications.DraftService import com.google.errorprone.annotations.MustBeClosed @@ -32,6 +43,72 @@ interface NotificationService { fun checks(): CheckService + /** + * Create a notification template. Requires all fields in the notification object. Templates are + * created in draft state by default. + */ + fun create(params: NotificationCreateParams): NotificationTemplateMutationResponse = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: NotificationCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationTemplateMutationResponse + + /** @see create */ + fun create( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationTemplateMutationResponse = + create( + NotificationCreateParams.builder() + .notificationTemplateCreateRequest(notificationTemplateCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest + ): NotificationTemplateMutationResponse = + create(notificationTemplateCreateRequest, RequestOptions.none()) + + /** + * Retrieve a notification template by ID. Returns the published version by default. Pass + * version=draft to retrieve an unpublished template. + */ + fun retrieve(id: String): NotificationTemplateGetResponse = + retrieve(id, NotificationRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: NotificationRetrieveParams = NotificationRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationTemplateGetResponse = retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: NotificationRetrieveParams = NotificationRetrieveParams.none(), + ): NotificationTemplateGetResponse = retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: NotificationRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationTemplateGetResponse + + /** @see retrieve */ + fun retrieve(params: NotificationRetrieveParams): NotificationTemplateGetResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(id: String, requestOptions: RequestOptions): NotificationTemplateGetResponse = + retrieve(id, NotificationRetrieveParams.none(), requestOptions) + + /** List notification templates in your workspace. */ fun list(): NotificationListResponse = list(NotificationListParams.none()) /** @see list */ @@ -49,6 +126,123 @@ interface NotificationService { fun list(requestOptions: RequestOptions): NotificationListResponse = list(NotificationListParams.none(), requestOptions) + /** Archive a notification template. */ + fun archive(id: String) = archive(id, NotificationArchiveParams.none()) + + /** @see archive */ + fun archive( + id: String, + params: NotificationArchiveParams = NotificationArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ) = archive(params.toBuilder().id(id).build(), requestOptions) + + /** @see archive */ + fun archive(id: String, params: NotificationArchiveParams = NotificationArchiveParams.none()) = + archive(id, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: NotificationArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ) + + /** @see archive */ + fun archive(params: NotificationArchiveParams) = archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(id: String, requestOptions: RequestOptions) = + archive(id, NotificationArchiveParams.none(), requestOptions) + + /** List versions of a notification template. */ + fun listVersions(id: String): NotificationTemplateVersionListResponse = + listVersions(id, NotificationListVersionsParams.none()) + + /** @see listVersions */ + fun listVersions( + id: String, + params: NotificationListVersionsParams = NotificationListVersionsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationTemplateVersionListResponse = + listVersions(params.toBuilder().id(id).build(), requestOptions) + + /** @see listVersions */ + fun listVersions( + id: String, + params: NotificationListVersionsParams = NotificationListVersionsParams.none(), + ): NotificationTemplateVersionListResponse = listVersions(id, params, RequestOptions.none()) + + /** @see listVersions */ + fun listVersions( + params: NotificationListVersionsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationTemplateVersionListResponse + + /** @see listVersions */ + fun listVersions( + params: NotificationListVersionsParams + ): NotificationTemplateVersionListResponse = listVersions(params, RequestOptions.none()) + + /** @see listVersions */ + fun listVersions( + id: String, + requestOptions: RequestOptions, + ): NotificationTemplateVersionListResponse = + listVersions(id, NotificationListVersionsParams.none(), requestOptions) + + /** + * Publish a notification template. Publishes the current draft by default. Pass a version in + * the request body to publish a specific historical version. + */ + fun publish(id: String) = publish(id, NotificationPublishParams.none()) + + /** @see publish */ + fun publish( + id: String, + params: NotificationPublishParams = NotificationPublishParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ) = publish(params.toBuilder().id(id).build(), requestOptions) + + /** @see publish */ + fun publish(id: String, params: NotificationPublishParams = NotificationPublishParams.none()) = + publish(id, params, RequestOptions.none()) + + /** @see publish */ + fun publish( + params: NotificationPublishParams, + requestOptions: RequestOptions = RequestOptions.none(), + ) + + /** @see publish */ + fun publish(params: NotificationPublishParams) = publish(params, RequestOptions.none()) + + /** @see publish */ + fun publish(id: String, requestOptions: RequestOptions) = + publish(id, NotificationPublishParams.none(), requestOptions) + + /** Replace a notification template. All fields are required. */ + fun replace( + id: String, + params: NotificationReplaceParams, + ): NotificationTemplateMutationResponse = replace(id, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + id: String, + params: NotificationReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationTemplateMutationResponse = + replace(params.toBuilder().id(id).build(), requestOptions) + + /** @see replace */ + fun replace(params: NotificationReplaceParams): NotificationTemplateMutationResponse = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: NotificationReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationTemplateMutationResponse + fun retrieveContent(id: String): NotificationGetContent = retrieveContent(id, NotificationRetrieveContentParams.none()) @@ -97,6 +291,90 @@ interface NotificationService { fun checks(): CheckService.WithRawResponse + /** + * Returns a raw HTTP response for `post /notifications`, but is otherwise the same as + * [NotificationService.create]. + */ + @MustBeClosed + fun create( + params: NotificationCreateParams + ): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: NotificationCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see create */ + @MustBeClosed + fun create( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + create( + NotificationCreateParams.builder() + .notificationTemplateCreateRequest(notificationTemplateCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + @MustBeClosed + fun create( + notificationTemplateCreateRequest: NotificationTemplateCreateRequest + ): HttpResponseFor = + create(notificationTemplateCreateRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /notifications/{id}`, but is otherwise the same as + * [NotificationService.retrieve]. + */ + @MustBeClosed + fun retrieve(id: String): HttpResponseFor = + retrieve(id, NotificationRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + params: NotificationRetrieveParams = NotificationRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + params: NotificationRetrieveParams = NotificationRetrieveParams.none(), + ): HttpResponseFor = + retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: NotificationRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: NotificationRetrieveParams + ): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(id, NotificationRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /notifications`, but is otherwise the same as * [NotificationService.list]. @@ -122,6 +400,165 @@ interface NotificationService { fun list(requestOptions: RequestOptions): HttpResponseFor = list(NotificationListParams.none(), requestOptions) + /** + * Returns a raw HTTP response for `delete /notifications/{id}`, but is otherwise the same + * as [NotificationService.archive]. + */ + @MustBeClosed + fun archive(id: String): HttpResponse = archive(id, NotificationArchiveParams.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + id: String, + params: NotificationArchiveParams = NotificationArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = archive(params.toBuilder().id(id).build(), requestOptions) + + /** @see archive */ + @MustBeClosed + fun archive( + id: String, + params: NotificationArchiveParams = NotificationArchiveParams.none(), + ): HttpResponse = archive(id, params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + params: NotificationArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** @see archive */ + @MustBeClosed + fun archive(params: NotificationArchiveParams): HttpResponse = + archive(params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive(id: String, requestOptions: RequestOptions): HttpResponse = + archive(id, NotificationArchiveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /notifications/{id}/versions`, but is otherwise the + * same as [NotificationService.listVersions]. + */ + @MustBeClosed + fun listVersions(id: String): HttpResponseFor = + listVersions(id, NotificationListVersionsParams.none()) + + /** @see listVersions */ + @MustBeClosed + fun listVersions( + id: String, + params: NotificationListVersionsParams = NotificationListVersionsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + listVersions(params.toBuilder().id(id).build(), requestOptions) + + /** @see listVersions */ + @MustBeClosed + fun listVersions( + id: String, + params: NotificationListVersionsParams = NotificationListVersionsParams.none(), + ): HttpResponseFor = + listVersions(id, params, RequestOptions.none()) + + /** @see listVersions */ + @MustBeClosed + fun listVersions( + params: NotificationListVersionsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see listVersions */ + @MustBeClosed + fun listVersions( + params: NotificationListVersionsParams + ): HttpResponseFor = + listVersions(params, RequestOptions.none()) + + /** @see listVersions */ + @MustBeClosed + fun listVersions( + id: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + listVersions(id, NotificationListVersionsParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /notifications/{id}/publish`, but is otherwise the + * same as [NotificationService.publish]. + */ + @MustBeClosed + fun publish(id: String): HttpResponse = publish(id, NotificationPublishParams.none()) + + /** @see publish */ + @MustBeClosed + fun publish( + id: String, + params: NotificationPublishParams = NotificationPublishParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = publish(params.toBuilder().id(id).build(), requestOptions) + + /** @see publish */ + @MustBeClosed + fun publish( + id: String, + params: NotificationPublishParams = NotificationPublishParams.none(), + ): HttpResponse = publish(id, params, RequestOptions.none()) + + /** @see publish */ + @MustBeClosed + fun publish( + params: NotificationPublishParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** @see publish */ + @MustBeClosed + fun publish(params: NotificationPublishParams): HttpResponse = + publish(params, RequestOptions.none()) + + /** @see publish */ + @MustBeClosed + fun publish(id: String, requestOptions: RequestOptions): HttpResponse = + publish(id, NotificationPublishParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /notifications/{id}`, but is otherwise the same as + * [NotificationService.replace]. + */ + @MustBeClosed + fun replace( + id: String, + params: NotificationReplaceParams, + ): HttpResponseFor = + replace(id, params, RequestOptions.none()) + + /** @see replace */ + @MustBeClosed + fun replace( + id: String, + params: NotificationReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + replace(params.toBuilder().id(id).build(), requestOptions) + + /** @see replace */ + @MustBeClosed + fun replace( + params: NotificationReplaceParams + ): HttpResponseFor = + replace(params, RequestOptions.none()) + + /** @see replace */ + @MustBeClosed + fun replace( + params: NotificationReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get /notifications/{id}/content`, but is otherwise the * same as [NotificationService.retrieveContent]. diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationServiceImpl.kt index dc6f4de3..ba780b8a 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationServiceImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationServiceImpl.kt @@ -5,6 +5,7 @@ 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 @@ -13,12 +14,22 @@ 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.notifications.NotificationArchiveParams +import com.courier.models.notifications.NotificationCreateParams import com.courier.models.notifications.NotificationGetContent import com.courier.models.notifications.NotificationListParams import com.courier.models.notifications.NotificationListResponse +import com.courier.models.notifications.NotificationListVersionsParams +import com.courier.models.notifications.NotificationPublishParams +import com.courier.models.notifications.NotificationReplaceParams import com.courier.models.notifications.NotificationRetrieveContentParams +import com.courier.models.notifications.NotificationRetrieveParams +import com.courier.models.notifications.NotificationTemplateGetResponse +import com.courier.models.notifications.NotificationTemplateMutationResponse +import com.courier.models.notifications.NotificationTemplateVersionListResponse import com.courier.services.blocking.notifications.CheckService import com.courier.services.blocking.notifications.CheckServiceImpl import com.courier.services.blocking.notifications.DraftService @@ -46,6 +57,20 @@ class NotificationServiceImpl internal constructor(private val clientOptions: Cl override fun checks(): CheckService = checks + override fun create( + params: NotificationCreateParams, + requestOptions: RequestOptions, + ): NotificationTemplateMutationResponse = + // post /notifications + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve( + params: NotificationRetrieveParams, + requestOptions: RequestOptions, + ): NotificationTemplateGetResponse = + // get /notifications/{id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun list( params: NotificationListParams, requestOptions: RequestOptions, @@ -53,6 +78,30 @@ class NotificationServiceImpl internal constructor(private val clientOptions: Cl // get /notifications withRawResponse().list(params, requestOptions).parse() + override fun archive(params: NotificationArchiveParams, requestOptions: RequestOptions) { + // delete /notifications/{id} + withRawResponse().archive(params, requestOptions) + } + + override fun listVersions( + params: NotificationListVersionsParams, + requestOptions: RequestOptions, + ): NotificationTemplateVersionListResponse = + // get /notifications/{id}/versions + withRawResponse().listVersions(params, requestOptions).parse() + + override fun publish(params: NotificationPublishParams, requestOptions: RequestOptions) { + // post /notifications/{id}/publish + withRawResponse().publish(params, requestOptions) + } + + override fun replace( + params: NotificationReplaceParams, + requestOptions: RequestOptions, + ): NotificationTemplateMutationResponse = + // put /notifications/{id} + withRawResponse().replace(params, requestOptions).parse() + override fun retrieveContent( params: NotificationRetrieveContentParams, requestOptions: RequestOptions, @@ -85,6 +134,64 @@ class NotificationServiceImpl internal constructor(private val clientOptions: Cl override fun checks(): CheckService.WithRawResponse = checks + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: NotificationCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications") + .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: NotificationRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", 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) @@ -112,6 +219,115 @@ class NotificationServiceImpl internal constructor(private val clientOptions: Cl } } + private val archiveHandler: Handler = emptyHandler() + + override fun archive( + params: NotificationArchiveParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", 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 listVersionsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listVersions( + params: NotificationListVersionsParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", params._pathParam(0), "versions") + .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 { listVersionsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val publishHandler: Handler = emptyHandler() + + override fun publish( + params: NotificationPublishParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", params._pathParam(0), "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) } + } + } + + private val replaceHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun replace( + params: NotificationReplaceParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", 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() + } + } + } + } + private val retrieveContentHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/RoutingStrategyService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/RoutingStrategyService.kt new file mode 100644 index 00000000..781eefdd --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/RoutingStrategyService.kt @@ -0,0 +1,370 @@ +// 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.routingstrategies.RoutingStrategyArchiveParams +import com.courier.models.routingstrategies.RoutingStrategyCreateParams +import com.courier.models.routingstrategies.RoutingStrategyCreateRequest +import com.courier.models.routingstrategies.RoutingStrategyGetResponse +import com.courier.models.routingstrategies.RoutingStrategyListParams +import com.courier.models.routingstrategies.RoutingStrategyListResponse +import com.courier.models.routingstrategies.RoutingStrategyMutationResponse +import com.courier.models.routingstrategies.RoutingStrategyReplaceParams +import com.courier.models.routingstrategies.RoutingStrategyRetrieveParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface RoutingStrategyService { + + /** + * 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): RoutingStrategyService + + /** + * Create a routing strategy. Requires a name and routing configuration at minimum. Channels and + * providers default to empty if omitted. + */ + fun create(params: RoutingStrategyCreateParams): RoutingStrategyMutationResponse = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: RoutingStrategyCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoutingStrategyMutationResponse + + /** @see create */ + fun create( + routingStrategyCreateRequest: RoutingStrategyCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoutingStrategyMutationResponse = + create( + RoutingStrategyCreateParams.builder() + .routingStrategyCreateRequest(routingStrategyCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + routingStrategyCreateRequest: RoutingStrategyCreateRequest + ): RoutingStrategyMutationResponse = create(routingStrategyCreateRequest, RequestOptions.none()) + + /** + * Retrieve a routing strategy by ID. Returns the full entity including routing content and + * metadata. + */ + fun retrieve(id: String): RoutingStrategyGetResponse = + retrieve(id, RoutingStrategyRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: RoutingStrategyRetrieveParams = RoutingStrategyRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): RoutingStrategyGetResponse = retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: RoutingStrategyRetrieveParams = RoutingStrategyRetrieveParams.none(), + ): RoutingStrategyGetResponse = retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoutingStrategyRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoutingStrategyGetResponse + + /** @see retrieve */ + fun retrieve(params: RoutingStrategyRetrieveParams): RoutingStrategyGetResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(id: String, requestOptions: RequestOptions): RoutingStrategyGetResponse = + retrieve(id, RoutingStrategyRetrieveParams.none(), requestOptions) + + /** + * List routing strategies in your workspace. Returns metadata only (no + * routing/channels/providers content). Use GET /routing-strategies/{id} for full details. + */ + fun list(): RoutingStrategyListResponse = list(RoutingStrategyListParams.none()) + + /** @see list */ + fun list( + params: RoutingStrategyListParams = RoutingStrategyListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): RoutingStrategyListResponse + + /** @see list */ + fun list( + params: RoutingStrategyListParams = RoutingStrategyListParams.none() + ): RoutingStrategyListResponse = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): RoutingStrategyListResponse = + list(RoutingStrategyListParams.none(), requestOptions) + + /** + * Archive a routing strategy. The strategy must not have associated notification templates. + * Unlink all templates before archiving. + */ + fun archive(id: String) = archive(id, RoutingStrategyArchiveParams.none()) + + /** @see archive */ + fun archive( + id: String, + params: RoutingStrategyArchiveParams = RoutingStrategyArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ) = archive(params.toBuilder().id(id).build(), requestOptions) + + /** @see archive */ + fun archive( + id: String, + params: RoutingStrategyArchiveParams = RoutingStrategyArchiveParams.none(), + ) = archive(id, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: RoutingStrategyArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ) + + /** @see archive */ + fun archive(params: RoutingStrategyArchiveParams) = archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(id: String, requestOptions: RequestOptions) = + archive(id, RoutingStrategyArchiveParams.none(), requestOptions) + + /** + * Replace a routing strategy. Full document replacement; the caller must send the complete + * desired state. Missing optional fields are cleared. + */ + fun replace(id: String, params: RoutingStrategyReplaceParams): RoutingStrategyMutationResponse = + replace(id, params, RequestOptions.none()) + + /** @see replace */ + fun replace( + id: String, + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoutingStrategyMutationResponse = replace(params.toBuilder().id(id).build(), requestOptions) + + /** @see replace */ + fun replace(params: RoutingStrategyReplaceParams): RoutingStrategyMutationResponse = + replace(params, RequestOptions.none()) + + /** @see replace */ + fun replace( + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoutingStrategyMutationResponse + + /** + * A view of [RoutingStrategyService] 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 + ): RoutingStrategyService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /routing-strategies`, but is otherwise the same as + * [RoutingStrategyService.create]. + */ + @MustBeClosed + fun create( + params: RoutingStrategyCreateParams + ): HttpResponseFor = create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: RoutingStrategyCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see create */ + @MustBeClosed + fun create( + routingStrategyCreateRequest: RoutingStrategyCreateRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + create( + RoutingStrategyCreateParams.builder() + .routingStrategyCreateRequest(routingStrategyCreateRequest) + .build(), + requestOptions, + ) + + /** @see create */ + @MustBeClosed + fun create( + routingStrategyCreateRequest: RoutingStrategyCreateRequest + ): HttpResponseFor = + create(routingStrategyCreateRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /routing-strategies/{id}`, but is otherwise the same + * as [RoutingStrategyService.retrieve]. + */ + @MustBeClosed + fun retrieve(id: String): HttpResponseFor = + retrieve(id, RoutingStrategyRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + params: RoutingStrategyRetrieveParams = RoutingStrategyRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + params: RoutingStrategyRetrieveParams = RoutingStrategyRetrieveParams.none(), + ): HttpResponseFor = retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RoutingStrategyRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RoutingStrategyRetrieveParams + ): HttpResponseFor = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(id, RoutingStrategyRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /routing-strategies`, but is otherwise the same as + * [RoutingStrategyService.list]. + */ + @MustBeClosed + fun list(): HttpResponseFor = + list(RoutingStrategyListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: RoutingStrategyListParams = RoutingStrategyListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list( + params: RoutingStrategyListParams = RoutingStrategyListParams.none() + ): HttpResponseFor = list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(RoutingStrategyListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /routing-strategies/{id}`, but is otherwise the + * same as [RoutingStrategyService.archive]. + */ + @MustBeClosed + fun archive(id: String): HttpResponse = archive(id, RoutingStrategyArchiveParams.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + id: String, + params: RoutingStrategyArchiveParams = RoutingStrategyArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = archive(params.toBuilder().id(id).build(), requestOptions) + + /** @see archive */ + @MustBeClosed + fun archive( + id: String, + params: RoutingStrategyArchiveParams = RoutingStrategyArchiveParams.none(), + ): HttpResponse = archive(id, params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + params: RoutingStrategyArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** @see archive */ + @MustBeClosed + fun archive(params: RoutingStrategyArchiveParams): HttpResponse = + archive(params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive(id: String, requestOptions: RequestOptions): HttpResponse = + archive(id, RoutingStrategyArchiveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /routing-strategies/{id}`, but is otherwise the same + * as [RoutingStrategyService.replace]. + */ + @MustBeClosed + fun replace( + id: String, + params: RoutingStrategyReplaceParams, + ): HttpResponseFor = + replace(id, params, RequestOptions.none()) + + /** @see replace */ + @MustBeClosed + fun replace( + id: String, + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + replace(params.toBuilder().id(id).build(), requestOptions) + + /** @see replace */ + @MustBeClosed + fun replace( + params: RoutingStrategyReplaceParams + ): HttpResponseFor = replace(params, RequestOptions.none()) + + /** @see replace */ + @MustBeClosed + fun replace( + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/RoutingStrategyServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/RoutingStrategyServiceImpl.kt new file mode 100644 index 00000000..b641f7ad --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/RoutingStrategyServiceImpl.kt @@ -0,0 +1,229 @@ +// 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.routingstrategies.RoutingStrategyArchiveParams +import com.courier.models.routingstrategies.RoutingStrategyCreateParams +import com.courier.models.routingstrategies.RoutingStrategyGetResponse +import com.courier.models.routingstrategies.RoutingStrategyListParams +import com.courier.models.routingstrategies.RoutingStrategyListResponse +import com.courier.models.routingstrategies.RoutingStrategyMutationResponse +import com.courier.models.routingstrategies.RoutingStrategyReplaceParams +import com.courier.models.routingstrategies.RoutingStrategyRetrieveParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class RoutingStrategyServiceImpl internal constructor(private val clientOptions: ClientOptions) : + RoutingStrategyService { + + private val withRawResponse: RoutingStrategyService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RoutingStrategyService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RoutingStrategyService = + RoutingStrategyServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: RoutingStrategyCreateParams, + requestOptions: RequestOptions, + ): RoutingStrategyMutationResponse = + // post /routing-strategies + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve( + params: RoutingStrategyRetrieveParams, + requestOptions: RequestOptions, + ): RoutingStrategyGetResponse = + // get /routing-strategies/{id} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list( + params: RoutingStrategyListParams, + requestOptions: RequestOptions, + ): RoutingStrategyListResponse = + // get /routing-strategies + withRawResponse().list(params, requestOptions).parse() + + override fun archive(params: RoutingStrategyArchiveParams, requestOptions: RequestOptions) { + // delete /routing-strategies/{id} + withRawResponse().archive(params, requestOptions) + } + + override fun replace( + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions, + ): RoutingStrategyMutationResponse = + // put /routing-strategies/{id} + withRawResponse().replace(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RoutingStrategyService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RoutingStrategyService.WithRawResponse = + RoutingStrategyServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: RoutingStrategyCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies") + .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: RoutingStrategyRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies", 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: RoutingStrategyListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies") + .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: RoutingStrategyArchiveParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies", 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 replaceHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun replace( + params: RoutingStrategyReplaceParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("routing-strategies", 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/test/kotlin/com/courier/core/ClientOptionsTest.kt b/courier-java-core/src/test/kotlin/com/courier/core/ClientOptionsTest.kt index bb4ebcb2..fd9aa5ca 100644 --- a/courier-java-core/src/test/kotlin/com/courier/core/ClientOptionsTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/core/ClientOptionsTest.kt @@ -16,6 +16,29 @@ internal class ClientOptionsTest { private val httpClient = mock() + @Test + fun putHeader_canOverwriteDefaultHeader() { + val clientOptions = + ClientOptions.builder() + .httpClient(httpClient) + .putHeader("User-Agent", "My User Agent") + .apiKey("My API Key") + .build() + + assertThat(clientOptions.headers.values("User-Agent")).containsExactly("My User Agent") + } + + @Test + fun toBuilder_bearerAuthCanBeUpdated() { + var clientOptions = + ClientOptions.builder().httpClient(httpClient).apiKey("My API Key").build() + + clientOptions = clientOptions.toBuilder().apiKey("another My API Key").build() + + assertThat(clientOptions.headers.values("Authorization")) + .containsExactly("Bearer another My API Key") + } + @Test fun toBuilder_whenOriginalClientOptionsGarbageCollected_doesNotCloseOriginalClient() { var clientOptions = diff --git a/courier-java-core/src/test/kotlin/com/courier/core/http/RetryingHttpClientTest.kt b/courier-java-core/src/test/kotlin/com/courier/core/http/RetryingHttpClientTest.kt index e5636ac7..c4654980 100644 --- a/courier-java-core/src/test/kotlin/com/courier/core/http/RetryingHttpClientTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/core/http/RetryingHttpClientTest.kt @@ -400,9 +400,9 @@ internal class RetryingHttpClientTest { assertThat(sleeper.durations).hasSize(3) // retries=1: 0.5s * [0.75, 1.0] assertThat(sleeper.durations[0]).isBetween(Duration.ofMillis(375), Duration.ofMillis(500)) - // retries=2: 1.0s * [0.75, 1.0] + // retries=2: 1s * [0.75, 1.0] assertThat(sleeper.durations[1]).isBetween(Duration.ofMillis(750), Duration.ofMillis(1000)) - // retries=3: 2.0s * [0.75, 1.0] + // retries=3: 2s * [0.75, 1.0] assertThat(sleeper.durations[2]).isBetween(Duration.ofMillis(1500), Duration.ofMillis(2000)) assertNoResponseLeaks() } @@ -427,9 +427,9 @@ internal class RetryingHttpClientTest { assertThat(response.statusCode()).isEqualTo(503) verify(7, postRequestedFor(urlPathEqualTo("/something"))) assertThat(sleeper.durations).hasSize(6) - // retries=5: min(0.5 * 2^4, 8) = 8.0s * [0.75, 1.0] + // retries=5: backoff hits the 8s cap * [0.75, 1.0] assertThat(sleeper.durations[4]).isBetween(Duration.ofMillis(6000), Duration.ofMillis(8000)) - // retries=6: min(0.5 * 2^5, 8) = min(16, 8) = 8.0s * [0.75, 1.0] (capped) + // retries=6: still capped at 8s * [0.75, 1.0] assertThat(sleeper.durations[5]).isBetween(Duration.ofMillis(6000), Duration.ofMillis(8000)) assertNoResponseLeaks() } diff --git a/courier-java-core/src/test/kotlin/com/courier/models/ChannelMetadataTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/ChannelMetadataTest.kt new file mode 100644 index 00000000..da4fc7a2 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/ChannelMetadataTest.kt @@ -0,0 +1,63 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +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 ChannelMetadataTest { + + @Test + fun create() { + val channelMetadata = + ChannelMetadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + + assertThat(channelMetadata.utm()) + .contains( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val channelMetadata = + ChannelMetadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + + val roundtrippedChannelMetadata = + jsonMapper.readValue( + jsonMapper.writeValueAsString(channelMetadata), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChannelMetadata).isEqualTo(channelMetadata) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/ChannelTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/ChannelTest.kt new file mode 100644 index 00000000..6995ec13 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/ChannelTest.kt @@ -0,0 +1,105 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +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 ChannelTest { + + @Test + fun create() { + val channel = + Channel.builder() + .brandId("brand_id") + .if_("if") + .metadata( + ChannelMetadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + ) + .override( + Channel.Override.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addProvider("string") + .routingMethod(Channel.RoutingMethod.ALL) + .timeouts(Timeouts.builder().channel(0L).provider(0L).build()) + .build() + + assertThat(channel.brandId()).contains("brand_id") + assertThat(channel.if_()).contains("if") + assertThat(channel.metadata()) + .contains( + ChannelMetadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + ) + assertThat(channel.override()) + .contains( + Channel.Override.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(channel.providers().getOrNull()).containsExactly("string") + assertThat(channel.routingMethod()).contains(Channel.RoutingMethod.ALL) + assertThat(channel.timeouts()).contains(Timeouts.builder().channel(0L).provider(0L).build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val channel = + Channel.builder() + .brandId("brand_id") + .if_("if") + .metadata( + ChannelMetadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + ) + .override( + Channel.Override.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addProvider("string") + .routingMethod(Channel.RoutingMethod.ALL) + .timeouts(Timeouts.builder().channel(0L).provider(0L).build()) + .build() + + val roundtrippedChannel = + jsonMapper.readValue(jsonMapper.writeValueAsString(channel), jacksonTypeRef()) + + assertThat(roundtrippedChannel).isEqualTo(channel) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/ElementalHtmlNodeWithTypeTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/ElementalHtmlNodeWithTypeTest.kt new file mode 100644 index 00000000..154093ac --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/ElementalHtmlNodeWithTypeTest.kt @@ -0,0 +1,51 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.jsonMapper +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 ElementalHtmlNodeWithTypeTest { + + @Test + fun create() { + val elementalHtmlNodeWithType = + ElementalHtmlNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalHtmlNodeWithType.Type.HTML) + .build() + + assertThat(elementalHtmlNodeWithType.channels().getOrNull()).containsExactly("string") + assertThat(elementalHtmlNodeWithType.if_()).contains("if") + assertThat(elementalHtmlNodeWithType.loop()).contains("loop") + assertThat(elementalHtmlNodeWithType.ref()).contains("ref") + assertThat(elementalHtmlNodeWithType.type()).contains(ElementalHtmlNodeWithType.Type.HTML) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val elementalHtmlNodeWithType = + ElementalHtmlNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalHtmlNodeWithType.Type.HTML) + .build() + + val roundtrippedElementalHtmlNodeWithType = + jsonMapper.readValue( + jsonMapper.writeValueAsString(elementalHtmlNodeWithType), + jacksonTypeRef(), + ) + + assertThat(roundtrippedElementalHtmlNodeWithType).isEqualTo(elementalHtmlNodeWithType) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/ElementalNodeTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/ElementalNodeTest.kt index cf511be7..55c8f8b1 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/ElementalNodeTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/ElementalNodeTest.kt @@ -34,6 +34,7 @@ internal class ElementalNodeTest { assertThat(elementalNode.actionNodeWithType()).isEmpty assertThat(elementalNode.dividerNodeWithType()).isEmpty assertThat(elementalNode.quoteNodeWithType()).isEmpty + assertThat(elementalNode.htmlNodeWithType()).isEmpty } @Test @@ -79,6 +80,7 @@ internal class ElementalNodeTest { assertThat(elementalNode.actionNodeWithType()).isEmpty assertThat(elementalNode.dividerNodeWithType()).isEmpty assertThat(elementalNode.quoteNodeWithType()).isEmpty + assertThat(elementalNode.htmlNodeWithType()).isEmpty } @Test @@ -121,6 +123,7 @@ internal class ElementalNodeTest { assertThat(elementalNode.actionNodeWithType()).isEmpty assertThat(elementalNode.dividerNodeWithType()).isEmpty assertThat(elementalNode.quoteNodeWithType()).isEmpty + assertThat(elementalNode.htmlNodeWithType()).isEmpty } @Test @@ -163,6 +166,7 @@ internal class ElementalNodeTest { assertThat(elementalNode.actionNodeWithType()).isEmpty assertThat(elementalNode.dividerNodeWithType()).isEmpty assertThat(elementalNode.quoteNodeWithType()).isEmpty + assertThat(elementalNode.htmlNodeWithType()).isEmpty } @Test @@ -208,6 +212,7 @@ internal class ElementalNodeTest { assertThat(elementalNode.actionNodeWithType()).contains(actionNodeWithType) assertThat(elementalNode.dividerNodeWithType()).isEmpty assertThat(elementalNode.quoteNodeWithType()).isEmpty + assertThat(elementalNode.htmlNodeWithType()).isEmpty } @Test @@ -253,6 +258,7 @@ internal class ElementalNodeTest { assertThat(elementalNode.actionNodeWithType()).isEmpty assertThat(elementalNode.dividerNodeWithType()).contains(dividerNodeWithType) assertThat(elementalNode.quoteNodeWithType()).isEmpty + assertThat(elementalNode.htmlNodeWithType()).isEmpty } @Test @@ -298,6 +304,7 @@ internal class ElementalNodeTest { assertThat(elementalNode.actionNodeWithType()).isEmpty assertThat(elementalNode.dividerNodeWithType()).isEmpty assertThat(elementalNode.quoteNodeWithType()).contains(quoteNodeWithType) + assertThat(elementalNode.htmlNodeWithType()).isEmpty } @Test @@ -323,6 +330,52 @@ internal class ElementalNodeTest { assertThat(roundtrippedElementalNode).isEqualTo(elementalNode) } + @Test + fun ofHtmlNodeWithType() { + val htmlNodeWithType = + ElementalHtmlNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalHtmlNodeWithType.Type.HTML) + .build() + + val elementalNode = ElementalNode.ofHtmlNodeWithType(htmlNodeWithType) + + assertThat(elementalNode.textNodeWithType()).isEmpty + assertThat(elementalNode.metaNodeWithType()).isEmpty + assertThat(elementalNode.channelNodeWithType()).isEmpty + assertThat(elementalNode.imageNodeWithType()).isEmpty + assertThat(elementalNode.actionNodeWithType()).isEmpty + assertThat(elementalNode.dividerNodeWithType()).isEmpty + assertThat(elementalNode.quoteNodeWithType()).isEmpty + assertThat(elementalNode.htmlNodeWithType()).contains(htmlNodeWithType) + } + + @Test + fun ofHtmlNodeWithTypeRoundtrip() { + val jsonMapper = jsonMapper() + val elementalNode = + ElementalNode.ofHtmlNodeWithType( + ElementalHtmlNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalHtmlNodeWithType.Type.HTML) + .build() + ) + + val roundtrippedElementalNode = + jsonMapper.readValue( + jsonMapper.writeValueAsString(elementalNode), + jacksonTypeRef(), + ) + + assertThat(roundtrippedElementalNode).isEqualTo(elementalNode) + } + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { BOOLEAN(JsonValue.from(false)), STRING(JsonValue.from("invalid")), diff --git a/courier-java-core/src/test/kotlin/com/courier/models/MessageChannelsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/MessageChannelsTest.kt new file mode 100644 index 00000000..4b91a00d --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/MessageChannelsTest.kt @@ -0,0 +1,83 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.JsonValue +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 MessageChannelsTest { + + @Test + fun create() { + val messageChannels = + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val messageChannels = + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + + val roundtrippedMessageChannels = + jsonMapper.readValue( + jsonMapper.writeValueAsString(messageChannels), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMessageChannels).isEqualTo(messageChannels) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/MessageProvidersTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/MessageProvidersTest.kt new file mode 100644 index 00000000..2e1163eb --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/MessageProvidersTest.kt @@ -0,0 +1,77 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.JsonValue +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 MessageProvidersTest { + + @Test + fun create() { + val messageProviders = + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val messageProviders = + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + + val roundtrippedMessageProviders = + jsonMapper.readValue( + jsonMapper.writeValueAsString(messageProviders), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMessageProviders).isEqualTo(messageProviders) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/MessageProvidersTypeTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/MessageProvidersTypeTest.kt new file mode 100644 index 00000000..4a38a9e8 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/MessageProvidersTypeTest.kt @@ -0,0 +1,98 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.JsonValue +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 MessageProvidersTypeTest { + + @Test + fun create() { + val messageProvidersType = + MessageProvidersType.builder() + .if_("if") + .metadata( + Metadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + ) + .override( + MessageProvidersType.Override.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .timeouts(0L) + .build() + + assertThat(messageProvidersType.if_()).contains("if") + assertThat(messageProvidersType.metadata()) + .contains( + Metadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + ) + assertThat(messageProvidersType.override()) + .contains( + MessageProvidersType.Override.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(messageProvidersType.timeouts()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val messageProvidersType = + MessageProvidersType.builder() + .if_("if") + .metadata( + Metadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + ) + .override( + MessageProvidersType.Override.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .timeouts(0L) + .build() + + val roundtrippedMessageProvidersType = + jsonMapper.readValue( + jsonMapper.writeValueAsString(messageProvidersType), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMessageProvidersType).isEqualTo(messageProvidersType) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/MetadataTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/MetadataTest.kt new file mode 100644 index 00000000..307e1eaf --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/MetadataTest.kt @@ -0,0 +1,63 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +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 MetadataTest { + + @Test + fun create() { + val metadata = + Metadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + + assertThat(metadata.utm()) + .contains( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val metadata = + Metadata.builder() + .utm( + Utm.builder() + .campaign("campaign") + .content("content") + .medium("medium") + .source("source") + .term("term") + .build() + ) + .build() + + val roundtrippedMetadata = + jsonMapper.readValue( + jsonMapper.writeValueAsString(metadata), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMetadata).isEqualTo(metadata) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/TimeoutsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/TimeoutsTest.kt new file mode 100644 index 00000000..c543003e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/TimeoutsTest.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +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 TimeoutsTest { + + @Test + fun create() { + val timeouts = Timeouts.builder().channel(0L).provider(0L).build() + + assertThat(timeouts.channel()).contains(0L) + assertThat(timeouts.provider()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val timeouts = Timeouts.builder().channel(0L).provider(0L).build() + + val roundtrippedTimeouts = + jsonMapper.readValue( + jsonMapper.writeValueAsString(timeouts), + jacksonTypeRef(), + ) + + assertThat(roundtrippedTimeouts).isEqualTo(timeouts) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationArchiveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationArchiveParamsTest.kt new file mode 100644 index 00000000..57900731 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationArchiveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationArchiveParamsTest { + + @Test + fun create() { + NotificationArchiveParams.builder().id("id").build() + } + + @Test + fun pathParams() { + val params = NotificationArchiveParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationCreateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationCreateParamsTest.kt new file mode 100644 index 00000000..eb8b89cd --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationCreateParamsTest.kt @@ -0,0 +1,209 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.models.ElementalChannelNodeWithType +import com.courier.models.ElementalContent +import com.courier.models.ElementalTextNodeWithType +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationCreateParamsTest { + + @Test + fun create() { + NotificationCreateParams.builder() + .notificationTemplateCreateRequest( + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder().id("brand_abc").build() + ) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Welcome Email") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("rs_123") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("marketing") + .build() + ) + .addTag("onboarding") + .addTag("welcome") + .build() + ) + .state(NotificationTemplateCreateRequest.State.DRAFT) + .build() + ) + .build() + } + + @Test + fun body() { + val params = + NotificationCreateParams.builder() + .notificationTemplateCreateRequest( + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder() + .id("brand_abc") + .build() + ) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Welcome Email") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("rs_123") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("marketing") + .build() + ) + .addTag("onboarding") + .addTag("welcome") + .build() + ) + .state(NotificationTemplateCreateRequest.State.DRAFT) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder().id("brand_abc").build() + ) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Welcome Email") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("rs_123") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("marketing") + .build() + ) + .addTag("onboarding") + .addTag("welcome") + .build() + ) + .state(NotificationTemplateCreateRequest.State.DRAFT) + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + NotificationCreateParams.builder() + .notificationTemplateCreateRequest( + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder() + .id("brand_abc") + .build() + ) + .content( + ElementalContent.builder() + .addElement(ElementalTextNodeWithType.builder().build()) + .version("2022-01-01") + .build() + ) + .name("Welcome Email") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("rs_123") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("marketing") + .build() + ) + .addTag("onboarding") + .addTag("welcome") + .build() + ) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder().id("brand_abc").build() + ) + .content( + ElementalContent.builder() + .addElement(ElementalTextNodeWithType.builder().build()) + .version("2022-01-01") + .build() + ) + .name("Welcome Email") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("rs_123") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("marketing") + .build() + ) + .addTag("onboarding") + .addTag("welcome") + .build() + ) + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListParamsTest.kt index ad2797a3..02de59ee 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListParamsTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListParamsTest.kt @@ -10,17 +10,28 @@ internal class NotificationListParamsTest { @Test fun create() { - NotificationListParams.builder().cursor("cursor").notes(true).build() + NotificationListParams.builder().cursor("cursor").eventId("event_id").notes(true).build() } @Test fun queryParams() { - val params = NotificationListParams.builder().cursor("cursor").notes(true).build() + val params = + NotificationListParams.builder() + .cursor("cursor") + .eventId("event_id") + .notes(true) + .build() val queryParams = params._queryParams() assertThat(queryParams) - .isEqualTo(QueryParams.builder().put("cursor", "cursor").put("notes", "true").build()) + .isEqualTo( + QueryParams.builder() + .put("cursor", "cursor") + .put("event_id", "event_id") + .put("notes", "true") + .build() + ) } @Test diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListResponseTest.kt index c223f94d..fcd413e5 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListResponseTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListResponseTest.kt @@ -17,7 +17,7 @@ internal class NotificationListResponseTest { NotificationListResponse.builder() .paging(Paging.builder().more(true).cursor("cursor").build()) .addResult( - NotificationListResponse.Result.builder() + NotificationListResponse.Result.Notification.builder() .id("id") .createdAt(0L) .addEventId("string") @@ -31,9 +31,9 @@ internal class NotificationListResponseTest { .topicId("topic_id") .updatedAt(0L) .tags( - NotificationListResponse.Result.Tags.builder() + NotificationListResponse.Result.Notification.Tags.builder() .addData( - NotificationListResponse.Result.Tags.Data.builder() + NotificationListResponse.Result.Notification.Tags.Data.builder() .id("id") .name("name") .build() @@ -49,31 +49,33 @@ internal class NotificationListResponseTest { .isEqualTo(Paging.builder().more(true).cursor("cursor").build()) assertThat(notificationListResponse.results()) .containsExactly( - NotificationListResponse.Result.builder() - .id("id") - .createdAt(0L) - .addEventId("string") - .note("note") - .routing( - MessageRouting.builder() - .addChannel("string") - .method(MessageRouting.Method.ALL) - .build() - ) - .topicId("topic_id") - .updatedAt(0L) - .tags( - NotificationListResponse.Result.Tags.builder() - .addData( - NotificationListResponse.Result.Tags.Data.builder() - .id("id") - .name("name") - .build() - ) - .build() - ) - .title("title") - .build() + NotificationListResponse.Result.ofNotification( + NotificationListResponse.Result.Notification.builder() + .id("id") + .createdAt(0L) + .addEventId("string") + .note("note") + .routing( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + .topicId("topic_id") + .updatedAt(0L) + .tags( + NotificationListResponse.Result.Notification.Tags.builder() + .addData( + NotificationListResponse.Result.Notification.Tags.Data.builder() + .id("id") + .name("name") + .build() + ) + .build() + ) + .title("title") + .build() + ) ) } @@ -84,7 +86,7 @@ internal class NotificationListResponseTest { NotificationListResponse.builder() .paging(Paging.builder().more(true).cursor("cursor").build()) .addResult( - NotificationListResponse.Result.builder() + NotificationListResponse.Result.Notification.builder() .id("id") .createdAt(0L) .addEventId("string") @@ -98,9 +100,9 @@ internal class NotificationListResponseTest { .topicId("topic_id") .updatedAt(0L) .tags( - NotificationListResponse.Result.Tags.builder() + NotificationListResponse.Result.Notification.Tags.builder() .addData( - NotificationListResponse.Result.Tags.Data.builder() + NotificationListResponse.Result.Notification.Tags.Data.builder() .id("id") .name("name") .build() diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListVersionsParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListVersionsParamsTest.kt new file mode 100644 index 00000000..fdd1624e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationListVersionsParamsTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationListVersionsParamsTest { + + @Test + fun create() { + NotificationListVersionsParams.builder().id("id").cursor("cursor").limit(10L).build() + } + + @Test + fun pathParams() { + val params = NotificationListVersionsParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + NotificationListVersionsParams.builder().id("id").cursor("cursor").limit(10L).build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo(QueryParams.builder().put("cursor", "cursor").put("limit", "10").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = NotificationListVersionsParams.builder().id("id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationPublishParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationPublishParamsTest.kt new file mode 100644 index 00000000..c093a673 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationPublishParamsTest.kt @@ -0,0 +1,54 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationPublishParamsTest { + + @Test + fun create() { + NotificationPublishParams.builder() + .id("id") + .notificationTemplatePublishRequest( + NotificationTemplatePublishRequest.builder().version("v321669910225").build() + ) + .build() + } + + @Test + fun pathParams() { + val params = NotificationPublishParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + NotificationPublishParams.builder() + .id("id") + .notificationTemplatePublishRequest( + NotificationTemplatePublishRequest.builder().version("v321669910225").build() + ) + .build() + + val body = params._body().getOrNull() + + assertThat(body) + .isEqualTo( + NotificationTemplatePublishRequest.builder().version("v321669910225").build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = NotificationPublishParams.builder().id("id").build() + + val body = params._body().getOrNull() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationReplaceParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationReplaceParamsTest.kt new file mode 100644 index 00000000..39e34a6f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationReplaceParamsTest.kt @@ -0,0 +1,232 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.models.ElementalChannelNodeWithType +import com.courier.models.ElementalContent +import com.courier.models.ElementalTextNodeWithType +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationReplaceParamsTest { + + @Test + fun create() { + NotificationReplaceParams.builder() + .id("id") + .notificationTemplateUpdateRequest( + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Updated Name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("updated") + .build() + ) + .state(NotificationTemplateUpdateRequest.State.PUBLISHED) + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + NotificationReplaceParams.builder() + .id("id") + .notificationTemplateUpdateRequest( + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement(ElementalTextNodeWithType.builder().build()) + .version("2022-01-01") + .build() + ) + .name("Updated Name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("updated") + .build() + ) + .build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + NotificationReplaceParams.builder() + .id("id") + .notificationTemplateUpdateRequest( + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Updated Name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("updated") + .build() + ) + .state(NotificationTemplateUpdateRequest.State.PUBLISHED) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Updated Name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("updated") + .build() + ) + .state(NotificationTemplateUpdateRequest.State.PUBLISHED) + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + NotificationReplaceParams.builder() + .id("id") + .notificationTemplateUpdateRequest( + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement(ElementalTextNodeWithType.builder().build()) + .version("2022-01-01") + .build() + ) + .name("Updated Name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("updated") + .build() + ) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement(ElementalTextNodeWithType.builder().build()) + .version("2022-01-01") + .build() + ) + .name("Updated Name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("updated") + .build() + ) + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationRetrieveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationRetrieveParamsTest.kt new file mode 100644 index 00000000..2a71aefd --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationRetrieveParamsTest.kt @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationRetrieveParamsTest { + + @Test + fun create() { + NotificationRetrieveParams.builder().id("id").version("version").build() + } + + @Test + fun pathParams() { + val params = NotificationRetrieveParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = NotificationRetrieveParams.builder().id("id").version("version").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().put("version", "version").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = NotificationRetrieveParams.builder().id("id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateCreateRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateCreateRequestTest.kt new file mode 100644 index 00000000..974768fa --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateCreateRequestTest.kt @@ -0,0 +1,136 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.core.jsonMapper +import com.courier.models.ElementalContent +import com.courier.models.ElementalTextNodeWithType +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationTemplateCreateRequestTest { + + @Test + fun create() { + val notificationTemplateCreateRequest = + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .build() + ) + .state(NotificationTemplateCreateRequest.State.DRAFT) + .build() + + assertThat(notificationTemplateCreateRequest.notification()) + .isEqualTo( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .build() + ) + assertThat(notificationTemplateCreateRequest.state()) + .contains(NotificationTemplateCreateRequest.State.DRAFT) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val notificationTemplateCreateRequest = + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .build() + ) + .state(NotificationTemplateCreateRequest.State.DRAFT) + .build() + + val roundtrippedNotificationTemplateCreateRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(notificationTemplateCreateRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNotificationTemplateCreateRequest) + .isEqualTo(notificationTemplateCreateRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateGetResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateGetResponseTest.kt new file mode 100644 index 00000000..720ed454 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateGetResponseTest.kt @@ -0,0 +1,151 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.core.jsonMapper +import com.courier.models.ElementalContent +import com.courier.models.ElementalTextNodeWithType +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationTemplateGetResponseTest { + + @Test + fun create() { + val notificationTemplateGetResponse = + NotificationTemplateGetResponse.builder() + .created(0L) + .creator("creator") + .notification( + NotificationTemplateGetResponse.Notification.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .id("id") + .build() + ) + .state(NotificationTemplateGetResponse.State.DRAFT) + .updated(0L) + .updater("updater") + .build() + + assertThat(notificationTemplateGetResponse.created()).isEqualTo(0L) + assertThat(notificationTemplateGetResponse.creator()).isEqualTo("creator") + assertThat(notificationTemplateGetResponse.notification()) + .isEqualTo( + NotificationTemplateGetResponse.Notification.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .id("id") + .build() + ) + assertThat(notificationTemplateGetResponse.state()) + .isEqualTo(NotificationTemplateGetResponse.State.DRAFT) + assertThat(notificationTemplateGetResponse.updated()).contains(0L) + assertThat(notificationTemplateGetResponse.updater()).contains("updater") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val notificationTemplateGetResponse = + NotificationTemplateGetResponse.builder() + .created(0L) + .creator("creator") + .notification( + NotificationTemplateGetResponse.Notification.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .id("id") + .build() + ) + .state(NotificationTemplateGetResponse.State.DRAFT) + .updated(0L) + .updater("updater") + .build() + + val roundtrippedNotificationTemplateGetResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(notificationTemplateGetResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNotificationTemplateGetResponse) + .isEqualTo(notificationTemplateGetResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateMutationResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateMutationResponseTest.kt new file mode 100644 index 00000000..69470bce --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateMutationResponseTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 NotificationTemplateMutationResponseTest { + + @Test + fun create() { + val notificationTemplateMutationResponse = + NotificationTemplateMutationResponse.builder() + .notification( + NotificationTemplateMutationResponse.Notification.builder().id("id").build() + ) + .state(NotificationTemplateMutationResponse.State.DRAFT) + .build() + + assertThat(notificationTemplateMutationResponse.notification()) + .isEqualTo(NotificationTemplateMutationResponse.Notification.builder().id("id").build()) + assertThat(notificationTemplateMutationResponse.state()) + .isEqualTo(NotificationTemplateMutationResponse.State.DRAFT) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val notificationTemplateMutationResponse = + NotificationTemplateMutationResponse.builder() + .notification( + NotificationTemplateMutationResponse.Notification.builder().id("id").build() + ) + .state(NotificationTemplateMutationResponse.State.DRAFT) + .build() + + val roundtrippedNotificationTemplateMutationResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(notificationTemplateMutationResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNotificationTemplateMutationResponse) + .isEqualTo(notificationTemplateMutationResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplatePayloadTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplatePayloadTest.kt new file mode 100644 index 00000000..12b423d1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplatePayloadTest.kt @@ -0,0 +1,110 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.core.jsonMapper +import com.courier.models.ElementalContent +import com.courier.models.ElementalTextNodeWithType +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationTemplatePayloadTest { + + @Test + fun create() { + val notificationTemplatePayload = + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder().strategyId("strategy_id").build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder().topicId("topic_id").build() + ) + .addTag("string") + .build() + + assertThat(notificationTemplatePayload.brand()) + .contains(NotificationTemplatePayload.Brand.builder().id("id").build()) + assertThat(notificationTemplatePayload.content()) + .isEqualTo( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + assertThat(notificationTemplatePayload.name()).isEqualTo("name") + assertThat(notificationTemplatePayload.routing()) + .contains( + NotificationTemplatePayload.Routing.builder().strategyId("strategy_id").build() + ) + assertThat(notificationTemplatePayload.subscription()) + .contains( + NotificationTemplatePayload.Subscription.builder().topicId("topic_id").build() + ) + assertThat(notificationTemplatePayload.tags()).containsExactly("string") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val notificationTemplatePayload = + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder().strategyId("strategy_id").build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder().topicId("topic_id").build() + ) + .addTag("string") + .build() + + val roundtrippedNotificationTemplatePayload = + jsonMapper.readValue( + jsonMapper.writeValueAsString(notificationTemplatePayload), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNotificationTemplatePayload).isEqualTo(notificationTemplatePayload) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplatePublishRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplatePublishRequestTest.kt new file mode 100644 index 00000000..9de4aea5 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplatePublishRequestTest.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 NotificationTemplatePublishRequestTest { + + @Test + fun create() { + val notificationTemplatePublishRequest = + NotificationTemplatePublishRequest.builder().version("v321669910225").build() + + assertThat(notificationTemplatePublishRequest.version()).contains("v321669910225") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val notificationTemplatePublishRequest = + NotificationTemplatePublishRequest.builder().version("v321669910225").build() + + val roundtrippedNotificationTemplatePublishRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(notificationTemplatePublishRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNotificationTemplatePublishRequest) + .isEqualTo(notificationTemplatePublishRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateSummaryTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateSummaryTest.kt new file mode 100644 index 00000000..b03e82bf --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateSummaryTest.kt @@ -0,0 +1,60 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 NotificationTemplateSummaryTest { + + @Test + fun create() { + val notificationTemplateSummary = + NotificationTemplateSummary.builder() + .id("id") + .created(0L) + .creator("creator") + .name("name") + .state(NotificationTemplateSummary.State.DRAFT) + .addTag("string") + .updated(0L) + .updater("updater") + .build() + + assertThat(notificationTemplateSummary.id()).isEqualTo("id") + assertThat(notificationTemplateSummary.created()).isEqualTo(0L) + assertThat(notificationTemplateSummary.creator()).isEqualTo("creator") + assertThat(notificationTemplateSummary.name()).isEqualTo("name") + assertThat(notificationTemplateSummary.state()) + .isEqualTo(NotificationTemplateSummary.State.DRAFT) + assertThat(notificationTemplateSummary.tags()).containsExactly("string") + assertThat(notificationTemplateSummary.updated()).contains(0L) + assertThat(notificationTemplateSummary.updater()).contains("updater") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val notificationTemplateSummary = + NotificationTemplateSummary.builder() + .id("id") + .created(0L) + .creator("creator") + .name("name") + .state(NotificationTemplateSummary.State.DRAFT) + .addTag("string") + .updated(0L) + .updater("updater") + .build() + + val roundtrippedNotificationTemplateSummary = + jsonMapper.readValue( + jsonMapper.writeValueAsString(notificationTemplateSummary), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNotificationTemplateSummary).isEqualTo(notificationTemplateSummary) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateUpdateRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateUpdateRequestTest.kt new file mode 100644 index 00000000..b220db66 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateUpdateRequestTest.kt @@ -0,0 +1,136 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.core.jsonMapper +import com.courier.models.ElementalContent +import com.courier.models.ElementalTextNodeWithType +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationTemplateUpdateRequestTest { + + @Test + fun create() { + val notificationTemplateUpdateRequest = + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .build() + ) + .state(NotificationTemplateUpdateRequest.State.DRAFT) + .build() + + assertThat(notificationTemplateUpdateRequest.notification()) + .isEqualTo( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .build() + ) + assertThat(notificationTemplateUpdateRequest.state()) + .contains(NotificationTemplateUpdateRequest.State.DRAFT) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val notificationTemplateUpdateRequest = + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand(NotificationTemplatePayload.Brand.builder().id("id").build()) + .content( + ElementalContent.builder() + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("version") + .build() + ) + .name("name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("string") + .build() + ) + .state(NotificationTemplateUpdateRequest.State.DRAFT) + .build() + + val roundtrippedNotificationTemplateUpdateRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(notificationTemplateUpdateRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNotificationTemplateUpdateRequest) + .isEqualTo(notificationTemplateUpdateRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateVersionListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateVersionListResponseTest.kt new file mode 100644 index 00000000..dd19a397 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/NotificationTemplateVersionListResponseTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +import com.courier.core.jsonMapper +import com.courier.models.Paging +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class NotificationTemplateVersionListResponseTest { + + @Test + fun create() { + val notificationTemplateVersionListResponse = + NotificationTemplateVersionListResponse.builder() + .paging(Paging.builder().more(true).cursor("cursor").build()) + .addVersion( + VersionNode.builder() + .created(0L) + .creator("creator") + .version("version") + .hasChanges(true) + .build() + ) + .build() + + assertThat(notificationTemplateVersionListResponse.paging()) + .isEqualTo(Paging.builder().more(true).cursor("cursor").build()) + assertThat(notificationTemplateVersionListResponse.versions()) + .containsExactly( + VersionNode.builder() + .created(0L) + .creator("creator") + .version("version") + .hasChanges(true) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val notificationTemplateVersionListResponse = + NotificationTemplateVersionListResponse.builder() + .paging(Paging.builder().more(true).cursor("cursor").build()) + .addVersion( + VersionNode.builder() + .created(0L) + .creator("creator") + .version("version") + .hasChanges(true) + .build() + ) + .build() + + val roundtrippedNotificationTemplateVersionListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(notificationTemplateVersionListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNotificationTemplateVersionListResponse) + .isEqualTo(notificationTemplateVersionListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/VersionNodeTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/VersionNodeTest.kt new file mode 100644 index 00000000..818456fe --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/VersionNodeTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications + +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 VersionNodeTest { + + @Test + fun create() { + val versionNode = + VersionNode.builder() + .created(0L) + .creator("creator") + .version("version") + .hasChanges(true) + .build() + + assertThat(versionNode.created()).isEqualTo(0L) + assertThat(versionNode.creator()).isEqualTo("creator") + assertThat(versionNode.version()).isEqualTo("version") + assertThat(versionNode.hasChanges()).contains(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val versionNode = + VersionNode.builder() + .created(0L) + .creator("creator") + .version("version") + .hasChanges(true) + .build() + + val roundtrippedVersionNode = + jsonMapper.readValue( + jsonMapper.writeValueAsString(versionNode), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVersionNode).isEqualTo(versionNode) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyArchiveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyArchiveParamsTest.kt new file mode 100644 index 00000000..cd716cae --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyArchiveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoutingStrategyArchiveParamsTest { + + @Test + fun create() { + RoutingStrategyArchiveParams.builder().id("id").build() + } + + @Test + fun pathParams() { + val params = RoutingStrategyArchiveParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateParamsTest.kt new file mode 100644 index 00000000..7c8e565f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateParamsTest.kt @@ -0,0 +1,264 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import com.courier.core.JsonValue +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoutingStrategyCreateParamsTest { + + @Test + fun create() { + RoutingStrategyCreateParams.builder() + .routingStrategyCreateRequest( + RoutingStrategyCreateRequest.builder() + .name("Email via SendGrid") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("sendgrid", "ses"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Routes email through sendgrid with SES failover") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "sendgrid", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("production") + .addTag("email") + .build() + ) + .build() + } + + @Test + fun body() { + val params = + RoutingStrategyCreateParams.builder() + .routingStrategyCreateRequest( + RoutingStrategyCreateRequest.builder() + .name("Email via SendGrid") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("sendgrid", "ses"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Routes email through sendgrid with SES failover") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "sendgrid", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("production") + .addTag("email") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + RoutingStrategyCreateRequest.builder() + .name("Email via SendGrid") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("sendgrid", "ses"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Routes email through sendgrid with SES failover") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "sendgrid", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("production") + .addTag("email") + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + RoutingStrategyCreateParams.builder() + .routingStrategyCreateRequest( + RoutingStrategyCreateRequest.builder() + .name("Email via SendGrid") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + RoutingStrategyCreateRequest.builder() + .name("Email via SendGrid") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateRequestTest.kt new file mode 100644 index 00000000..1b792284 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyCreateRequestTest.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +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 RoutingStrategyCreateRequestTest { + + @Test + fun create() { + val routingStrategyCreateRequest = + RoutingStrategyCreateRequest.builder() + .name("name") + .routing( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("description") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("string") + .build() + + assertThat(routingStrategyCreateRequest.name()).isEqualTo("name") + assertThat(routingStrategyCreateRequest.routing()) + .isEqualTo( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + assertThat(routingStrategyCreateRequest.channels()) + .contains( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + assertThat(routingStrategyCreateRequest.description()).contains("description") + assertThat(routingStrategyCreateRequest.providers()) + .contains( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + assertThat(routingStrategyCreateRequest.tags().getOrNull()).containsExactly("string") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val routingStrategyCreateRequest = + RoutingStrategyCreateRequest.builder() + .name("name") + .routing( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("description") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("string") + .build() + + val roundtrippedRoutingStrategyCreateRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(routingStrategyCreateRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoutingStrategyCreateRequest).isEqualTo(routingStrategyCreateRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyGetResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyGetResponseTest.kt new file mode 100644 index 00000000..a80ce950 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyGetResponseTest.kt @@ -0,0 +1,244 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +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 RoutingStrategyGetResponseTest { + + @Test + fun create() { + val routingStrategyGetResponse = + RoutingStrategyGetResponse.builder() + .id("id") + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .created(0L) + .creator("creator") + .name("name") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .routing( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + .description("description") + .addTag("string") + .updated(0L) + .updater("updater") + .build() + + assertThat(routingStrategyGetResponse.id()).isEqualTo("id") + assertThat(routingStrategyGetResponse.channels()) + .isEqualTo( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + assertThat(routingStrategyGetResponse.created()).isEqualTo(0L) + assertThat(routingStrategyGetResponse.creator()).isEqualTo("creator") + assertThat(routingStrategyGetResponse.name()).isEqualTo("name") + assertThat(routingStrategyGetResponse.providers()) + .isEqualTo( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + assertThat(routingStrategyGetResponse.routing()) + .isEqualTo( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + assertThat(routingStrategyGetResponse.description()).contains("description") + assertThat(routingStrategyGetResponse.tags().getOrNull()).containsExactly("string") + assertThat(routingStrategyGetResponse.updated()).contains(0L) + assertThat(routingStrategyGetResponse.updater()).contains("updater") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val routingStrategyGetResponse = + RoutingStrategyGetResponse.builder() + .id("id") + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .created(0L) + .creator("creator") + .name("name") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .routing( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + .description("description") + .addTag("string") + .updated(0L) + .updater("updater") + .build() + + val roundtrippedRoutingStrategyGetResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(routingStrategyGetResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoutingStrategyGetResponse).isEqualTo(routingStrategyGetResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyListParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyListParamsTest.kt new file mode 100644 index 00000000..1070a40e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyListParamsTest.kt @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import com.courier.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoutingStrategyListParamsTest { + + @Test + fun create() { + RoutingStrategyListParams.builder().cursor("cursor").limit(1L).build() + } + + @Test + fun queryParams() { + val params = RoutingStrategyListParams.builder().cursor("cursor").limit(1L).build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo(QueryParams.builder().put("cursor", "cursor").put("limit", "1").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = RoutingStrategyListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyListResponseTest.kt new file mode 100644 index 00000000..17031095 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyListResponseTest.kt @@ -0,0 +1,77 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import com.courier.core.jsonMapper +import com.courier.models.Paging +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoutingStrategyListResponseTest { + + @Test + fun create() { + val routingStrategyListResponse = + RoutingStrategyListResponse.builder() + .paging(Paging.builder().more(true).cursor("cursor").build()) + .addResult( + RoutingStrategySummary.builder() + .id("id") + .created(0L) + .creator("creator") + .name("name") + .description("description") + .addTag("string") + .updated(0L) + .updater("updater") + .build() + ) + .build() + + assertThat(routingStrategyListResponse.paging()) + .isEqualTo(Paging.builder().more(true).cursor("cursor").build()) + assertThat(routingStrategyListResponse.results()) + .containsExactly( + RoutingStrategySummary.builder() + .id("id") + .created(0L) + .creator("creator") + .name("name") + .description("description") + .addTag("string") + .updated(0L) + .updater("updater") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val routingStrategyListResponse = + RoutingStrategyListResponse.builder() + .paging(Paging.builder().more(true).cursor("cursor").build()) + .addResult( + RoutingStrategySummary.builder() + .id("id") + .created(0L) + .creator("creator") + .name("name") + .description("description") + .addTag("string") + .updated(0L) + .updater("updater") + .build() + ) + .build() + + val roundtrippedRoutingStrategyListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(routingStrategyListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoutingStrategyListResponse).isEqualTo(routingStrategyListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyMutationResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyMutationResponseTest.kt new file mode 100644 index 00000000..d02f1d89 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyMutationResponseTest.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +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 RoutingStrategyMutationResponseTest { + + @Test + fun create() { + val routingStrategyMutationResponse = + RoutingStrategyMutationResponse.builder().id("id").build() + + assertThat(routingStrategyMutationResponse.id()).isEqualTo("id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val routingStrategyMutationResponse = + RoutingStrategyMutationResponse.builder().id("id").build() + + val roundtrippedRoutingStrategyMutationResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(routingStrategyMutationResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoutingStrategyMutationResponse) + .isEqualTo(routingStrategyMutationResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceParamsTest.kt new file mode 100644 index 00000000..a4f7ad2f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceParamsTest.kt @@ -0,0 +1,287 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import com.courier.core.JsonValue +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoutingStrategyReplaceParamsTest { + + @Test + fun create() { + RoutingStrategyReplaceParams.builder() + .id("id") + .routingStrategyReplaceRequest( + RoutingStrategyReplaceRequest.builder() + .name("Email via SendGrid v2") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("ses", "sendgrid"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Updated routing with SES primary") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "ses", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .tags(listOf("production", "email", "v2")) + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + RoutingStrategyReplaceParams.builder() + .id("id") + .routingStrategyReplaceRequest( + RoutingStrategyReplaceRequest.builder() + .name("Email via SendGrid v2") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + RoutingStrategyReplaceParams.builder() + .id("id") + .routingStrategyReplaceRequest( + RoutingStrategyReplaceRequest.builder() + .name("Email via SendGrid v2") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("ses", "sendgrid"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Updated routing with SES primary") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "ses", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .tags(listOf("production", "email", "v2")) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + RoutingStrategyReplaceRequest.builder() + .name("Email via SendGrid v2") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("ses", "sendgrid"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Updated routing with SES primary") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "ses", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .tags(listOf("production", "email", "v2")) + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + RoutingStrategyReplaceParams.builder() + .id("id") + .routingStrategyReplaceRequest( + RoutingStrategyReplaceRequest.builder() + .name("Email via SendGrid v2") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + RoutingStrategyReplaceRequest.builder() + .name("Email via SendGrid v2") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceRequestTest.kt new file mode 100644 index 00000000..382745ba --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyReplaceRequestTest.kt @@ -0,0 +1,230 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +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 RoutingStrategyReplaceRequestTest { + + @Test + fun create() { + val routingStrategyReplaceRequest = + RoutingStrategyReplaceRequest.builder() + .name("name") + .routing( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("description") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("string") + .build() + + assertThat(routingStrategyReplaceRequest.name()).isEqualTo("name") + assertThat(routingStrategyReplaceRequest.routing()) + .isEqualTo( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + assertThat(routingStrategyReplaceRequest.channels()) + .contains( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + assertThat(routingStrategyReplaceRequest.description()).contains("description") + assertThat(routingStrategyReplaceRequest.providers()) + .contains( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + assertThat(routingStrategyReplaceRequest.tags().getOrNull()).containsExactly("string") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val routingStrategyReplaceRequest = + RoutingStrategyReplaceRequest.builder() + .name("name") + .routing( + MessageRouting.builder() + .addChannel("string") + .method(MessageRouting.Method.ALL) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("string"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("description") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("string") + .build() + + val roundtrippedRoutingStrategyReplaceRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(routingStrategyReplaceRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoutingStrategyReplaceRequest) + .isEqualTo(routingStrategyReplaceRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyRetrieveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyRetrieveParamsTest.kt new file mode 100644 index 00000000..deceb0b5 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategyRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoutingStrategyRetrieveParamsTest { + + @Test + fun create() { + RoutingStrategyRetrieveParams.builder().id("id").build() + } + + @Test + fun pathParams() { + val params = RoutingStrategyRetrieveParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategySummaryTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategySummaryTest.kt new file mode 100644 index 00000000..b048af61 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/routingstrategies/RoutingStrategySummaryTest.kt @@ -0,0 +1,60 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.routingstrategies + +import com.courier.core.jsonMapper +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 RoutingStrategySummaryTest { + + @Test + fun create() { + val routingStrategySummary = + RoutingStrategySummary.builder() + .id("id") + .created(0L) + .creator("creator") + .name("name") + .description("description") + .addTag("string") + .updated(0L) + .updater("updater") + .build() + + assertThat(routingStrategySummary.id()).isEqualTo("id") + assertThat(routingStrategySummary.created()).isEqualTo(0L) + assertThat(routingStrategySummary.creator()).isEqualTo("creator") + assertThat(routingStrategySummary.name()).isEqualTo("name") + assertThat(routingStrategySummary.description()).contains("description") + assertThat(routingStrategySummary.tags().getOrNull()).containsExactly("string") + assertThat(routingStrategySummary.updated()).contains(0L) + assertThat(routingStrategySummary.updater()).contains("updater") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val routingStrategySummary = + RoutingStrategySummary.builder() + .id("id") + .created(0L) + .creator("creator") + .name("name") + .description("description") + .addTag("string") + .updated(0L) + .updater("updater") + .build() + + val roundtrippedRoutingStrategySummary = + jsonMapper.readValue( + jsonMapper.writeValueAsString(routingStrategySummary), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoutingStrategySummary).isEqualTo(routingStrategySummary) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/send/SendMessageParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/send/SendMessageParamsTest.kt index ed44547f..6ce5de55 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/send/SendMessageParamsTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/send/SendMessageParamsTest.kt @@ -4,7 +4,9 @@ package com.courier.models.send import com.courier.core.JsonValue import com.courier.models.ElementalContentSugar +import com.courier.models.MessageChannels import com.courier.models.MessageContext +import com.courier.models.MessageProviders import com.courier.models.UserRecipient import com.courier.models.Utm import org.assertj.core.api.Assertions.assertThat @@ -19,7 +21,7 @@ internal class SendMessageParamsTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -88,7 +90,7 @@ internal class SendMessageParamsTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -219,7 +221,7 @@ internal class SendMessageParamsTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -290,7 +292,7 @@ internal class SendMessageParamsTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -425,7 +427,7 @@ internal class SendMessageParamsTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -494,7 +496,7 @@ internal class SendMessageParamsTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/models/tenants/PutTenantTemplateRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/tenants/PutTenantTemplateRequestTest.kt index e3120505..f85c5745 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/tenants/PutTenantTemplateRequestTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/tenants/PutTenantTemplateRequestTest.kt @@ -6,6 +6,8 @@ import com.courier.core.JsonValue import com.courier.core.jsonMapper import com.courier.models.ElementalContent import com.courier.models.ElementalTextNodeWithType +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders import com.courier.models.MessageRouting import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat @@ -34,7 +36,7 @@ internal class PutTenantTemplateRequestTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -62,7 +64,7 @@ internal class PutTenantTemplateRequestTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -115,7 +117,7 @@ internal class PutTenantTemplateRequestTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -143,7 +145,7 @@ internal class PutTenantTemplateRequestTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -200,7 +202,7 @@ internal class PutTenantTemplateRequestTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -228,7 +230,7 @@ internal class PutTenantTemplateRequestTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/models/tenants/TenantTemplateInputTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/tenants/TenantTemplateInputTest.kt index d649872b..cee84e51 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/tenants/TenantTemplateInputTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/tenants/TenantTemplateInputTest.kt @@ -6,6 +6,8 @@ import com.courier.core.JsonValue import com.courier.core.jsonMapper import com.courier.models.ElementalContent import com.courier.models.ElementalTextNodeWithType +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders import com.courier.models.MessageRouting import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat @@ -32,7 +34,7 @@ internal class TenantTemplateInputTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -60,7 +62,7 @@ internal class TenantTemplateInputTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -109,7 +111,7 @@ internal class TenantTemplateInputTest { ) assertThat(tenantTemplateInput.channels()) .contains( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -138,7 +140,7 @@ internal class TenantTemplateInputTest { ) assertThat(tenantTemplateInput.providers()) .contains( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -191,7 +193,7 @@ internal class TenantTemplateInputTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -219,7 +221,7 @@ internal class TenantTemplateInputTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/models/tenants/templates/TemplateReplaceParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/tenants/templates/TemplateReplaceParamsTest.kt index 67cf9e87..d9211a8f 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/tenants/templates/TemplateReplaceParamsTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/tenants/templates/TemplateReplaceParamsTest.kt @@ -5,6 +5,8 @@ package com.courier.models.tenants.templates import com.courier.core.JsonValue import com.courier.models.ElementalContent import com.courier.models.ElementalTextNodeWithType +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders import com.courier.models.MessageRouting import com.courier.models.tenants.PutTenantTemplateRequest import com.courier.models.tenants.TenantTemplateInput @@ -37,7 +39,7 @@ internal class TemplateReplaceParamsTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -65,7 +67,7 @@ internal class TemplateReplaceParamsTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -156,7 +158,7 @@ internal class TemplateReplaceParamsTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -185,7 +187,7 @@ internal class TemplateReplaceParamsTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -244,7 +246,7 @@ internal class TemplateReplaceParamsTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -272,7 +274,7 @@ internal class TemplateReplaceParamsTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/services/ErrorHandlingTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/ErrorHandlingTest.kt index 1d44e8fa..c47f3113 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/ErrorHandlingTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/ErrorHandlingTest.kt @@ -17,7 +17,9 @@ import com.courier.errors.UnauthorizedException import com.courier.errors.UnexpectedStatusCodeException import com.courier.errors.UnprocessableEntityException import com.courier.models.ElementalContentSugar +import com.courier.models.MessageChannels import com.courier.models.MessageContext +import com.courier.models.MessageProviders import com.courier.models.UserRecipient import com.courier.models.Utm import com.courier.models.send.SendMessageParams @@ -80,7 +82,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -155,7 +157,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -313,7 +315,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -388,7 +390,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -546,7 +548,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -621,7 +623,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -779,7 +781,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -854,7 +856,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1012,7 +1014,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1087,7 +1089,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1245,7 +1247,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1320,7 +1322,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1478,7 +1480,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1553,7 +1555,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1711,7 +1713,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1786,7 +1788,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -1944,7 +1946,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2019,7 +2021,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2177,7 +2179,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2252,7 +2254,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2410,7 +2412,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2485,7 +2487,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2643,7 +2645,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2718,7 +2720,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2876,7 +2878,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -2951,7 +2953,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -3109,7 +3111,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -3184,7 +3186,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -3342,7 +3344,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -3417,7 +3419,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -3575,7 +3577,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -3650,7 +3652,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -3806,7 +3808,7 @@ internal class ErrorHandlingTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -3881,7 +3883,7 @@ internal class ErrorHandlingTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/services/ServiceParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/ServiceParamsTest.kt index 56b92d4a..4eab125f 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/ServiceParamsTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/ServiceParamsTest.kt @@ -6,7 +6,9 @@ import com.courier.client.CourierClient import com.courier.client.okhttp.CourierOkHttpClient import com.courier.core.JsonValue import com.courier.models.ElementalContentSugar +import com.courier.models.MessageChannels import com.courier.models.MessageContext +import com.courier.models.MessageProviders import com.courier.models.UserRecipient import com.courier.models.Utm import com.courier.models.send.SendMessageParams @@ -52,7 +54,7 @@ internal class ServiceParamsTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -123,7 +125,7 @@ internal class ServiceParamsTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/NotificationServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/NotificationServiceAsyncTest.kt index e26c7a58..48c39683 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/async/NotificationServiceAsyncTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/NotificationServiceAsyncTest.kt @@ -3,12 +3,84 @@ package com.courier.services.async import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.models.ElementalChannelNodeWithType +import com.courier.models.ElementalContent import com.courier.models.notifications.NotificationListParams +import com.courier.models.notifications.NotificationListVersionsParams +import com.courier.models.notifications.NotificationPublishParams +import com.courier.models.notifications.NotificationReplaceParams +import com.courier.models.notifications.NotificationRetrieveParams +import com.courier.models.notifications.NotificationTemplateCreateRequest +import com.courier.models.notifications.NotificationTemplatePayload +import com.courier.models.notifications.NotificationTemplatePublishRequest +import com.courier.models.notifications.NotificationTemplateUpdateRequest import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test internal class NotificationServiceAsyncTest { + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val notificationServiceAsync = client.notifications() + + val notificationTemplateMutationResponseFuture = + notificationServiceAsync.create( + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder().id("brand_abc").build() + ) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Welcome Email") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("rs_123") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("marketing") + .build() + ) + .addTag("onboarding") + .addTag("welcome") + .build() + ) + .state(NotificationTemplateCreateRequest.State.DRAFT) + .build() + ) + + val notificationTemplateMutationResponse = notificationTemplateMutationResponseFuture.get() + notificationTemplateMutationResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val notificationServiceAsync = client.notifications() + + val notificationTemplateGetResponseFuture = + notificationServiceAsync.retrieve( + NotificationRetrieveParams.builder().id("id").version("version").build() + ) + + val notificationTemplateGetResponse = notificationTemplateGetResponseFuture.get() + notificationTemplateGetResponse.validate() + } + @Disabled("Mock server tests are disabled") @Test fun list() { @@ -17,13 +89,120 @@ internal class NotificationServiceAsyncTest { val notificationsFuture = notificationServiceAsync.list( - NotificationListParams.builder().cursor("cursor").notes(true).build() + NotificationListParams.builder() + .cursor("cursor") + .eventId("event_id") + .notes(true) + .build() ) val notifications = notificationsFuture.get() notifications.validate() } + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val notificationServiceAsync = client.notifications() + + val future = notificationServiceAsync.archive("id") + + val response = future.get() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listVersions() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val notificationServiceAsync = client.notifications() + + val notificationTemplateVersionListResponseFuture = + notificationServiceAsync.listVersions( + NotificationListVersionsParams.builder() + .id("id") + .cursor("cursor") + .limit(10L) + .build() + ) + + val notificationTemplateVersionListResponse = + notificationTemplateVersionListResponseFuture.get() + notificationTemplateVersionListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun publish() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val notificationServiceAsync = client.notifications() + + val future = + notificationServiceAsync.publish( + NotificationPublishParams.builder() + .id("id") + .notificationTemplatePublishRequest( + NotificationTemplatePublishRequest.builder() + .version("v321669910225") + .build() + ) + .build() + ) + + val response = future.get() + } + + @Disabled("Mock server tests are disabled") + @Test + fun replace() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val notificationServiceAsync = client.notifications() + + val notificationTemplateMutationResponseFuture = + notificationServiceAsync.replace( + NotificationReplaceParams.builder() + .id("id") + .notificationTemplateUpdateRequest( + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder().id("id").build() + ) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Updated Name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("updated") + .build() + ) + .state(NotificationTemplateUpdateRequest.State.PUBLISHED) + .build() + ) + .build() + ) + + val notificationTemplateMutationResponse = notificationTemplateMutationResponseFuture.get() + notificationTemplateMutationResponse.validate() + } + @Disabled("Mock server tests are disabled") @Test fun retrieveContent() { diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/RoutingStrategyServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/RoutingStrategyServiceAsyncTest.kt new file mode 100644 index 00000000..68efb8c8 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/RoutingStrategyServiceAsyncTest.kt @@ -0,0 +1,218 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async + +import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.core.JsonValue +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +import com.courier.models.routingstrategies.RoutingStrategyCreateRequest +import com.courier.models.routingstrategies.RoutingStrategyListParams +import com.courier.models.routingstrategies.RoutingStrategyReplaceParams +import com.courier.models.routingstrategies.RoutingStrategyReplaceRequest +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RoutingStrategyServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val routingStrategyServiceAsync = client.routingStrategies() + + val routingStrategyMutationResponseFuture = + routingStrategyServiceAsync.create( + RoutingStrategyCreateRequest.builder() + .name("Email via SendGrid") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("sendgrid", "ses"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Routes email through sendgrid with SES failover") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "sendgrid", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("production") + .addTag("email") + .build() + ) + + val routingStrategyMutationResponse = routingStrategyMutationResponseFuture.get() + routingStrategyMutationResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val routingStrategyServiceAsync = client.routingStrategies() + + val routingStrategyGetResponseFuture = routingStrategyServiceAsync.retrieve("id") + + val routingStrategyGetResponse = routingStrategyGetResponseFuture.get() + routingStrategyGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val routingStrategyServiceAsync = client.routingStrategies() + + val routingStrategyListResponseFuture = + routingStrategyServiceAsync.list( + RoutingStrategyListParams.builder().cursor("cursor").limit(1L).build() + ) + + val routingStrategyListResponse = routingStrategyListResponseFuture.get() + routingStrategyListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val routingStrategyServiceAsync = client.routingStrategies() + + val future = routingStrategyServiceAsync.archive("id") + + val response = future.get() + } + + @Disabled("Mock server tests are disabled") + @Test + fun replace() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val routingStrategyServiceAsync = client.routingStrategies() + + val routingStrategyMutationResponseFuture = + routingStrategyServiceAsync.replace( + RoutingStrategyReplaceParams.builder() + .id("id") + .routingStrategyReplaceRequest( + RoutingStrategyReplaceRequest.builder() + .name("Email via SendGrid v2") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("ses", "sendgrid"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Updated routing with SES primary") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "ses", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .tags(listOf("production", "email", "v2")) + .build() + ) + .build() + ) + + val routingStrategyMutationResponse = routingStrategyMutationResponseFuture.get() + routingStrategyMutationResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/SendServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/SendServiceAsyncTest.kt index fd2c9776..e0001f6a 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/async/SendServiceAsyncTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/SendServiceAsyncTest.kt @@ -5,7 +5,9 @@ package com.courier.services.async import com.courier.client.okhttp.CourierOkHttpClientAsync import com.courier.core.JsonValue import com.courier.models.ElementalContentSugar +import com.courier.models.MessageChannels import com.courier.models.MessageContext +import com.courier.models.MessageProviders import com.courier.models.UserRecipient import com.courier.models.Utm import com.courier.models.send.SendMessageParams @@ -27,7 +29,7 @@ internal class SendServiceAsyncTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -98,7 +100,7 @@ internal class SendServiceAsyncTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/tenants/TemplateServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/tenants/TemplateServiceAsyncTest.kt index 4350ae7b..02337e31 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/async/tenants/TemplateServiceAsyncTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/tenants/TemplateServiceAsyncTest.kt @@ -6,6 +6,8 @@ import com.courier.client.okhttp.CourierOkHttpClientAsync import com.courier.core.JsonValue import com.courier.models.ElementalContent import com.courier.models.ElementalTextNodeWithType +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders import com.courier.models.MessageRouting import com.courier.models.tenants.PostTenantTemplatePublishRequest import com.courier.models.tenants.PutTenantTemplateRequest @@ -107,7 +109,7 @@ internal class TemplateServiceAsyncTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -136,7 +138,7 @@ internal class TemplateServiceAsyncTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/NotificationServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/NotificationServiceTest.kt index 6be0d0ea..155f239c 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/blocking/NotificationServiceTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/NotificationServiceTest.kt @@ -3,12 +3,82 @@ package com.courier.services.blocking import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.models.ElementalChannelNodeWithType +import com.courier.models.ElementalContent import com.courier.models.notifications.NotificationListParams +import com.courier.models.notifications.NotificationListVersionsParams +import com.courier.models.notifications.NotificationPublishParams +import com.courier.models.notifications.NotificationReplaceParams +import com.courier.models.notifications.NotificationRetrieveParams +import com.courier.models.notifications.NotificationTemplateCreateRequest +import com.courier.models.notifications.NotificationTemplatePayload +import com.courier.models.notifications.NotificationTemplatePublishRequest +import com.courier.models.notifications.NotificationTemplateUpdateRequest import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test internal class NotificationServiceTest { + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val notificationService = client.notifications() + + val notificationTemplateMutationResponse = + notificationService.create( + NotificationTemplateCreateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder().id("brand_abc").build() + ) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Welcome Email") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("rs_123") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("marketing") + .build() + ) + .addTag("onboarding") + .addTag("welcome") + .build() + ) + .state(NotificationTemplateCreateRequest.State.DRAFT) + .build() + ) + + notificationTemplateMutationResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val notificationService = client.notifications() + + val notificationTemplateGetResponse = + notificationService.retrieve( + NotificationRetrieveParams.builder().id("id").version("version").build() + ) + + notificationTemplateGetResponse.validate() + } + @Disabled("Mock server tests are disabled") @Test fun list() { @@ -17,12 +87,109 @@ internal class NotificationServiceTest { val notifications = notificationService.list( - NotificationListParams.builder().cursor("cursor").notes(true).build() + NotificationListParams.builder() + .cursor("cursor") + .eventId("event_id") + .notes(true) + .build() ) notifications.validate() } + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val notificationService = client.notifications() + + notificationService.archive("id") + } + + @Disabled("Mock server tests are disabled") + @Test + fun listVersions() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val notificationService = client.notifications() + + val notificationTemplateVersionListResponse = + notificationService.listVersions( + NotificationListVersionsParams.builder() + .id("id") + .cursor("cursor") + .limit(10L) + .build() + ) + + notificationTemplateVersionListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun publish() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val notificationService = client.notifications() + + notificationService.publish( + NotificationPublishParams.builder() + .id("id") + .notificationTemplatePublishRequest( + NotificationTemplatePublishRequest.builder().version("v321669910225").build() + ) + .build() + ) + } + + @Disabled("Mock server tests are disabled") + @Test + fun replace() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val notificationService = client.notifications() + + val notificationTemplateMutationResponse = + notificationService.replace( + NotificationReplaceParams.builder() + .id("id") + .notificationTemplateUpdateRequest( + NotificationTemplateUpdateRequest.builder() + .notification( + NotificationTemplatePayload.builder() + .brand( + NotificationTemplatePayload.Brand.builder().id("id").build() + ) + .content( + ElementalContent.builder() + .addElement( + ElementalChannelNodeWithType.builder() + .type(ElementalChannelNodeWithType.Type.CHANNEL) + .build() + ) + .version("2022-01-01") + .build() + ) + .name("Updated Name") + .routing( + NotificationTemplatePayload.Routing.builder() + .strategyId("strategy_id") + .build() + ) + .subscription( + NotificationTemplatePayload.Subscription.builder() + .topicId("topic_id") + .build() + ) + .addTag("updated") + .build() + ) + .state(NotificationTemplateUpdateRequest.State.PUBLISHED) + .build() + ) + .build() + ) + + notificationTemplateMutationResponse.validate() + } + @Disabled("Mock server tests are disabled") @Test fun retrieveContent() { diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/RoutingStrategyServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/RoutingStrategyServiceTest.kt new file mode 100644 index 00000000..e50f6201 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/RoutingStrategyServiceTest.kt @@ -0,0 +1,212 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking + +import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.core.JsonValue +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders +import com.courier.models.MessageRouting +import com.courier.models.routingstrategies.RoutingStrategyCreateRequest +import com.courier.models.routingstrategies.RoutingStrategyListParams +import com.courier.models.routingstrategies.RoutingStrategyReplaceParams +import com.courier.models.routingstrategies.RoutingStrategyReplaceRequest +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RoutingStrategyServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val routingStrategyService = client.routingStrategies() + + val routingStrategyMutationResponse = + routingStrategyService.create( + RoutingStrategyCreateRequest.builder() + .name("Email via SendGrid") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("sendgrid", "ses"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Routes email through sendgrid with SES failover") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "sendgrid", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .addTag("production") + .addTag("email") + .build() + ) + + routingStrategyMutationResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val routingStrategyService = client.routingStrategies() + + val routingStrategyGetResponse = routingStrategyService.retrieve("id") + + routingStrategyGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val routingStrategyService = client.routingStrategies() + + val routingStrategyListResponse = + routingStrategyService.list( + RoutingStrategyListParams.builder().cursor("cursor").limit(1L).build() + ) + + routingStrategyListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val routingStrategyService = client.routingStrategies() + + routingStrategyService.archive("id") + } + + @Disabled("Mock server tests are disabled") + @Test + fun replace() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val routingStrategyService = client.routingStrategies() + + val routingStrategyMutationResponse = + routingStrategyService.replace( + RoutingStrategyReplaceParams.builder() + .id("id") + .routingStrategyReplaceRequest( + RoutingStrategyReplaceRequest.builder() + .name("Email via SendGrid v2") + .routing( + MessageRouting.builder() + .addChannel("email") + .method(MessageRouting.Method.SINGLE) + .build() + ) + .channels( + MessageChannels.builder() + .putAdditionalProperty( + "email", + JsonValue.from( + mapOf( + "brand_id" to "brand_id", + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf("foo" to "bar"), + "providers" to listOf("ses", "sendgrid"), + "routing_method" to "all", + "timeouts" to mapOf("channel" to 0, "provider" to 0), + ) + ), + ) + .build() + ) + .description("Updated routing with SES primary") + .providers( + MessageProviders.builder() + .putAdditionalProperty( + "ses", + JsonValue.from( + mapOf( + "if" to "if", + "metadata" to + mapOf( + "utm" to + mapOf( + "campaign" to "campaign", + "content" to "content", + "medium" to "medium", + "source" to "source", + "term" to "term", + ) + ), + "override" to mapOf(), + "timeouts" to 0, + ) + ), + ) + .build() + ) + .tags(listOf("production", "email", "v2")) + .build() + ) + .build() + ) + + routingStrategyMutationResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/SendServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/SendServiceTest.kt index 6885c587..402fbbf5 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/blocking/SendServiceTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/SendServiceTest.kt @@ -5,7 +5,9 @@ package com.courier.services.blocking import com.courier.client.okhttp.CourierOkHttpClient import com.courier.core.JsonValue import com.courier.models.ElementalContentSugar +import com.courier.models.MessageChannels import com.courier.models.MessageContext +import com.courier.models.MessageProviders import com.courier.models.UserRecipient import com.courier.models.Utm import com.courier.models.send.SendMessageParams @@ -27,7 +29,7 @@ internal class SendServiceTest { SendMessageParams.Message.builder() .brandId("brand_id") .channels( - SendMessageParams.Message.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -98,7 +100,7 @@ internal class SendServiceTest { .build() ) .providers( - SendMessageParams.Message.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/tenants/TemplateServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/tenants/TemplateServiceTest.kt index 04d972dc..db7c0cfe 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/blocking/tenants/TemplateServiceTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/tenants/TemplateServiceTest.kt @@ -6,6 +6,8 @@ import com.courier.client.okhttp.CourierOkHttpClient import com.courier.core.JsonValue import com.courier.models.ElementalContent import com.courier.models.ElementalTextNodeWithType +import com.courier.models.MessageChannels +import com.courier.models.MessageProviders import com.courier.models.MessageRouting import com.courier.models.tenants.PostTenantTemplatePublishRequest import com.courier.models.tenants.PutTenantTemplateRequest @@ -104,7 +106,7 @@ internal class TemplateServiceTest { .build() ) .channels( - TenantTemplateInput.Channels.builder() + MessageChannels.builder() .putAdditionalProperty( "foo", JsonValue.from( @@ -133,7 +135,7 @@ internal class TemplateServiceTest { .build() ) .providers( - TenantTemplateInput.Providers.builder() + MessageProviders.builder() .putAdditionalProperty( "foo", JsonValue.from( 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 73cdacb0..acd2df32 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 @@ -63,6 +63,7 @@ internal class ProGuardCompatibilityTest { assertThat(client.messages()).isNotNull() assertThat(client.requests()).isNotNull() assertThat(client.notifications()).isNotNull() + assertThat(client.routingStrategies()).isNotNull() assertThat(client.profiles()).isNotNull() assertThat(client.tenants()).isNotNull() assertThat(client.translations()).isNotNull() diff --git a/scripts/fast-format b/scripts/fast-format index 1b3bc473..35a1dee2 100755 --- a/scripts/fast-format +++ b/scripts/fast-format @@ -24,8 +24,8 @@ if [ ! -f "$FILE_LIST" ]; then exit 1 fi -if ! command -v ktfmt-fast-format &> /dev/null; then - echo "Error: ktfmt-fast-format not found" +if ! command -v ktfmt &> /dev/null; then + echo "Error: ktfmt not found" exit 1 fi @@ -36,7 +36,7 @@ echo "==> Done looking for Kotlin files" if [[ -n "$kt_files" ]]; then echo "==> will format Kotlin files" - echo "$kt_files" | tr '\n' '\0' | xargs -0 ktfmt-fast-format --kotlinlang-style "$@" + echo "$kt_files" | tr '\n' '\0' | xargs -0 ktfmt --kotlinlang-style "$@" else echo "No Kotlin files to format -- expected outcome during incremental formatting" fi