From 46de0d2d85f59c4d1d220dc3e3028c7e6760c769 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 23:02:53 +0000 Subject: [PATCH 1/2] feat(api): add audience/list/slack/msTeams/pagerduty/webhook recipients, restructure to union --- .stats.yml | 6 +- .../com/courier/models/AirshipProfile.kt | 234 +++ .../courier/models/AirshipProfileAudience.kt | 171 ++ .../com/courier/models/AudienceFilter.kt | 483 +++++ .../com/courier/models/AudienceRecipient.kt | 375 ++++ .../main/kotlin/com/courier/models/Discord.kt | 194 ++ .../main/kotlin/com/courier/models/Expo.kt | 189 ++ .../kotlin/com/courier/models/Intercom.kt | 206 ++ .../com/courier/models/IntercomRecipient.kt | 167 ++ .../kotlin/com/courier/models/ListFilter.kt | 483 +++++ .../courier/models/ListPatternRecipient.kt | 298 +++ .../com/courier/models/ListRecipient.kt | 349 ++++ .../main/kotlin/com/courier/models/MsTeams.kt | 314 +++ .../courier/models/MsTeamsBaseProperties.kt | 208 ++ .../com/courier/models/MsTeamsRecipient.kt | 200 ++ .../com/courier/models/MultipleTokens.kt | 190 ++ .../kotlin/com/courier/models/Pagerduty.kt | 274 +++ .../com/courier/models/PagerdutyRecipient.kt | 175 ++ .../kotlin/com/courier/models/Recipient.kt | 1091 ---------- .../com/courier/models/SendDirectMessage.kt | 167 ++ .../com/courier/models/SendToChannel.kt | 171 ++ .../courier/models/SendToMsTeamsChannelId.kt | 244 +++ .../models/SendToMsTeamsChannelName.kt | 281 +++ .../models/SendToMsTeamsConversationId.kt | 250 +++ .../com/courier/models/SendToMsTeamsEmail.kt | 243 +++ .../com/courier/models/SendToMsTeamsUserId.kt | 243 +++ .../com/courier/models/SendToSlackChannel.kt | 210 ++ .../com/courier/models/SendToSlackEmail.kt | 209 ++ .../com/courier/models/SendToSlackUserId.kt | 209 ++ .../main/kotlin/com/courier/models/Slack.kt | 224 ++ .../com/courier/models/SlackBaseProperties.kt | 175 ++ .../com/courier/models/SlackRecipient.kt | 181 ++ .../main/kotlin/com/courier/models/Token.kt | 166 ++ .../kotlin/com/courier/models/UserProfile.kt | 1860 +++++++++++++++++ .../models/UserProfileFirebaseToken.kt | 194 ++ .../com/courier/models/WebhookAuthMode.kt | 139 ++ .../courier/models/WebhookAuthentication.kt | 291 +++ .../com/courier/models/WebhookMethod.kt | 132 ++ .../com/courier/models/WebhookProfile.kt | 446 ++++ .../com/courier/models/WebhookProfileType.kt | 134 ++ .../com/courier/models/WebhookRecipient.kt | 172 ++ .../com/courier/models/audiences/Audience.kt | 8 + .../models/audiences/AudienceUpdateParams.kt | 22 + .../com/courier/models/audiences/Filter.kt | 516 ++--- .../courier/models/audiences/FilterConfig.kt | 508 ++--- .../models/audiences/NestedFilterConfig.kt | 438 ++++ .../models/audiences/SingleFilterConfig.kt | 454 ++++ .../courier/models/send/SendMessageParams.kt | 296 ++- .../models/AirshipProfileAudienceTest.kt | 34 + .../com/courier/models/AirshipProfileTest.kt | 42 + .../com/courier/models/AudienceFilterTest.kt | 44 + .../courier/models/AudienceRecipientTest.kt | 78 + .../kotlin/com/courier/models/DiscordTest.kt | 77 + .../kotlin/com/courier/models/ExpoTest.kt | 79 + .../courier/models/IntercomRecipientTest.kt | 32 + .../kotlin/com/courier/models/IntercomTest.kt | 35 + .../com/courier/models/ListFilterTest.kt | 44 + .../models/ListPatternRecipientTest.kt | 55 + .../com/courier/models/ListRecipientTest.kt | 78 + .../models/MsTeamsBasePropertiesTest.kt | 35 + .../courier/models/MsTeamsRecipientTest.kt | 59 + .../kotlin/com/courier/models/MsTeamsTest.kt | 215 ++ .../com/courier/models/MultipleTokensTest.kt | 34 + .../courier/models/PagerdutyRecipientTest.kt | 60 + .../com/courier/models/PagerdutyTest.kt | 47 + .../com/courier/models/RecipientTest.kt | 201 -- .../courier/models/SendDirectMessageTest.kt | 32 + .../com/courier/models/SendToChannelTest.kt | 32 + .../models/SendToMsTeamsChannelIdTest.kt | 44 + .../models/SendToMsTeamsChannelNameTest.kt | 47 + .../models/SendToMsTeamsConversationIdTest.kt | 44 + .../courier/models/SendToMsTeamsEmailTest.kt | 44 + .../courier/models/SendToMsTeamsUserIdTest.kt | 44 + .../courier/models/SendToSlackChannelTest.kt | 35 + .../courier/models/SendToSlackEmailTest.kt | 35 + .../courier/models/SendToSlackUserIdTest.kt | 35 + .../courier/models/SlackBasePropertiesTest.kt | 32 + .../com/courier/models/SlackRecipientTest.kt | 56 + .../kotlin/com/courier/models/SlackTest.kt | 111 + .../kotlin/com/courier/models/TokenTest.kt | 29 + .../models/UserProfileFirebaseTokenTest.kt | 72 + .../com/courier/models/UserProfileTest.kt | 246 +++ .../models/WebhookAuthenticationTest.kt | 47 + .../com/courier/models/WebhookProfileTest.kt | 86 + .../courier/models/WebhookRecipientTest.kt | 97 + .../audiences/AudienceListResponseTest.kt | 12 +- .../courier/models/audiences/AudienceTest.kt | 20 +- .../audiences/AudienceUpdateParamsTest.kt | 20 +- .../audiences/AudienceUpdateResponseTest.kt | 12 +- .../models/audiences/FilterConfigTest.kt | 95 +- .../courier/models/audiences/FilterTest.kt | 90 +- .../audiences/NestedFilterConfigTest.kt | 62 + .../audiences/SingleFilterConfigTest.kt | 44 + .../models/send/SendMessageParamsTest.kt | 6 +- .../com/courier/services/ErrorHandlingTest.kt | 34 +- .../com/courier/services/ServiceParamsTest.kt | 2 +- .../async/AudienceServiceAsyncTest.kt | 6 +- .../services/async/SendServiceAsyncTest.kt | 2 +- .../services/blocking/AudienceServiceTest.kt | 6 +- .../services/blocking/SendServiceTest.kt | 2 +- .../proguard/ProGuardCompatibilityTest.kt | 27 +- 101 files changed, 14870 insertions(+), 2177 deletions(-) create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/AirshipProfile.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/AirshipProfileAudience.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/AudienceFilter.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/AudienceRecipient.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/Discord.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/Expo.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/Intercom.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/IntercomRecipient.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/ListFilter.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/ListPatternRecipient.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/ListRecipient.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/MsTeams.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/MsTeamsBaseProperties.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/MsTeamsRecipient.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/MultipleTokens.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/Pagerduty.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/PagerdutyRecipient.kt delete mode 100644 courier-java-core/src/main/kotlin/com/courier/models/Recipient.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendDirectMessage.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToChannel.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsChannelId.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsChannelName.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsConversationId.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsEmail.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsUserId.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToSlackChannel.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToSlackEmail.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SendToSlackUserId.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/Slack.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SlackBaseProperties.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/SlackRecipient.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/Token.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/UserProfile.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/UserProfileFirebaseToken.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/WebhookAuthMode.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/WebhookAuthentication.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/WebhookMethod.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/WebhookProfile.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/WebhookProfileType.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/WebhookRecipient.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/audiences/NestedFilterConfig.kt create mode 100644 courier-java-core/src/main/kotlin/com/courier/models/audiences/SingleFilterConfig.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/AirshipProfileAudienceTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/AirshipProfileTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/AudienceFilterTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/AudienceRecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/DiscordTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/ExpoTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/IntercomRecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/IntercomTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/ListFilterTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/ListPatternRecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/ListRecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/MsTeamsBasePropertiesTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/MsTeamsRecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/MsTeamsTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/MultipleTokensTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/PagerdutyRecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/PagerdutyTest.kt delete mode 100644 courier-java-core/src/test/kotlin/com/courier/models/RecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendDirectMessageTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToChannelTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsChannelIdTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsChannelNameTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsConversationIdTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsEmailTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsUserIdTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToSlackChannelTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToSlackEmailTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SendToSlackUserIdTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SlackBasePropertiesTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SlackRecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/SlackTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/TokenTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/UserProfileFirebaseTokenTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/UserProfileTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/WebhookAuthenticationTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/WebhookProfileTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/WebhookRecipientTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/audiences/NestedFilterConfigTest.kt create mode 100644 courier-java-core/src/test/kotlin/com/courier/models/audiences/SingleFilterConfigTest.kt diff --git a/.stats.yml b/.stats.yml index 4b96b1ea..1c575735 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 77 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier%2Fcourier-9859cb664d1a9de0323c857e96cf41d0a5ac5c5903c501059f36bf62553b1583.yml -openapi_spec_hash: d29149d60504eba35c63f583ce4bf0bc -config_hash: 3ec521d062b05b81c22bc1a25bfe3d02 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier%2Fcourier-fab4ee8a24b719456f38d4a6050f4e40158db57937a1d55035be9325df494941.yml +openapi_spec_hash: be1371c71559511c79a4285238b7131c +config_hash: 54d2059f36ceee17804ef6c2800affd2 diff --git a/courier-java-core/src/main/kotlin/com/courier/models/AirshipProfile.kt b/courier-java-core/src/main/kotlin/com/courier/models/AirshipProfile.kt new file mode 100644 index 00000000..73b3ae8f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/AirshipProfile.kt @@ -0,0 +1,234 @@ +// 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.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class AirshipProfile +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val audience: JsonField, + private val deviceTypes: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("audience") + @ExcludeMissing + audience: JsonField = JsonMissing.of(), + @JsonProperty("device_types") + @ExcludeMissing + deviceTypes: JsonField> = JsonMissing.of(), + ) : this(audience, deviceTypes, 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 audience(): AirshipProfileAudience = audience.getRequired("audience") + + /** + * @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 deviceTypes(): List = deviceTypes.getRequired("device_types") + + /** + * Returns the raw JSON value of [audience]. + * + * Unlike [audience], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("audience") + @ExcludeMissing + fun _audience(): JsonField = audience + + /** + * Returns the raw JSON value of [deviceTypes]. + * + * Unlike [deviceTypes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("device_types") + @ExcludeMissing + fun _deviceTypes(): JsonField> = deviceTypes + + @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 [AirshipProfile]. + * + * The following fields are required: + * ```java + * .audience() + * .deviceTypes() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AirshipProfile]. */ + class Builder internal constructor() { + + private var audience: JsonField? = null + private var deviceTypes: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(airshipProfile: AirshipProfile) = apply { + audience = airshipProfile.audience + deviceTypes = airshipProfile.deviceTypes.map { it.toMutableList() } + additionalProperties = airshipProfile.additionalProperties.toMutableMap() + } + + fun audience(audience: AirshipProfileAudience) = audience(JsonField.of(audience)) + + /** + * Sets [Builder.audience] to an arbitrary JSON value. + * + * You should usually call [Builder.audience] with a well-typed [AirshipProfileAudience] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun audience(audience: JsonField) = apply { + this.audience = audience + } + + fun deviceTypes(deviceTypes: List) = deviceTypes(JsonField.of(deviceTypes)) + + /** + * Sets [Builder.deviceTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.deviceTypes] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun deviceTypes(deviceTypes: JsonField>) = apply { + this.deviceTypes = deviceTypes.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [deviceTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDeviceType(deviceType: String) = apply { + deviceTypes = + (deviceTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("deviceTypes", it).add(deviceType) + } + } + + 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 [AirshipProfile]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .audience() + * .deviceTypes() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AirshipProfile = + AirshipProfile( + checkRequired("audience", audience), + checkRequired("deviceTypes", deviceTypes).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AirshipProfile = apply { + if (validated) { + return@apply + } + + audience().validate() + deviceTypes() + 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 = + (audience.asKnown().getOrNull()?.validity() ?: 0) + + (deviceTypes.asKnown().getOrNull()?.size ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AirshipProfile && + audience == other.audience && + deviceTypes == other.deviceTypes && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(audience, deviceTypes, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AirshipProfile{audience=$audience, deviceTypes=$deviceTypes, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/AirshipProfileAudience.kt b/courier-java-core/src/main/kotlin/com/courier/models/AirshipProfileAudience.kt new file mode 100644 index 00000000..3221dd9b --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/AirshipProfileAudience.kt @@ -0,0 +1,171 @@ +// 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.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 + +class AirshipProfileAudience +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val namedUser: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("named_user") @ExcludeMissing namedUser: JsonField = JsonMissing.of() + ) : this(namedUser, 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 namedUser(): String = namedUser.getRequired("named_user") + + /** + * Returns the raw JSON value of [namedUser]. + * + * Unlike [namedUser], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("named_user") @ExcludeMissing fun _namedUser(): JsonField = namedUser + + @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 [AirshipProfileAudience]. + * + * The following fields are required: + * ```java + * .namedUser() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AirshipProfileAudience]. */ + class Builder internal constructor() { + + private var namedUser: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(airshipProfileAudience: AirshipProfileAudience) = apply { + namedUser = airshipProfileAudience.namedUser + additionalProperties = airshipProfileAudience.additionalProperties.toMutableMap() + } + + fun namedUser(namedUser: String) = namedUser(JsonField.of(namedUser)) + + /** + * Sets [Builder.namedUser] to an arbitrary JSON value. + * + * You should usually call [Builder.namedUser] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun namedUser(namedUser: JsonField) = apply { this.namedUser = namedUser } + + 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 [AirshipProfileAudience]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .namedUser() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AirshipProfileAudience = + AirshipProfileAudience( + checkRequired("namedUser", namedUser), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AirshipProfileAudience = apply { + if (validated) { + return@apply + } + + namedUser() + 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 (namedUser.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AirshipProfileAudience && + namedUser == other.namedUser && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(namedUser, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AirshipProfileAudience{namedUser=$namedUser, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/AudienceFilter.kt b/courier-java-core/src/main/kotlin/com/courier/models/AudienceFilter.kt new file mode 100644 index 00000000..d49d13b5 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/AudienceFilter.kt @@ -0,0 +1,483 @@ +// 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.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 + +class AudienceFilter +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val operator: JsonField, + private val path: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("operator") @ExcludeMissing operator: JsonField = JsonMissing.of(), + @JsonProperty("path") @ExcludeMissing path: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(operator, path, value, mutableMapOf()) + + /** + * Send to users only if they are member of the account + * + * @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 operator(): Operator = operator.getRequired("operator") + + /** + * @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 path(): Path = path.getRequired("path") + + /** + * @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 value(): String = value.getRequired("value") + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [path]. + * + * Unlike [path], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path + + /** + * Returns the raw JSON value of [value]. + * + * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + + @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 [AudienceFilter]. + * + * The following fields are required: + * ```java + * .operator() + * .path() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AudienceFilter]. */ + class Builder internal constructor() { + + private var operator: JsonField? = null + private var path: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(audienceFilter: AudienceFilter) = apply { + operator = audienceFilter.operator + path = audienceFilter.path + value = audienceFilter.value + additionalProperties = audienceFilter.additionalProperties.toMutableMap() + } + + /** Send to users only if they are member of the account */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + fun path(path: Path) = path(JsonField.of(path)) + + /** + * Sets [Builder.path] to an arbitrary JSON value. + * + * You should usually call [Builder.path] with a well-typed [Path] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun path(path: JsonField) = apply { this.path = path } + + fun value(value: String) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun value(value: JsonField) = apply { this.value = value } + + 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 [AudienceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .operator() + * .path() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AudienceFilter = + AudienceFilter( + checkRequired("operator", operator), + checkRequired("path", path), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AudienceFilter = apply { + if (validated) { + return@apply + } + + operator().validate() + path().validate() + value() + 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 = + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (path.asKnown().getOrNull()?.validity() ?: 0) + + (if (value.asKnown().isPresent) 1 else 0) + + /** Send to users only if they are member of the account */ + class Operator @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 MEMBER_OF = of("MEMBER_OF") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + MEMBER_OF + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] 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 { + MEMBER_OF, + /** An enum member indicating that [Operator] 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) { + MEMBER_OF -> Value.MEMBER_OF + 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) { + MEMBER_OF -> Known.MEMBER_OF + else -> throw CourierInvalidDataException("Unknown Operator: $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(): Operator = 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Path @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 ACCOUNT_ID = of("account_id") + + @JvmStatic fun of(value: String) = Path(JsonField.of(value)) + } + + /** An enum containing [Path]'s known values. */ + enum class Known { + ACCOUNT_ID + } + + /** + * An enum containing [Path]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Path] 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 { + ACCOUNT_ID, + /** An enum member indicating that [Path] 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) { + ACCOUNT_ID -> Value.ACCOUNT_ID + 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) { + ACCOUNT_ID -> Known.ACCOUNT_ID + else -> throw CourierInvalidDataException("Unknown Path: $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(): Path = 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 Path && 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 AudienceFilter && + operator == other.operator && + path == other.path && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(operator, path, value, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AudienceFilter{operator=$operator, path=$path, value=$value, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/AudienceRecipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/AudienceRecipient.kt new file mode 100644 index 00000000..47a50fb1 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/AudienceRecipient.kt @@ -0,0 +1,375 @@ +// 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.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 + +/** Send to all users in an audience */ +class AudienceRecipient +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val audienceId: JsonField, + private val data: JsonField, + private val filters: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("audience_id") + @ExcludeMissing + audienceId: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + ) : this(audienceId, data, filters, mutableMapOf()) + + /** + * A unique identifier associated with an Audience. A message will be sent to each user in the + * audience. + * + * @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 audienceId(): String = audienceId.getRequired("audience_id") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun data(): Optional = data.getOptional("data") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun filters(): Optional> = filters.getOptional("filters") + + /** + * Returns the raw JSON value of [audienceId]. + * + * Unlike [audienceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("audience_id") @ExcludeMissing fun _audienceId(): JsonField = audienceId + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + @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 [AudienceRecipient]. + * + * The following fields are required: + * ```java + * .audienceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AudienceRecipient]. */ + class Builder internal constructor() { + + private var audienceId: JsonField? = null + private var data: JsonField = JsonMissing.of() + private var filters: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(audienceRecipient: AudienceRecipient) = apply { + audienceId = audienceRecipient.audienceId + data = audienceRecipient.data + filters = audienceRecipient.filters.map { it.toMutableList() } + additionalProperties = audienceRecipient.additionalProperties.toMutableMap() + } + + /** + * A unique identifier associated with an Audience. A message will be sent to each user in + * the audience. + */ + fun audienceId(audienceId: String) = audienceId(JsonField.of(audienceId)) + + /** + * Sets [Builder.audienceId] to an arbitrary JSON value. + * + * You should usually call [Builder.audienceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun audienceId(audienceId: JsonField) = apply { this.audienceId = audienceId } + + fun data(data: Data?) = data(JsonField.ofNullable(data)) + + /** Alias for calling [Builder.data] with `data.orElse(null)`. */ + fun data(data: Optional) = data(data.getOrNull()) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] 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 } + + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + + /** Alias for calling [Builder.filters] with `filters.orElse(null)`. */ + fun filters(filters: Optional>) = filters(filters.getOrNull()) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [AudienceFilter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: AudienceFilter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + 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 [AudienceRecipient]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .audienceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AudienceRecipient = + AudienceRecipient( + checkRequired("audienceId", audienceId), + data, + (filters ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AudienceRecipient = apply { + if (validated) { + return@apply + } + + audienceId() + data().ifPresent { it.validate() } + filters().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (audienceId.asKnown().isPresent) 1 else 0) + + (data.asKnown().getOrNull()?.validity() ?: 0) + + (filters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Data + @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 [Data]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + additionalProperties = data.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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Data = Data(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Data = 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 Data && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Data{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AudienceRecipient && + audienceId == other.audienceId && + data == other.data && + filters == other.filters && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(audienceId, data, filters, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AudienceRecipient{audienceId=$audienceId, data=$data, filters=$filters, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Discord.kt b/courier-java-core/src/main/kotlin/com/courier/models/Discord.kt new file mode 100644 index 00000000..a188cb33 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Discord.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.BaseDeserializer +import com.courier.core.BaseSerializer +import com.courier.core.JsonValue +import com.courier.core.allMaxBy +import com.courier.core.getOrThrow +import com.courier.errors.CourierInvalidDataException +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.Objects +import java.util.Optional + +@JsonDeserialize(using = Discord.Deserializer::class) +@JsonSerialize(using = Discord.Serializer::class) +class Discord +private constructor( + private val sendToChannel: SendToChannel? = null, + private val sendDirectMessage: SendDirectMessage? = null, + private val _json: JsonValue? = null, +) { + + fun sendToChannel(): Optional = Optional.ofNullable(sendToChannel) + + fun sendDirectMessage(): Optional = Optional.ofNullable(sendDirectMessage) + + fun isSendToChannel(): Boolean = sendToChannel != null + + fun isSendDirectMessage(): Boolean = sendDirectMessage != null + + fun asSendToChannel(): SendToChannel = sendToChannel.getOrThrow("sendToChannel") + + fun asSendDirectMessage(): SendDirectMessage = sendDirectMessage.getOrThrow("sendDirectMessage") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + sendToChannel != null -> visitor.visitSendToChannel(sendToChannel) + sendDirectMessage != null -> visitor.visitSendDirectMessage(sendDirectMessage) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Discord = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSendToChannel(sendToChannel: SendToChannel) { + sendToChannel.validate() + } + + override fun visitSendDirectMessage(sendDirectMessage: SendDirectMessage) { + sendDirectMessage.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 = + accept( + object : Visitor { + override fun visitSendToChannel(sendToChannel: SendToChannel) = + sendToChannel.validity() + + override fun visitSendDirectMessage(sendDirectMessage: SendDirectMessage) = + sendDirectMessage.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Discord && + sendToChannel == other.sendToChannel && + sendDirectMessage == other.sendDirectMessage + } + + override fun hashCode(): Int = Objects.hash(sendToChannel, sendDirectMessage) + + override fun toString(): String = + when { + sendToChannel != null -> "Discord{sendToChannel=$sendToChannel}" + sendDirectMessage != null -> "Discord{sendDirectMessage=$sendDirectMessage}" + _json != null -> "Discord{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Discord") + } + + companion object { + + @JvmStatic + fun ofSendToChannel(sendToChannel: SendToChannel) = Discord(sendToChannel = sendToChannel) + + @JvmStatic + fun ofSendDirectMessage(sendDirectMessage: SendDirectMessage) = + Discord(sendDirectMessage = sendDirectMessage) + } + + /** An interface that defines how to map each variant of [Discord] to a value of type [T]. */ + interface Visitor { + + fun visitSendToChannel(sendToChannel: SendToChannel): T + + fun visitSendDirectMessage(sendDirectMessage: SendDirectMessage): T + + /** + * Maps an unknown variant of [Discord] to a value of type [T]. + * + * An instance of [Discord] 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. + */ + fun unknown(json: JsonValue?): T { + throw CourierInvalidDataException("Unknown Discord: $json") + } + } + + internal class Deserializer : BaseDeserializer(Discord::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Discord { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Discord(sendToChannel = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Discord(sendDirectMessage = 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 -> Discord(_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(Discord::class) { + + override fun serialize( + value: Discord, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.sendToChannel != null -> generator.writeObject(value.sendToChannel) + value.sendDirectMessage != null -> generator.writeObject(value.sendDirectMessage) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Discord") + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Expo.kt b/courier-java-core/src/main/kotlin/com/courier/models/Expo.kt new file mode 100644 index 00000000..ddbb6749 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Expo.kt @@ -0,0 +1,189 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.BaseDeserializer +import com.courier.core.BaseSerializer +import com.courier.core.JsonValue +import com.courier.core.allMaxBy +import com.courier.core.getOrThrow +import com.courier.errors.CourierInvalidDataException +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.Objects +import java.util.Optional + +@JsonDeserialize(using = Expo.Deserializer::class) +@JsonSerialize(using = Expo.Serializer::class) +class Expo +private constructor( + private val token: Token? = null, + private val multipleTokens: MultipleTokens? = null, + private val _json: JsonValue? = null, +) { + + fun token(): Optional = Optional.ofNullable(token) + + fun multipleTokens(): Optional = Optional.ofNullable(multipleTokens) + + fun isToken(): Boolean = token != null + + fun isMultipleTokens(): Boolean = multipleTokens != null + + fun asToken(): Token = token.getOrThrow("token") + + fun asMultipleTokens(): MultipleTokens = multipleTokens.getOrThrow("multipleTokens") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + token != null -> visitor.visitToken(token) + multipleTokens != null -> visitor.visitMultipleTokens(multipleTokens) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Expo = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitToken(token: Token) { + token.validate() + } + + override fun visitMultipleTokens(multipleTokens: MultipleTokens) { + multipleTokens.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 = + accept( + object : Visitor { + override fun visitToken(token: Token) = token.validity() + + override fun visitMultipleTokens(multipleTokens: MultipleTokens) = + multipleTokens.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Expo && token == other.token && multipleTokens == other.multipleTokens + } + + override fun hashCode(): Int = Objects.hash(token, multipleTokens) + + override fun toString(): String = + when { + token != null -> "Expo{token=$token}" + multipleTokens != null -> "Expo{multipleTokens=$multipleTokens}" + _json != null -> "Expo{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Expo") + } + + companion object { + + @JvmStatic fun ofToken(token: Token) = Expo(token = token) + + @JvmStatic + fun ofMultipleTokens(multipleTokens: MultipleTokens) = Expo(multipleTokens = multipleTokens) + } + + /** An interface that defines how to map each variant of [Expo] to a value of type [T]. */ + interface Visitor { + + fun visitToken(token: Token): T + + fun visitMultipleTokens(multipleTokens: MultipleTokens): T + + /** + * Maps an unknown variant of [Expo] to a value of type [T]. + * + * An instance of [Expo] 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. + */ + fun unknown(json: JsonValue?): T { + throw CourierInvalidDataException("Unknown Expo: $json") + } + } + + internal class Deserializer : BaseDeserializer(Expo::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Expo { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Expo(token = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Expo(multipleTokens = 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 -> Expo(_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(Expo::class) { + + override fun serialize( + value: Expo, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.token != null -> generator.writeObject(value.token) + value.multipleTokens != null -> generator.writeObject(value.multipleTokens) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Expo") + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Intercom.kt b/courier-java-core/src/main/kotlin/com/courier/models/Intercom.kt new file mode 100644 index 00000000..23f38111 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Intercom.kt @@ -0,0 +1,206 @@ +// 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.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 + +class Intercom +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val from: JsonField, + private val to: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("from") @ExcludeMissing from: JsonField = JsonMissing.of(), + @JsonProperty("to") @ExcludeMissing to: JsonField = JsonMissing.of(), + ) : this(from, to, 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 from(): String = from.getRequired("from") + + /** + * @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 to(): IntercomRecipient = to.getRequired("to") + + /** + * Returns the raw JSON value of [from]. + * + * Unlike [from], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("from") @ExcludeMissing fun _from(): JsonField = from + + /** + * Returns the raw JSON value of [to]. + * + * Unlike [to], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("to") @ExcludeMissing fun _to(): JsonField = to + + @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 [Intercom]. + * + * The following fields are required: + * ```java + * .from() + * .to() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Intercom]. */ + class Builder internal constructor() { + + private var from: JsonField? = null + private var to: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(intercom: Intercom) = apply { + from = intercom.from + to = intercom.to + additionalProperties = intercom.additionalProperties.toMutableMap() + } + + fun from(from: String) = from(JsonField.of(from)) + + /** + * Sets [Builder.from] to an arbitrary JSON value. + * + * You should usually call [Builder.from] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun from(from: JsonField) = apply { this.from = from } + + fun to(to: IntercomRecipient) = to(JsonField.of(to)) + + /** + * Sets [Builder.to] to an arbitrary JSON value. + * + * You should usually call [Builder.to] with a well-typed [IntercomRecipient] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun to(to: JsonField) = apply { this.to = to } + + 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 [Intercom]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .from() + * .to() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Intercom = + Intercom( + checkRequired("from", from), + checkRequired("to", to), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Intercom = apply { + if (validated) { + return@apply + } + + from() + to().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 (from.asKnown().isPresent) 1 else 0) + (to.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Intercom && + from == other.from && + to == other.to && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(from, to, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Intercom{from=$from, to=$to, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/IntercomRecipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/IntercomRecipient.kt new file mode 100644 index 00000000..a37cccf7 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/IntercomRecipient.kt @@ -0,0 +1,167 @@ +// 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.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 + +class IntercomRecipient +@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 [IntercomRecipient]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IntercomRecipient]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(intercomRecipient: IntercomRecipient) = apply { + id = intercomRecipient.id + additionalProperties = intercomRecipient.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 [IntercomRecipient]. + * + * 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(): IntercomRecipient = + IntercomRecipient(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): IntercomRecipient = 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 IntercomRecipient && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "IntercomRecipient{id=$id, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/ListFilter.kt b/courier-java-core/src/main/kotlin/com/courier/models/ListFilter.kt new file mode 100644 index 00000000..eff3d18e --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/ListFilter.kt @@ -0,0 +1,483 @@ +// 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.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 + +class ListFilter +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val operator: JsonField, + private val path: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("operator") @ExcludeMissing operator: JsonField = JsonMissing.of(), + @JsonProperty("path") @ExcludeMissing path: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(operator, path, value, mutableMapOf()) + + /** + * Send to users only if they are member of the account + * + * @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 operator(): Operator = operator.getRequired("operator") + + /** + * @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 path(): Path = path.getRequired("path") + + /** + * @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 value(): String = value.getRequired("value") + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [path]. + * + * Unlike [path], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path + + /** + * Returns the raw JSON value of [value]. + * + * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + + @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 [ListFilter]. + * + * The following fields are required: + * ```java + * .operator() + * .path() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ListFilter]. */ + class Builder internal constructor() { + + private var operator: JsonField? = null + private var path: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(listFilter: ListFilter) = apply { + operator = listFilter.operator + path = listFilter.path + value = listFilter.value + additionalProperties = listFilter.additionalProperties.toMutableMap() + } + + /** Send to users only if they are member of the account */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + fun path(path: Path) = path(JsonField.of(path)) + + /** + * Sets [Builder.path] to an arbitrary JSON value. + * + * You should usually call [Builder.path] with a well-typed [Path] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun path(path: JsonField) = apply { this.path = path } + + fun value(value: String) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun value(value: JsonField) = apply { this.value = value } + + 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 [ListFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .operator() + * .path() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ListFilter = + ListFilter( + checkRequired("operator", operator), + checkRequired("path", path), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ListFilter = apply { + if (validated) { + return@apply + } + + operator().validate() + path().validate() + value() + 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 = + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (path.asKnown().getOrNull()?.validity() ?: 0) + + (if (value.asKnown().isPresent) 1 else 0) + + /** Send to users only if they are member of the account */ + class Operator @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 MEMBER_OF = of("MEMBER_OF") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + MEMBER_OF + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] 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 { + MEMBER_OF, + /** An enum member indicating that [Operator] 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) { + MEMBER_OF -> Value.MEMBER_OF + 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) { + MEMBER_OF -> Known.MEMBER_OF + else -> throw CourierInvalidDataException("Unknown Operator: $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(): Operator = 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Path @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 ACCOUNT_ID = of("account_id") + + @JvmStatic fun of(value: String) = Path(JsonField.of(value)) + } + + /** An enum containing [Path]'s known values. */ + enum class Known { + ACCOUNT_ID + } + + /** + * An enum containing [Path]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Path] 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 { + ACCOUNT_ID, + /** An enum member indicating that [Path] 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) { + ACCOUNT_ID -> Value.ACCOUNT_ID + 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) { + ACCOUNT_ID -> Known.ACCOUNT_ID + else -> throw CourierInvalidDataException("Unknown Path: $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(): Path = 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 Path && 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 ListFilter && + operator == other.operator && + path == other.path && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(operator, path, value, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ListFilter{operator=$operator, path=$path, value=$value, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/ListPatternRecipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/ListPatternRecipient.kt new file mode 100644 index 00000000..1feecfbb --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/ListPatternRecipient.kt @@ -0,0 +1,298 @@ +// 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 + +/** Send to users in lists matching a pattern */ +class ListPatternRecipient +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField, + private val listPattern: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("list_pattern") + @ExcludeMissing + listPattern: JsonField = JsonMissing.of(), + ) : this(data, listPattern, mutableMapOf()) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun data(): Optional = data.getOptional("data") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun listPattern(): Optional = listPattern.getOptional("list_pattern") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + /** + * Returns the raw JSON value of [listPattern]. + * + * Unlike [listPattern], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("list_pattern") + @ExcludeMissing + fun _listPattern(): JsonField = listPattern + + @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 [ListPatternRecipient]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ListPatternRecipient]. */ + class Builder internal constructor() { + + private var data: JsonField = JsonMissing.of() + private var listPattern: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(listPatternRecipient: ListPatternRecipient) = apply { + data = listPatternRecipient.data + listPattern = listPatternRecipient.listPattern + additionalProperties = listPatternRecipient.additionalProperties.toMutableMap() + } + + fun data(data: Data?) = data(JsonField.ofNullable(data)) + + /** Alias for calling [Builder.data] with `data.orElse(null)`. */ + fun data(data: Optional) = data(data.getOrNull()) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] 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 } + + fun listPattern(listPattern: String?) = listPattern(JsonField.ofNullable(listPattern)) + + /** Alias for calling [Builder.listPattern] with `listPattern.orElse(null)`. */ + fun listPattern(listPattern: Optional) = listPattern(listPattern.getOrNull()) + + /** + * Sets [Builder.listPattern] to an arbitrary JSON value. + * + * You should usually call [Builder.listPattern] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun listPattern(listPattern: JsonField) = apply { this.listPattern = listPattern } + + 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 [ListPatternRecipient]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ListPatternRecipient = + ListPatternRecipient(data, listPattern, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ListPatternRecipient = apply { + if (validated) { + return@apply + } + + data().ifPresent { it.validate() } + listPattern() + 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 = + (data.asKnown().getOrNull()?.validity() ?: 0) + + (if (listPattern.asKnown().isPresent) 1 else 0) + + class Data + @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 [Data]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + additionalProperties = data.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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Data = Data(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Data = 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 Data && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Data{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ListPatternRecipient && + data == other.data && + listPattern == other.listPattern && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(data, listPattern, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ListPatternRecipient{data=$data, listPattern=$listPattern, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/ListRecipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/ListRecipient.kt new file mode 100644 index 00000000..240e85ca --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/ListRecipient.kt @@ -0,0 +1,349 @@ +// 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.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 + +/** Send to all users in a specific list */ +class ListRecipient +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField, + private val filters: JsonField>, + private val listId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("list_id") @ExcludeMissing listId: JsonField = JsonMissing.of(), + ) : this(data, filters, listId, mutableMapOf()) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun data(): Optional = data.getOptional("data") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun filters(): Optional> = filters.getOptional("filters") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun listId(): Optional = listId.getOptional("list_id") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [listId]. + * + * Unlike [listId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("list_id") @ExcludeMissing fun _listId(): JsonField = listId + + @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 [ListRecipient]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ListRecipient]. */ + class Builder internal constructor() { + + private var data: JsonField = JsonMissing.of() + private var filters: JsonField>? = null + private var listId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(listRecipient: ListRecipient) = apply { + data = listRecipient.data + filters = listRecipient.filters.map { it.toMutableList() } + listId = listRecipient.listId + additionalProperties = listRecipient.additionalProperties.toMutableMap() + } + + fun data(data: Data?) = data(JsonField.ofNullable(data)) + + /** Alias for calling [Builder.data] with `data.orElse(null)`. */ + fun data(data: Optional) = data(data.getOrNull()) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] 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 } + + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + + /** Alias for calling [Builder.filters] with `filters.orElse(null)`. */ + fun filters(filters: Optional>) = filters(filters.getOrNull()) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [ListFilter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: ListFilter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + fun listId(listId: String?) = listId(JsonField.ofNullable(listId)) + + /** Alias for calling [Builder.listId] with `listId.orElse(null)`. */ + fun listId(listId: Optional) = listId(listId.getOrNull()) + + /** + * Sets [Builder.listId] to an arbitrary JSON value. + * + * You should usually call [Builder.listId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun listId(listId: JsonField) = apply { this.listId = listId } + + 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 [ListRecipient]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ListRecipient = + ListRecipient( + data, + (filters ?: JsonMissing.of()).map { it.toImmutable() }, + listId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ListRecipient = apply { + if (validated) { + return@apply + } + + data().ifPresent { it.validate() } + filters().ifPresent { it.forEach { it.validate() } } + listId() + 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 = + (data.asKnown().getOrNull()?.validity() ?: 0) + + (filters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (listId.asKnown().isPresent) 1 else 0) + + class Data + @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 [Data]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + additionalProperties = data.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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Data = Data(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Data = 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 Data && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Data{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ListRecipient && + data == other.data && + filters == other.filters && + listId == other.listId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(data, filters, listId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ListRecipient{data=$data, filters=$filters, listId=$listId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/MsTeams.kt b/courier-java-core/src/main/kotlin/com/courier/models/MsTeams.kt new file mode 100644 index 00000000..9ad592ab --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/MsTeams.kt @@ -0,0 +1,314 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.BaseDeserializer +import com.courier.core.BaseSerializer +import com.courier.core.JsonValue +import com.courier.core.allMaxBy +import com.courier.core.getOrThrow +import com.courier.errors.CourierInvalidDataException +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.Objects +import java.util.Optional + +@JsonDeserialize(using = MsTeams.Deserializer::class) +@JsonSerialize(using = MsTeams.Serializer::class) +class MsTeams +private constructor( + private val sendToMsTeamsUserId: SendToMsTeamsUserId? = null, + private val sendToMsTeamsEmail: SendToMsTeamsEmail? = null, + private val sendToMsTeamsChannelId: SendToMsTeamsChannelId? = null, + private val sendToMsTeamsConversationId: SendToMsTeamsConversationId? = null, + private val sendToMsTeamsChannelName: SendToMsTeamsChannelName? = null, + private val _json: JsonValue? = null, +) { + + fun sendToMsTeamsUserId(): Optional = + Optional.ofNullable(sendToMsTeamsUserId) + + fun sendToMsTeamsEmail(): Optional = Optional.ofNullable(sendToMsTeamsEmail) + + fun sendToMsTeamsChannelId(): Optional = + Optional.ofNullable(sendToMsTeamsChannelId) + + fun sendToMsTeamsConversationId(): Optional = + Optional.ofNullable(sendToMsTeamsConversationId) + + fun sendToMsTeamsChannelName(): Optional = + Optional.ofNullable(sendToMsTeamsChannelName) + + fun isSendToMsTeamsUserId(): Boolean = sendToMsTeamsUserId != null + + fun isSendToMsTeamsEmail(): Boolean = sendToMsTeamsEmail != null + + fun isSendToMsTeamsChannelId(): Boolean = sendToMsTeamsChannelId != null + + fun isSendToMsTeamsConversationId(): Boolean = sendToMsTeamsConversationId != null + + fun isSendToMsTeamsChannelName(): Boolean = sendToMsTeamsChannelName != null + + fun asSendToMsTeamsUserId(): SendToMsTeamsUserId = + sendToMsTeamsUserId.getOrThrow("sendToMsTeamsUserId") + + fun asSendToMsTeamsEmail(): SendToMsTeamsEmail = + sendToMsTeamsEmail.getOrThrow("sendToMsTeamsEmail") + + fun asSendToMsTeamsChannelId(): SendToMsTeamsChannelId = + sendToMsTeamsChannelId.getOrThrow("sendToMsTeamsChannelId") + + fun asSendToMsTeamsConversationId(): SendToMsTeamsConversationId = + sendToMsTeamsConversationId.getOrThrow("sendToMsTeamsConversationId") + + fun asSendToMsTeamsChannelName(): SendToMsTeamsChannelName = + sendToMsTeamsChannelName.getOrThrow("sendToMsTeamsChannelName") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + sendToMsTeamsUserId != null -> visitor.visitSendToMsTeamsUserId(sendToMsTeamsUserId) + sendToMsTeamsEmail != null -> visitor.visitSendToMsTeamsEmail(sendToMsTeamsEmail) + sendToMsTeamsChannelId != null -> + visitor.visitSendToMsTeamsChannelId(sendToMsTeamsChannelId) + sendToMsTeamsConversationId != null -> + visitor.visitSendToMsTeamsConversationId(sendToMsTeamsConversationId) + sendToMsTeamsChannelName != null -> + visitor.visitSendToMsTeamsChannelName(sendToMsTeamsChannelName) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): MsTeams = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSendToMsTeamsUserId(sendToMsTeamsUserId: SendToMsTeamsUserId) { + sendToMsTeamsUserId.validate() + } + + override fun visitSendToMsTeamsEmail(sendToMsTeamsEmail: SendToMsTeamsEmail) { + sendToMsTeamsEmail.validate() + } + + override fun visitSendToMsTeamsChannelId( + sendToMsTeamsChannelId: SendToMsTeamsChannelId + ) { + sendToMsTeamsChannelId.validate() + } + + override fun visitSendToMsTeamsConversationId( + sendToMsTeamsConversationId: SendToMsTeamsConversationId + ) { + sendToMsTeamsConversationId.validate() + } + + override fun visitSendToMsTeamsChannelName( + sendToMsTeamsChannelName: SendToMsTeamsChannelName + ) { + sendToMsTeamsChannelName.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 = + accept( + object : Visitor { + override fun visitSendToMsTeamsUserId(sendToMsTeamsUserId: SendToMsTeamsUserId) = + sendToMsTeamsUserId.validity() + + override fun visitSendToMsTeamsEmail(sendToMsTeamsEmail: SendToMsTeamsEmail) = + sendToMsTeamsEmail.validity() + + override fun visitSendToMsTeamsChannelId( + sendToMsTeamsChannelId: SendToMsTeamsChannelId + ) = sendToMsTeamsChannelId.validity() + + override fun visitSendToMsTeamsConversationId( + sendToMsTeamsConversationId: SendToMsTeamsConversationId + ) = sendToMsTeamsConversationId.validity() + + override fun visitSendToMsTeamsChannelName( + sendToMsTeamsChannelName: SendToMsTeamsChannelName + ) = sendToMsTeamsChannelName.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MsTeams && + sendToMsTeamsUserId == other.sendToMsTeamsUserId && + sendToMsTeamsEmail == other.sendToMsTeamsEmail && + sendToMsTeamsChannelId == other.sendToMsTeamsChannelId && + sendToMsTeamsConversationId == other.sendToMsTeamsConversationId && + sendToMsTeamsChannelName == other.sendToMsTeamsChannelName + } + + override fun hashCode(): Int = + Objects.hash( + sendToMsTeamsUserId, + sendToMsTeamsEmail, + sendToMsTeamsChannelId, + sendToMsTeamsConversationId, + sendToMsTeamsChannelName, + ) + + override fun toString(): String = + when { + sendToMsTeamsUserId != null -> "MsTeams{sendToMsTeamsUserId=$sendToMsTeamsUserId}" + sendToMsTeamsEmail != null -> "MsTeams{sendToMsTeamsEmail=$sendToMsTeamsEmail}" + sendToMsTeamsChannelId != null -> + "MsTeams{sendToMsTeamsChannelId=$sendToMsTeamsChannelId}" + sendToMsTeamsConversationId != null -> + "MsTeams{sendToMsTeamsConversationId=$sendToMsTeamsConversationId}" + sendToMsTeamsChannelName != null -> + "MsTeams{sendToMsTeamsChannelName=$sendToMsTeamsChannelName}" + _json != null -> "MsTeams{_unknown=$_json}" + else -> throw IllegalStateException("Invalid MsTeams") + } + + companion object { + + @JvmStatic + fun ofSendToMsTeamsUserId(sendToMsTeamsUserId: SendToMsTeamsUserId) = + MsTeams(sendToMsTeamsUserId = sendToMsTeamsUserId) + + @JvmStatic + fun ofSendToMsTeamsEmail(sendToMsTeamsEmail: SendToMsTeamsEmail) = + MsTeams(sendToMsTeamsEmail = sendToMsTeamsEmail) + + @JvmStatic + fun ofSendToMsTeamsChannelId(sendToMsTeamsChannelId: SendToMsTeamsChannelId) = + MsTeams(sendToMsTeamsChannelId = sendToMsTeamsChannelId) + + @JvmStatic + fun ofSendToMsTeamsConversationId( + sendToMsTeamsConversationId: SendToMsTeamsConversationId + ) = MsTeams(sendToMsTeamsConversationId = sendToMsTeamsConversationId) + + @JvmStatic + fun ofSendToMsTeamsChannelName(sendToMsTeamsChannelName: SendToMsTeamsChannelName) = + MsTeams(sendToMsTeamsChannelName = sendToMsTeamsChannelName) + } + + /** An interface that defines how to map each variant of [MsTeams] to a value of type [T]. */ + interface Visitor { + + fun visitSendToMsTeamsUserId(sendToMsTeamsUserId: SendToMsTeamsUserId): T + + fun visitSendToMsTeamsEmail(sendToMsTeamsEmail: SendToMsTeamsEmail): T + + fun visitSendToMsTeamsChannelId(sendToMsTeamsChannelId: SendToMsTeamsChannelId): T + + fun visitSendToMsTeamsConversationId( + sendToMsTeamsConversationId: SendToMsTeamsConversationId + ): T + + fun visitSendToMsTeamsChannelName(sendToMsTeamsChannelName: SendToMsTeamsChannelName): T + + /** + * Maps an unknown variant of [MsTeams] to a value of type [T]. + * + * An instance of [MsTeams] 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. + */ + fun unknown(json: JsonValue?): T { + throw CourierInvalidDataException("Unknown MsTeams: $json") + } + } + + internal class Deserializer : BaseDeserializer(MsTeams::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): MsTeams { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + MsTeams(sendToMsTeamsUserId = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + MsTeams(sendToMsTeamsEmail = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + MsTeams(sendToMsTeamsChannelId = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + MsTeams(sendToMsTeamsConversationId = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + MsTeams(sendToMsTeamsChannelName = 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 -> MsTeams(_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(MsTeams::class) { + + override fun serialize( + value: MsTeams, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.sendToMsTeamsUserId != null -> + generator.writeObject(value.sendToMsTeamsUserId) + value.sendToMsTeamsEmail != null -> generator.writeObject(value.sendToMsTeamsEmail) + value.sendToMsTeamsChannelId != null -> + generator.writeObject(value.sendToMsTeamsChannelId) + value.sendToMsTeamsConversationId != null -> + generator.writeObject(value.sendToMsTeamsConversationId) + value.sendToMsTeamsChannelName != null -> + generator.writeObject(value.sendToMsTeamsChannelName) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid MsTeams") + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/MsTeamsBaseProperties.kt b/courier-java-core/src/main/kotlin/com/courier/models/MsTeamsBaseProperties.kt new file mode 100644 index 00000000..ff1e3117 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/MsTeamsBaseProperties.kt @@ -0,0 +1,208 @@ +// 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.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 + +class MsTeamsBaseProperties +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val serviceUrl: JsonField, + private val tenantId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("service_url") + @ExcludeMissing + serviceUrl: JsonField = JsonMissing.of(), + @JsonProperty("tenant_id") @ExcludeMissing tenantId: JsonField = JsonMissing.of(), + ) : this(serviceUrl, tenantId, 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 serviceUrl(): String = serviceUrl.getRequired("service_url") + + /** + * @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 tenantId(): String = tenantId.getRequired("tenant_id") + + /** + * Returns the raw JSON value of [serviceUrl]. + * + * Unlike [serviceUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("service_url") @ExcludeMissing fun _serviceUrl(): JsonField = serviceUrl + + /** + * Returns the raw JSON value of [tenantId]. + * + * Unlike [tenantId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tenant_id") @ExcludeMissing fun _tenantId(): JsonField = tenantId + + @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 [MsTeamsBaseProperties]. + * + * The following fields are required: + * ```java + * .serviceUrl() + * .tenantId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MsTeamsBaseProperties]. */ + class Builder internal constructor() { + + private var serviceUrl: JsonField? = null + private var tenantId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(msTeamsBaseProperties: MsTeamsBaseProperties) = apply { + serviceUrl = msTeamsBaseProperties.serviceUrl + tenantId = msTeamsBaseProperties.tenantId + additionalProperties = msTeamsBaseProperties.additionalProperties.toMutableMap() + } + + fun serviceUrl(serviceUrl: String) = serviceUrl(JsonField.of(serviceUrl)) + + /** + * Sets [Builder.serviceUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.serviceUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun serviceUrl(serviceUrl: JsonField) = apply { this.serviceUrl = serviceUrl } + + fun tenantId(tenantId: String) = tenantId(JsonField.of(tenantId)) + + /** + * Sets [Builder.tenantId] to an arbitrary JSON value. + * + * You should usually call [Builder.tenantId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tenantId(tenantId: JsonField) = apply { this.tenantId = tenantId } + + 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 [MsTeamsBaseProperties]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .serviceUrl() + * .tenantId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MsTeamsBaseProperties = + MsTeamsBaseProperties( + checkRequired("serviceUrl", serviceUrl), + checkRequired("tenantId", tenantId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MsTeamsBaseProperties = apply { + if (validated) { + return@apply + } + + serviceUrl() + tenantId() + 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 (serviceUrl.asKnown().isPresent) 1 else 0) + + (if (tenantId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MsTeamsBaseProperties && + serviceUrl == other.serviceUrl && + tenantId == other.tenantId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(serviceUrl, tenantId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MsTeamsBaseProperties{serviceUrl=$serviceUrl, tenantId=$tenantId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/MsTeamsRecipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/MsTeamsRecipient.kt new file mode 100644 index 00000000..d48bee43 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/MsTeamsRecipient.kt @@ -0,0 +1,200 @@ +// 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.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 + +/** Send via Microsoft Teams */ +class MsTeamsRecipient +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val msTeams: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("ms_teams") @ExcludeMissing msTeams: JsonField = JsonMissing.of() + ) : this(msTeams, 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 msTeams(): MsTeams = msTeams.getRequired("ms_teams") + + /** + * Returns the raw JSON value of [msTeams]. + * + * Unlike [msTeams], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("ms_teams") @ExcludeMissing fun _msTeams(): JsonField = msTeams + + @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 [MsTeamsRecipient]. + * + * The following fields are required: + * ```java + * .msTeams() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MsTeamsRecipient]. */ + class Builder internal constructor() { + + private var msTeams: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(msTeamsRecipient: MsTeamsRecipient) = apply { + msTeams = msTeamsRecipient.msTeams + additionalProperties = msTeamsRecipient.additionalProperties.toMutableMap() + } + + fun msTeams(msTeams: MsTeams) = msTeams(JsonField.of(msTeams)) + + /** + * Sets [Builder.msTeams] to an arbitrary JSON value. + * + * You should usually call [Builder.msTeams] with a well-typed [MsTeams] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun msTeams(msTeams: JsonField) = apply { this.msTeams = msTeams } + + /** + * Alias for calling [msTeams] with `MsTeams.ofSendToMsTeamsUserId(sendToMsTeamsUserId)`. + */ + fun msTeams(sendToMsTeamsUserId: SendToMsTeamsUserId) = + msTeams(MsTeams.ofSendToMsTeamsUserId(sendToMsTeamsUserId)) + + /** Alias for calling [msTeams] with `MsTeams.ofSendToMsTeamsEmail(sendToMsTeamsEmail)`. */ + fun msTeams(sendToMsTeamsEmail: SendToMsTeamsEmail) = + msTeams(MsTeams.ofSendToMsTeamsEmail(sendToMsTeamsEmail)) + + /** + * Alias for calling [msTeams] with + * `MsTeams.ofSendToMsTeamsChannelId(sendToMsTeamsChannelId)`. + */ + fun msTeams(sendToMsTeamsChannelId: SendToMsTeamsChannelId) = + msTeams(MsTeams.ofSendToMsTeamsChannelId(sendToMsTeamsChannelId)) + + /** + * Alias for calling [msTeams] with + * `MsTeams.ofSendToMsTeamsConversationId(sendToMsTeamsConversationId)`. + */ + fun msTeams(sendToMsTeamsConversationId: SendToMsTeamsConversationId) = + msTeams(MsTeams.ofSendToMsTeamsConversationId(sendToMsTeamsConversationId)) + + /** + * Alias for calling [msTeams] with + * `MsTeams.ofSendToMsTeamsChannelName(sendToMsTeamsChannelName)`. + */ + fun msTeams(sendToMsTeamsChannelName: SendToMsTeamsChannelName) = + msTeams(MsTeams.ofSendToMsTeamsChannelName(sendToMsTeamsChannelName)) + + 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 [MsTeamsRecipient]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .msTeams() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MsTeamsRecipient = + MsTeamsRecipient(checkRequired("msTeams", msTeams), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): MsTeamsRecipient = apply { + if (validated) { + return@apply + } + + msTeams().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 = (msTeams.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MsTeamsRecipient && + msTeams == other.msTeams && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(msTeams, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MsTeamsRecipient{msTeams=$msTeams, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/MultipleTokens.kt b/courier-java-core/src/main/kotlin/com/courier/models/MultipleTokens.kt new file mode 100644 index 00000000..d5627aff --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/MultipleTokens.kt @@ -0,0 +1,190 @@ +// 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.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class MultipleTokens +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val tokens: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("tokens") @ExcludeMissing tokens: JsonField> = JsonMissing.of() + ) : this(tokens, 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 tokens(): List = tokens.getRequired("tokens") + + /** + * Returns the raw JSON value of [tokens]. + * + * Unlike [tokens], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tokens") @ExcludeMissing fun _tokens(): JsonField> = tokens + + @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 [MultipleTokens]. + * + * The following fields are required: + * ```java + * .tokens() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MultipleTokens]. */ + class Builder internal constructor() { + + private var tokens: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(multipleTokens: MultipleTokens) = apply { + tokens = multipleTokens.tokens.map { it.toMutableList() } + additionalProperties = multipleTokens.additionalProperties.toMutableMap() + } + + fun tokens(tokens: List) = tokens(JsonField.of(tokens)) + + /** + * Sets [Builder.tokens] to an arbitrary JSON value. + * + * You should usually call [Builder.tokens] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tokens(tokens: JsonField>) = apply { + this.tokens = tokens.map { it.toMutableList() } + } + + /** + * Adds a single [Token] to [tokens]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addToken(token: Token) = apply { + tokens = + (tokens ?: JsonField.of(mutableListOf())).also { + checkKnown("tokens", it).add(token) + } + } + + 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 [MultipleTokens]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .tokens() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MultipleTokens = + MultipleTokens( + checkRequired("tokens", tokens).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MultipleTokens = apply { + if (validated) { + return@apply + } + + tokens().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 = + (tokens.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MultipleTokens && + tokens == other.tokens && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tokens, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MultipleTokens{tokens=$tokens, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Pagerduty.kt b/courier-java-core/src/main/kotlin/com/courier/models/Pagerduty.kt new file mode 100644 index 00000000..acedab0e --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Pagerduty.kt @@ -0,0 +1,274 @@ +// 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 Pagerduty +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val eventAction: JsonField, + private val routingKey: JsonField, + private val severity: JsonField, + private val source: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("event_action") + @ExcludeMissing + eventAction: JsonField = JsonMissing.of(), + @JsonProperty("routing_key") + @ExcludeMissing + routingKey: JsonField = JsonMissing.of(), + @JsonProperty("severity") @ExcludeMissing severity: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + ) : this(eventAction, routingKey, severity, source, mutableMapOf()) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun eventAction(): Optional = eventAction.getOptional("event_action") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun routingKey(): Optional = routingKey.getOptional("routing_key") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun severity(): Optional = severity.getOptional("severity") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun source(): Optional = source.getOptional("source") + + /** + * Returns the raw JSON value of [eventAction]. + * + * Unlike [eventAction], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("event_action") + @ExcludeMissing + fun _eventAction(): JsonField = eventAction + + /** + * Returns the raw JSON value of [routingKey]. + * + * Unlike [routingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("routing_key") @ExcludeMissing fun _routingKey(): JsonField = routingKey + + /** + * Returns the raw JSON value of [severity]. + * + * Unlike [severity], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("severity") @ExcludeMissing fun _severity(): JsonField = severity + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + @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 [Pagerduty]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Pagerduty]. */ + class Builder internal constructor() { + + private var eventAction: JsonField = JsonMissing.of() + private var routingKey: JsonField = JsonMissing.of() + private var severity: JsonField = JsonMissing.of() + private var source: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(pagerduty: Pagerduty) = apply { + eventAction = pagerduty.eventAction + routingKey = pagerduty.routingKey + severity = pagerduty.severity + source = pagerduty.source + additionalProperties = pagerduty.additionalProperties.toMutableMap() + } + + fun eventAction(eventAction: String?) = eventAction(JsonField.ofNullable(eventAction)) + + /** Alias for calling [Builder.eventAction] with `eventAction.orElse(null)`. */ + fun eventAction(eventAction: Optional) = eventAction(eventAction.getOrNull()) + + /** + * Sets [Builder.eventAction] to an arbitrary JSON value. + * + * You should usually call [Builder.eventAction] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun eventAction(eventAction: JsonField) = apply { this.eventAction = eventAction } + + fun routingKey(routingKey: String?) = routingKey(JsonField.ofNullable(routingKey)) + + /** Alias for calling [Builder.routingKey] with `routingKey.orElse(null)`. */ + fun routingKey(routingKey: Optional) = routingKey(routingKey.getOrNull()) + + /** + * Sets [Builder.routingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.routingKey] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun routingKey(routingKey: JsonField) = apply { this.routingKey = routingKey } + + fun severity(severity: String?) = severity(JsonField.ofNullable(severity)) + + /** Alias for calling [Builder.severity] with `severity.orElse(null)`. */ + fun severity(severity: Optional) = severity(severity.getOrNull()) + + /** + * Sets [Builder.severity] to an arbitrary JSON value. + * + * You should usually call [Builder.severity] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun severity(severity: JsonField) = apply { this.severity = severity } + + fun source(source: String?) = source(JsonField.ofNullable(source)) + + /** Alias for calling [Builder.source] with `source.orElse(null)`. */ + fun source(source: Optional) = source(source.getOrNull()) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + 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 [Pagerduty]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Pagerduty = + Pagerduty( + eventAction, + routingKey, + severity, + source, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Pagerduty = apply { + if (validated) { + return@apply + } + + eventAction() + routingKey() + severity() + source() + 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 (eventAction.asKnown().isPresent) 1 else 0) + + (if (routingKey.asKnown().isPresent) 1 else 0) + + (if (severity.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Pagerduty && + eventAction == other.eventAction && + routingKey == other.routingKey && + severity == other.severity && + source == other.source && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(eventAction, routingKey, severity, source, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Pagerduty{eventAction=$eventAction, routingKey=$routingKey, severity=$severity, source=$source, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/PagerdutyRecipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/PagerdutyRecipient.kt new file mode 100644 index 00000000..c4060b51 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/PagerdutyRecipient.kt @@ -0,0 +1,175 @@ +// 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.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 + +/** Send via PagerDuty */ +class PagerdutyRecipient +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val pagerduty: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("pagerduty") + @ExcludeMissing + pagerduty: JsonField = JsonMissing.of() + ) : this(pagerduty, 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 pagerduty(): Pagerduty = pagerduty.getRequired("pagerduty") + + /** + * Returns the raw JSON value of [pagerduty]. + * + * Unlike [pagerduty], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("pagerduty") @ExcludeMissing fun _pagerduty(): JsonField = pagerduty + + @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 [PagerdutyRecipient]. + * + * The following fields are required: + * ```java + * .pagerduty() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PagerdutyRecipient]. */ + class Builder internal constructor() { + + private var pagerduty: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(pagerdutyRecipient: PagerdutyRecipient) = apply { + pagerduty = pagerdutyRecipient.pagerduty + additionalProperties = pagerdutyRecipient.additionalProperties.toMutableMap() + } + + fun pagerduty(pagerduty: Pagerduty) = pagerduty(JsonField.of(pagerduty)) + + /** + * Sets [Builder.pagerduty] to an arbitrary JSON value. + * + * You should usually call [Builder.pagerduty] with a well-typed [Pagerduty] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun pagerduty(pagerduty: JsonField) = apply { this.pagerduty = pagerduty } + + 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 [PagerdutyRecipient]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .pagerduty() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PagerdutyRecipient = + PagerdutyRecipient( + checkRequired("pagerduty", pagerduty), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PagerdutyRecipient = apply { + if (validated) { + return@apply + } + + pagerduty().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 = (pagerduty.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PagerdutyRecipient && + pagerduty == other.pagerduty && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(pagerduty, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PagerdutyRecipient{pagerduty=$pagerduty, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Recipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/Recipient.kt deleted file mode 100644 index c3e268d4..00000000 --- a/courier-java-core/src/main/kotlin/com/courier/models/Recipient.kt +++ /dev/null @@ -1,1091 +0,0 @@ -// 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.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 - -class Recipient -@JsonCreator(mode = JsonCreator.Mode.DISABLED) -private constructor( - private val accountId: JsonField, - private val context: JsonField, - private val data: JsonField, - private val email: JsonField, - private val listId: JsonField, - private val locale: JsonField, - private val phoneNumber: JsonField, - private val preferences: JsonField, - private val tenantId: JsonField, - private val userId: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("account_id") @ExcludeMissing accountId: JsonField = JsonMissing.of(), - @JsonProperty("context") - @ExcludeMissing - context: JsonField = JsonMissing.of(), - @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), - @JsonProperty("email") @ExcludeMissing email: JsonField = JsonMissing.of(), - @JsonProperty("list_id") @ExcludeMissing listId: JsonField = JsonMissing.of(), - @JsonProperty("locale") @ExcludeMissing locale: JsonField = JsonMissing.of(), - @JsonProperty("phone_number") - @ExcludeMissing - phoneNumber: JsonField = JsonMissing.of(), - @JsonProperty("preferences") - @ExcludeMissing - preferences: JsonField = JsonMissing.of(), - @JsonProperty("tenant_id") @ExcludeMissing tenantId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), - ) : this( - accountId, - context, - data, - email, - listId, - locale, - phoneNumber, - preferences, - tenantId, - userId, - mutableMapOf(), - ) - - /** - * Deprecated - Use `tenant_id` instead. - * - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun accountId(): Optional = accountId.getOptional("account_id") - - /** - * Context such as tenant_id to send the notification with. - * - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun context(): Optional = context.getOptional("context") - - /** - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun data(): Optional = data.getOptional("data") - - /** - * The user's email address. - * - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun email(): Optional = email.getOptional("email") - - /** - * The id of the list to send the message to. - * - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun listId(): Optional = listId.getOptional("list_id") - - /** - * The user's preferred ISO 639-1 language code. - * - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun locale(): Optional = locale.getOptional("locale") - - /** - * The user's phone number. - * - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun phoneNumber(): Optional = phoneNumber.getOptional("phone_number") - - /** - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun preferences(): Optional = preferences.getOptional("preferences") - - /** - * The id of the tenant the user is associated with. - * - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun tenantId(): Optional = tenantId.getOptional("tenant_id") - - /** - * The user's unique identifier. Typically, this will match the user id of a user in your - * system. - * - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun userId(): Optional = userId.getOptional("user_id") - - /** - * Returns the raw JSON value of [accountId]. - * - * Unlike [accountId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("account_id") @ExcludeMissing fun _accountId(): JsonField = accountId - - /** - * Returns the raw JSON value of [context]. - * - * Unlike [context], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("context") @ExcludeMissing fun _context(): JsonField = context - - /** - * Returns the raw JSON value of [data]. - * - * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data - - /** - * Returns the raw JSON value of [email]. - * - * Unlike [email], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("email") @ExcludeMissing fun _email(): JsonField = email - - /** - * Returns the raw JSON value of [listId]. - * - * Unlike [listId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("list_id") @ExcludeMissing fun _listId(): JsonField = listId - - /** - * Returns the raw JSON value of [locale]. - * - * Unlike [locale], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("locale") @ExcludeMissing fun _locale(): JsonField = locale - - /** - * Returns the raw JSON value of [phoneNumber]. - * - * Unlike [phoneNumber], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("phone_number") - @ExcludeMissing - fun _phoneNumber(): JsonField = phoneNumber - - /** - * Returns the raw JSON value of [preferences]. - * - * Unlike [preferences], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("preferences") - @ExcludeMissing - fun _preferences(): JsonField = preferences - - /** - * Returns the raw JSON value of [tenantId]. - * - * Unlike [tenantId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("tenant_id") @ExcludeMissing fun _tenantId(): JsonField = tenantId - - /** - * Returns the raw JSON value of [userId]. - * - * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId - - @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 [Recipient]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Recipient]. */ - class Builder internal constructor() { - - private var accountId: JsonField = JsonMissing.of() - private var context: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() - private var email: JsonField = JsonMissing.of() - private var listId: JsonField = JsonMissing.of() - private var locale: JsonField = JsonMissing.of() - private var phoneNumber: JsonField = JsonMissing.of() - private var preferences: JsonField = JsonMissing.of() - private var tenantId: JsonField = JsonMissing.of() - private var userId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(recipient: Recipient) = apply { - accountId = recipient.accountId - context = recipient.context - data = recipient.data - email = recipient.email - listId = recipient.listId - locale = recipient.locale - phoneNumber = recipient.phoneNumber - preferences = recipient.preferences - tenantId = recipient.tenantId - userId = recipient.userId - additionalProperties = recipient.additionalProperties.toMutableMap() - } - - /** Deprecated - Use `tenant_id` instead. */ - fun accountId(accountId: String?) = accountId(JsonField.ofNullable(accountId)) - - /** Alias for calling [Builder.accountId] with `accountId.orElse(null)`. */ - fun accountId(accountId: Optional) = accountId(accountId.getOrNull()) - - /** - * Sets [Builder.accountId] to an arbitrary JSON value. - * - * You should usually call [Builder.accountId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun accountId(accountId: JsonField) = apply { this.accountId = accountId } - - /** Context such as tenant_id to send the notification with. */ - fun context(context: MessageContext?) = context(JsonField.ofNullable(context)) - - /** Alias for calling [Builder.context] with `context.orElse(null)`. */ - fun context(context: Optional) = context(context.getOrNull()) - - /** - * Sets [Builder.context] to an arbitrary JSON value. - * - * You should usually call [Builder.context] with a well-typed [MessageContext] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun context(context: JsonField) = apply { this.context = context } - - fun data(data: Data?) = data(JsonField.ofNullable(data)) - - /** Alias for calling [Builder.data] with `data.orElse(null)`. */ - fun data(data: Optional) = data(data.getOrNull()) - - /** - * Sets [Builder.data] to an arbitrary JSON value. - * - * You should usually call [Builder.data] with a well-typed [Data] 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 } - - /** The user's email address. */ - fun email(email: String?) = email(JsonField.ofNullable(email)) - - /** Alias for calling [Builder.email] with `email.orElse(null)`. */ - fun email(email: Optional) = email(email.getOrNull()) - - /** - * Sets [Builder.email] to an arbitrary JSON value. - * - * You should usually call [Builder.email] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun email(email: JsonField) = apply { this.email = email } - - /** The id of the list to send the message to. */ - fun listId(listId: String?) = listId(JsonField.ofNullable(listId)) - - /** Alias for calling [Builder.listId] with `listId.orElse(null)`. */ - fun listId(listId: Optional) = listId(listId.getOrNull()) - - /** - * Sets [Builder.listId] to an arbitrary JSON value. - * - * You should usually call [Builder.listId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun listId(listId: JsonField) = apply { this.listId = listId } - - /** The user's preferred ISO 639-1 language code. */ - fun locale(locale: String?) = locale(JsonField.ofNullable(locale)) - - /** Alias for calling [Builder.locale] with `locale.orElse(null)`. */ - fun locale(locale: Optional) = locale(locale.getOrNull()) - - /** - * Sets [Builder.locale] to an arbitrary JSON value. - * - * You should usually call [Builder.locale] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun locale(locale: JsonField) = apply { this.locale = locale } - - /** The user's phone number. */ - fun phoneNumber(phoneNumber: String?) = phoneNumber(JsonField.ofNullable(phoneNumber)) - - /** Alias for calling [Builder.phoneNumber] with `phoneNumber.orElse(null)`. */ - fun phoneNumber(phoneNumber: Optional) = phoneNumber(phoneNumber.getOrNull()) - - /** - * Sets [Builder.phoneNumber] to an arbitrary JSON value. - * - * You should usually call [Builder.phoneNumber] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun phoneNumber(phoneNumber: JsonField) = apply { this.phoneNumber = phoneNumber } - - fun preferences(preferences: Preferences?) = preferences(JsonField.ofNullable(preferences)) - - /** Alias for calling [Builder.preferences] with `preferences.orElse(null)`. */ - fun preferences(preferences: Optional) = preferences(preferences.getOrNull()) - - /** - * Sets [Builder.preferences] to an arbitrary JSON value. - * - * You should usually call [Builder.preferences] with a well-typed [Preferences] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun preferences(preferences: JsonField) = apply { - this.preferences = preferences - } - - /** The id of the tenant the user is associated with. */ - fun tenantId(tenantId: String?) = tenantId(JsonField.ofNullable(tenantId)) - - /** Alias for calling [Builder.tenantId] with `tenantId.orElse(null)`. */ - fun tenantId(tenantId: Optional) = tenantId(tenantId.getOrNull()) - - /** - * Sets [Builder.tenantId] to an arbitrary JSON value. - * - * You should usually call [Builder.tenantId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun tenantId(tenantId: JsonField) = apply { this.tenantId = tenantId } - - /** - * The user's unique identifier. Typically, this will match the user id of a user in your - * system. - */ - fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) - - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) - - /** - * Sets [Builder.userId] to an arbitrary JSON value. - * - * You should usually call [Builder.userId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun userId(userId: JsonField) = apply { this.userId = userId } - - 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 [Recipient]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Recipient = - Recipient( - accountId, - context, - data, - email, - listId, - locale, - phoneNumber, - preferences, - tenantId, - userId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Recipient = apply { - if (validated) { - return@apply - } - - accountId() - context().ifPresent { it.validate() } - data().ifPresent { it.validate() } - email() - listId() - locale() - phoneNumber() - preferences().ifPresent { it.validate() } - tenantId() - userId() - 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 (accountId.asKnown().isPresent) 1 else 0) + - (context.asKnown().getOrNull()?.validity() ?: 0) + - (data.asKnown().getOrNull()?.validity() ?: 0) + - (if (email.asKnown().isPresent) 1 else 0) + - (if (listId.asKnown().isPresent) 1 else 0) + - (if (locale.asKnown().isPresent) 1 else 0) + - (if (phoneNumber.asKnown().isPresent) 1 else 0) + - (preferences.asKnown().getOrNull()?.validity() ?: 0) + - (if (tenantId.asKnown().isPresent) 1 else 0) + - (if (userId.asKnown().isPresent) 1 else 0) - - class Data - @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 [Data]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Data]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(data: Data) = apply { - additionalProperties = data.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 [Data]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Data = Data(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Data = 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 Data && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Data{additionalProperties=$additionalProperties}" - } - - class Preferences - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val notifications: JsonField, - private val categories: JsonField, - private val templateId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("notifications") - @ExcludeMissing - notifications: JsonField = JsonMissing.of(), - @JsonProperty("categories") - @ExcludeMissing - categories: JsonField = JsonMissing.of(), - @JsonProperty("templateId") - @ExcludeMissing - templateId: JsonField = JsonMissing.of(), - ) : this(notifications, categories, templateId, 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 notifications(): Notifications = notifications.getRequired("notifications") - - /** - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun categories(): Optional = categories.getOptional("categories") - - /** - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun templateId(): Optional = templateId.getOptional("templateId") - - /** - * Returns the raw JSON value of [notifications]. - * - * Unlike [notifications], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("notifications") - @ExcludeMissing - fun _notifications(): JsonField = notifications - - /** - * Returns the raw JSON value of [categories]. - * - * Unlike [categories], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("categories") - @ExcludeMissing - fun _categories(): JsonField = categories - - /** - * Returns the raw JSON value of [templateId]. - * - * Unlike [templateId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("templateId") - @ExcludeMissing - fun _templateId(): JsonField = templateId - - @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 [Preferences]. - * - * The following fields are required: - * ```java - * .notifications() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Preferences]. */ - class Builder internal constructor() { - - private var notifications: JsonField? = null - private var categories: JsonField = JsonMissing.of() - private var templateId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(preferences: Preferences) = apply { - notifications = preferences.notifications - categories = preferences.categories - templateId = preferences.templateId - additionalProperties = preferences.additionalProperties.toMutableMap() - } - - fun notifications(notifications: Notifications) = - notifications(JsonField.of(notifications)) - - /** - * Sets [Builder.notifications] to an arbitrary JSON value. - * - * You should usually call [Builder.notifications] with a well-typed [Notifications] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun notifications(notifications: JsonField) = apply { - this.notifications = notifications - } - - fun categories(categories: Categories?) = categories(JsonField.ofNullable(categories)) - - /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ - fun categories(categories: Optional) = categories(categories.getOrNull()) - - /** - * Sets [Builder.categories] to an arbitrary JSON value. - * - * You should usually call [Builder.categories] with a well-typed [Categories] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun categories(categories: JsonField) = apply { - this.categories = categories - } - - fun templateId(templateId: String?) = templateId(JsonField.ofNullable(templateId)) - - /** Alias for calling [Builder.templateId] with `templateId.orElse(null)`. */ - fun templateId(templateId: Optional) = templateId(templateId.getOrNull()) - - /** - * Sets [Builder.templateId] to an arbitrary JSON value. - * - * You should usually call [Builder.templateId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun templateId(templateId: JsonField) = apply { this.templateId = templateId } - - 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 [Preferences]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .notifications() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Preferences = - Preferences( - checkRequired("notifications", notifications), - categories, - templateId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Preferences = apply { - if (validated) { - return@apply - } - - notifications().validate() - categories().ifPresent { it.validate() } - templateId() - 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 = - (notifications.asKnown().getOrNull()?.validity() ?: 0) + - (categories.asKnown().getOrNull()?.validity() ?: 0) + - (if (templateId.asKnown().isPresent) 1 else 0) - - class Notifications - @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 [Notifications]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Notifications]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(notifications: Notifications) = apply { - additionalProperties = notifications.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 [Notifications]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Notifications = Notifications(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Notifications = 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 Notifications && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Notifications{additionalProperties=$additionalProperties}" - } - - class Categories - @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 [Categories]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Categories]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(categories: Categories) = apply { - additionalProperties = categories.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 [Categories]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Categories = Categories(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Categories = 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 Categories && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "Categories{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Preferences && - notifications == other.notifications && - categories == other.categories && - templateId == other.templateId && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(notifications, categories, templateId, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Preferences{notifications=$notifications, categories=$categories, templateId=$templateId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Recipient && - accountId == other.accountId && - context == other.context && - data == other.data && - email == other.email && - listId == other.listId && - locale == other.locale && - phoneNumber == other.phoneNumber && - preferences == other.preferences && - tenantId == other.tenantId && - userId == other.userId && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash( - accountId, - context, - data, - email, - listId, - locale, - phoneNumber, - preferences, - tenantId, - userId, - additionalProperties, - ) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Recipient{accountId=$accountId, context=$context, data=$data, email=$email, listId=$listId, locale=$locale, phoneNumber=$phoneNumber, preferences=$preferences, tenantId=$tenantId, userId=$userId, additionalProperties=$additionalProperties}" -} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendDirectMessage.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendDirectMessage.kt new file mode 100644 index 00000000..2fa7a39c --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendDirectMessage.kt @@ -0,0 +1,167 @@ +// 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.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 + +class SendDirectMessage +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val userId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of() + ) : this(userId, 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 userId(): String = userId.getRequired("user_id") + + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + @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 [SendDirectMessage]. + * + * The following fields are required: + * ```java + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendDirectMessage]. */ + class Builder internal constructor() { + + private var userId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendDirectMessage: SendDirectMessage) = apply { + userId = sendDirectMessage.userId + additionalProperties = sendDirectMessage.additionalProperties.toMutableMap() + } + + fun userId(userId: String) = userId(JsonField.of(userId)) + + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } + + 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 [SendDirectMessage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendDirectMessage = + SendDirectMessage(checkRequired("userId", userId), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): SendDirectMessage = apply { + if (validated) { + return@apply + } + + userId() + 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 (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendDirectMessage && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(userId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendDirectMessage{userId=$userId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToChannel.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToChannel.kt new file mode 100644 index 00000000..360010e2 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToChannel.kt @@ -0,0 +1,171 @@ +// 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.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 + +class SendToChannel +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val channelId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("channel_id") @ExcludeMissing channelId: JsonField = JsonMissing.of() + ) : this(channelId, 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 channelId(): String = channelId.getRequired("channel_id") + + /** + * Returns the raw JSON value of [channelId]. + * + * Unlike [channelId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channel_id") @ExcludeMissing fun _channelId(): JsonField = channelId + + @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 [SendToChannel]. + * + * The following fields are required: + * ```java + * .channelId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToChannel]. */ + class Builder internal constructor() { + + private var channelId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToChannel: SendToChannel) = apply { + channelId = sendToChannel.channelId + additionalProperties = sendToChannel.additionalProperties.toMutableMap() + } + + fun channelId(channelId: String) = channelId(JsonField.of(channelId)) + + /** + * Sets [Builder.channelId] to an arbitrary JSON value. + * + * You should usually call [Builder.channelId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun channelId(channelId: JsonField) = apply { this.channelId = channelId } + + 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 [SendToChannel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .channelId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToChannel = + SendToChannel( + checkRequired("channelId", channelId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToChannel = apply { + if (validated) { + return@apply + } + + channelId() + 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 (channelId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToChannel && + channelId == other.channelId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(channelId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToChannel{channelId=$channelId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsChannelId.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsChannelId.kt new file mode 100644 index 00000000..867e2bf2 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsChannelId.kt @@ -0,0 +1,244 @@ +// 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.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 + +class SendToMsTeamsChannelId +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val channelId: JsonField, + private val serviceUrl: JsonField, + private val tenantId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("channel_id") @ExcludeMissing channelId: JsonField = JsonMissing.of(), + @JsonProperty("service_url") + @ExcludeMissing + serviceUrl: JsonField = JsonMissing.of(), + @JsonProperty("tenant_id") @ExcludeMissing tenantId: JsonField = JsonMissing.of(), + ) : this(channelId, serviceUrl, tenantId, 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 channelId(): String = channelId.getRequired("channel_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 serviceUrl(): String = serviceUrl.getRequired("service_url") + + /** + * @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 tenantId(): String = tenantId.getRequired("tenant_id") + + /** + * Returns the raw JSON value of [channelId]. + * + * Unlike [channelId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channel_id") @ExcludeMissing fun _channelId(): JsonField = channelId + + /** + * Returns the raw JSON value of [serviceUrl]. + * + * Unlike [serviceUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("service_url") @ExcludeMissing fun _serviceUrl(): JsonField = serviceUrl + + /** + * Returns the raw JSON value of [tenantId]. + * + * Unlike [tenantId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tenant_id") @ExcludeMissing fun _tenantId(): JsonField = tenantId + + @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 [SendToMsTeamsChannelId]. + * + * The following fields are required: + * ```java + * .channelId() + * .serviceUrl() + * .tenantId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToMsTeamsChannelId]. */ + class Builder internal constructor() { + + private var channelId: JsonField? = null + private var serviceUrl: JsonField? = null + private var tenantId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToMsTeamsChannelId: SendToMsTeamsChannelId) = apply { + channelId = sendToMsTeamsChannelId.channelId + serviceUrl = sendToMsTeamsChannelId.serviceUrl + tenantId = sendToMsTeamsChannelId.tenantId + additionalProperties = sendToMsTeamsChannelId.additionalProperties.toMutableMap() + } + + fun channelId(channelId: String) = channelId(JsonField.of(channelId)) + + /** + * Sets [Builder.channelId] to an arbitrary JSON value. + * + * You should usually call [Builder.channelId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun channelId(channelId: JsonField) = apply { this.channelId = channelId } + + fun serviceUrl(serviceUrl: String) = serviceUrl(JsonField.of(serviceUrl)) + + /** + * Sets [Builder.serviceUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.serviceUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun serviceUrl(serviceUrl: JsonField) = apply { this.serviceUrl = serviceUrl } + + fun tenantId(tenantId: String) = tenantId(JsonField.of(tenantId)) + + /** + * Sets [Builder.tenantId] to an arbitrary JSON value. + * + * You should usually call [Builder.tenantId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tenantId(tenantId: JsonField) = apply { this.tenantId = tenantId } + + 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 [SendToMsTeamsChannelId]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .channelId() + * .serviceUrl() + * .tenantId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToMsTeamsChannelId = + SendToMsTeamsChannelId( + checkRequired("channelId", channelId), + checkRequired("serviceUrl", serviceUrl), + checkRequired("tenantId", tenantId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToMsTeamsChannelId = apply { + if (validated) { + return@apply + } + + channelId() + serviceUrl() + tenantId() + 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 (channelId.asKnown().isPresent) 1 else 0) + + (if (serviceUrl.asKnown().isPresent) 1 else 0) + + (if (tenantId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToMsTeamsChannelId && + channelId == other.channelId && + serviceUrl == other.serviceUrl && + tenantId == other.tenantId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(channelId, serviceUrl, tenantId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToMsTeamsChannelId{channelId=$channelId, serviceUrl=$serviceUrl, tenantId=$tenantId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsChannelName.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsChannelName.kt new file mode 100644 index 00000000..9fed8864 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsChannelName.kt @@ -0,0 +1,281 @@ +// 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.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 + +class SendToMsTeamsChannelName +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val channelName: JsonField, + private val serviceUrl: JsonField, + private val teamId: JsonField, + private val tenantId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("channel_name") + @ExcludeMissing + channelName: JsonField = JsonMissing.of(), + @JsonProperty("service_url") + @ExcludeMissing + serviceUrl: JsonField = JsonMissing.of(), + @JsonProperty("team_id") @ExcludeMissing teamId: JsonField = JsonMissing.of(), + @JsonProperty("tenant_id") @ExcludeMissing tenantId: JsonField = JsonMissing.of(), + ) : this(channelName, serviceUrl, teamId, tenantId, 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 channelName(): String = channelName.getRequired("channel_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 serviceUrl(): String = serviceUrl.getRequired("service_url") + + /** + * @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 teamId(): String = teamId.getRequired("team_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 tenantId(): String = tenantId.getRequired("tenant_id") + + /** + * Returns the raw JSON value of [channelName]. + * + * Unlike [channelName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channel_name") + @ExcludeMissing + fun _channelName(): JsonField = channelName + + /** + * Returns the raw JSON value of [serviceUrl]. + * + * Unlike [serviceUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("service_url") @ExcludeMissing fun _serviceUrl(): JsonField = serviceUrl + + /** + * Returns the raw JSON value of [teamId]. + * + * Unlike [teamId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("team_id") @ExcludeMissing fun _teamId(): JsonField = teamId + + /** + * Returns the raw JSON value of [tenantId]. + * + * Unlike [tenantId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tenant_id") @ExcludeMissing fun _tenantId(): JsonField = tenantId + + @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 [SendToMsTeamsChannelName]. + * + * The following fields are required: + * ```java + * .channelName() + * .serviceUrl() + * .teamId() + * .tenantId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToMsTeamsChannelName]. */ + class Builder internal constructor() { + + private var channelName: JsonField? = null + private var serviceUrl: JsonField? = null + private var teamId: JsonField? = null + private var tenantId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToMsTeamsChannelName: SendToMsTeamsChannelName) = apply { + channelName = sendToMsTeamsChannelName.channelName + serviceUrl = sendToMsTeamsChannelName.serviceUrl + teamId = sendToMsTeamsChannelName.teamId + tenantId = sendToMsTeamsChannelName.tenantId + additionalProperties = sendToMsTeamsChannelName.additionalProperties.toMutableMap() + } + + fun channelName(channelName: String) = channelName(JsonField.of(channelName)) + + /** + * Sets [Builder.channelName] to an arbitrary JSON value. + * + * You should usually call [Builder.channelName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun channelName(channelName: JsonField) = apply { this.channelName = channelName } + + fun serviceUrl(serviceUrl: String) = serviceUrl(JsonField.of(serviceUrl)) + + /** + * Sets [Builder.serviceUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.serviceUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun serviceUrl(serviceUrl: JsonField) = apply { this.serviceUrl = serviceUrl } + + fun teamId(teamId: String) = teamId(JsonField.of(teamId)) + + /** + * Sets [Builder.teamId] to an arbitrary JSON value. + * + * You should usually call [Builder.teamId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun teamId(teamId: JsonField) = apply { this.teamId = teamId } + + fun tenantId(tenantId: String) = tenantId(JsonField.of(tenantId)) + + /** + * Sets [Builder.tenantId] to an arbitrary JSON value. + * + * You should usually call [Builder.tenantId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tenantId(tenantId: JsonField) = apply { this.tenantId = tenantId } + + 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 [SendToMsTeamsChannelName]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .channelName() + * .serviceUrl() + * .teamId() + * .tenantId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToMsTeamsChannelName = + SendToMsTeamsChannelName( + checkRequired("channelName", channelName), + checkRequired("serviceUrl", serviceUrl), + checkRequired("teamId", teamId), + checkRequired("tenantId", tenantId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToMsTeamsChannelName = apply { + if (validated) { + return@apply + } + + channelName() + serviceUrl() + teamId() + tenantId() + 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 (channelName.asKnown().isPresent) 1 else 0) + + (if (serviceUrl.asKnown().isPresent) 1 else 0) + + (if (teamId.asKnown().isPresent) 1 else 0) + + (if (tenantId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToMsTeamsChannelName && + channelName == other.channelName && + serviceUrl == other.serviceUrl && + teamId == other.teamId && + tenantId == other.tenantId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(channelName, serviceUrl, teamId, tenantId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToMsTeamsChannelName{channelName=$channelName, serviceUrl=$serviceUrl, teamId=$teamId, tenantId=$tenantId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsConversationId.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsConversationId.kt new file mode 100644 index 00000000..350af3a0 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsConversationId.kt @@ -0,0 +1,250 @@ +// 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.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 + +class SendToMsTeamsConversationId +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val conversationId: JsonField, + private val serviceUrl: JsonField, + private val tenantId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("conversation_id") + @ExcludeMissing + conversationId: JsonField = JsonMissing.of(), + @JsonProperty("service_url") + @ExcludeMissing + serviceUrl: JsonField = JsonMissing.of(), + @JsonProperty("tenant_id") @ExcludeMissing tenantId: JsonField = JsonMissing.of(), + ) : this(conversationId, serviceUrl, tenantId, 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 conversationId(): String = conversationId.getRequired("conversation_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 serviceUrl(): String = serviceUrl.getRequired("service_url") + + /** + * @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 tenantId(): String = tenantId.getRequired("tenant_id") + + /** + * Returns the raw JSON value of [conversationId]. + * + * Unlike [conversationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("conversation_id") + @ExcludeMissing + fun _conversationId(): JsonField = conversationId + + /** + * Returns the raw JSON value of [serviceUrl]. + * + * Unlike [serviceUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("service_url") @ExcludeMissing fun _serviceUrl(): JsonField = serviceUrl + + /** + * Returns the raw JSON value of [tenantId]. + * + * Unlike [tenantId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tenant_id") @ExcludeMissing fun _tenantId(): JsonField = tenantId + + @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 [SendToMsTeamsConversationId]. + * + * The following fields are required: + * ```java + * .conversationId() + * .serviceUrl() + * .tenantId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToMsTeamsConversationId]. */ + class Builder internal constructor() { + + private var conversationId: JsonField? = null + private var serviceUrl: JsonField? = null + private var tenantId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToMsTeamsConversationId: SendToMsTeamsConversationId) = apply { + conversationId = sendToMsTeamsConversationId.conversationId + serviceUrl = sendToMsTeamsConversationId.serviceUrl + tenantId = sendToMsTeamsConversationId.tenantId + additionalProperties = sendToMsTeamsConversationId.additionalProperties.toMutableMap() + } + + fun conversationId(conversationId: String) = conversationId(JsonField.of(conversationId)) + + /** + * Sets [Builder.conversationId] to an arbitrary JSON value. + * + * You should usually call [Builder.conversationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun conversationId(conversationId: JsonField) = apply { + this.conversationId = conversationId + } + + fun serviceUrl(serviceUrl: String) = serviceUrl(JsonField.of(serviceUrl)) + + /** + * Sets [Builder.serviceUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.serviceUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun serviceUrl(serviceUrl: JsonField) = apply { this.serviceUrl = serviceUrl } + + fun tenantId(tenantId: String) = tenantId(JsonField.of(tenantId)) + + /** + * Sets [Builder.tenantId] to an arbitrary JSON value. + * + * You should usually call [Builder.tenantId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tenantId(tenantId: JsonField) = apply { this.tenantId = tenantId } + + 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 [SendToMsTeamsConversationId]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .conversationId() + * .serviceUrl() + * .tenantId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToMsTeamsConversationId = + SendToMsTeamsConversationId( + checkRequired("conversationId", conversationId), + checkRequired("serviceUrl", serviceUrl), + checkRequired("tenantId", tenantId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToMsTeamsConversationId = apply { + if (validated) { + return@apply + } + + conversationId() + serviceUrl() + tenantId() + 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 (conversationId.asKnown().isPresent) 1 else 0) + + (if (serviceUrl.asKnown().isPresent) 1 else 0) + + (if (tenantId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToMsTeamsConversationId && + conversationId == other.conversationId && + serviceUrl == other.serviceUrl && + tenantId == other.tenantId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(conversationId, serviceUrl, tenantId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToMsTeamsConversationId{conversationId=$conversationId, serviceUrl=$serviceUrl, tenantId=$tenantId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsEmail.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsEmail.kt new file mode 100644 index 00000000..be1dcfb8 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsEmail.kt @@ -0,0 +1,243 @@ +// 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.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 + +class SendToMsTeamsEmail +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val email: JsonField, + private val serviceUrl: JsonField, + private val tenantId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("email") @ExcludeMissing email: JsonField = JsonMissing.of(), + @JsonProperty("service_url") + @ExcludeMissing + serviceUrl: JsonField = JsonMissing.of(), + @JsonProperty("tenant_id") @ExcludeMissing tenantId: JsonField = JsonMissing.of(), + ) : this(email, serviceUrl, tenantId, 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 email(): String = email.getRequired("email") + + /** + * @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 serviceUrl(): String = serviceUrl.getRequired("service_url") + + /** + * @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 tenantId(): String = tenantId.getRequired("tenant_id") + + /** + * Returns the raw JSON value of [email]. + * + * Unlike [email], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("email") @ExcludeMissing fun _email(): JsonField = email + + /** + * Returns the raw JSON value of [serviceUrl]. + * + * Unlike [serviceUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("service_url") @ExcludeMissing fun _serviceUrl(): JsonField = serviceUrl + + /** + * Returns the raw JSON value of [tenantId]. + * + * Unlike [tenantId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tenant_id") @ExcludeMissing fun _tenantId(): JsonField = tenantId + + @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 [SendToMsTeamsEmail]. + * + * The following fields are required: + * ```java + * .email() + * .serviceUrl() + * .tenantId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToMsTeamsEmail]. */ + class Builder internal constructor() { + + private var email: JsonField? = null + private var serviceUrl: JsonField? = null + private var tenantId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToMsTeamsEmail: SendToMsTeamsEmail) = apply { + email = sendToMsTeamsEmail.email + serviceUrl = sendToMsTeamsEmail.serviceUrl + tenantId = sendToMsTeamsEmail.tenantId + additionalProperties = sendToMsTeamsEmail.additionalProperties.toMutableMap() + } + + fun email(email: String) = email(JsonField.of(email)) + + /** + * Sets [Builder.email] to an arbitrary JSON value. + * + * You should usually call [Builder.email] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun email(email: JsonField) = apply { this.email = email } + + fun serviceUrl(serviceUrl: String) = serviceUrl(JsonField.of(serviceUrl)) + + /** + * Sets [Builder.serviceUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.serviceUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun serviceUrl(serviceUrl: JsonField) = apply { this.serviceUrl = serviceUrl } + + fun tenantId(tenantId: String) = tenantId(JsonField.of(tenantId)) + + /** + * Sets [Builder.tenantId] to an arbitrary JSON value. + * + * You should usually call [Builder.tenantId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tenantId(tenantId: JsonField) = apply { this.tenantId = tenantId } + + 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 [SendToMsTeamsEmail]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .email() + * .serviceUrl() + * .tenantId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToMsTeamsEmail = + SendToMsTeamsEmail( + checkRequired("email", email), + checkRequired("serviceUrl", serviceUrl), + checkRequired("tenantId", tenantId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToMsTeamsEmail = apply { + if (validated) { + return@apply + } + + email() + serviceUrl() + tenantId() + 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 (email.asKnown().isPresent) 1 else 0) + + (if (serviceUrl.asKnown().isPresent) 1 else 0) + + (if (tenantId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToMsTeamsEmail && + email == other.email && + serviceUrl == other.serviceUrl && + tenantId == other.tenantId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(email, serviceUrl, tenantId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToMsTeamsEmail{email=$email, serviceUrl=$serviceUrl, tenantId=$tenantId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsUserId.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsUserId.kt new file mode 100644 index 00000000..ce4fb3b7 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToMsTeamsUserId.kt @@ -0,0 +1,243 @@ +// 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.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 + +class SendToMsTeamsUserId +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val serviceUrl: JsonField, + private val tenantId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("service_url") + @ExcludeMissing + serviceUrl: JsonField = JsonMissing.of(), + @JsonProperty("tenant_id") @ExcludeMissing tenantId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this(serviceUrl, tenantId, userId, 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 serviceUrl(): String = serviceUrl.getRequired("service_url") + + /** + * @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 tenantId(): String = tenantId.getRequired("tenant_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 userId(): String = userId.getRequired("user_id") + + /** + * Returns the raw JSON value of [serviceUrl]. + * + * Unlike [serviceUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("service_url") @ExcludeMissing fun _serviceUrl(): JsonField = serviceUrl + + /** + * Returns the raw JSON value of [tenantId]. + * + * Unlike [tenantId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tenant_id") @ExcludeMissing fun _tenantId(): JsonField = tenantId + + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + @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 [SendToMsTeamsUserId]. + * + * The following fields are required: + * ```java + * .serviceUrl() + * .tenantId() + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToMsTeamsUserId]. */ + class Builder internal constructor() { + + private var serviceUrl: JsonField? = null + private var tenantId: JsonField? = null + private var userId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToMsTeamsUserId: SendToMsTeamsUserId) = apply { + serviceUrl = sendToMsTeamsUserId.serviceUrl + tenantId = sendToMsTeamsUserId.tenantId + userId = sendToMsTeamsUserId.userId + additionalProperties = sendToMsTeamsUserId.additionalProperties.toMutableMap() + } + + fun serviceUrl(serviceUrl: String) = serviceUrl(JsonField.of(serviceUrl)) + + /** + * Sets [Builder.serviceUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.serviceUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun serviceUrl(serviceUrl: JsonField) = apply { this.serviceUrl = serviceUrl } + + fun tenantId(tenantId: String) = tenantId(JsonField.of(tenantId)) + + /** + * Sets [Builder.tenantId] to an arbitrary JSON value. + * + * You should usually call [Builder.tenantId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tenantId(tenantId: JsonField) = apply { this.tenantId = tenantId } + + fun userId(userId: String) = userId(JsonField.of(userId)) + + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } + + 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 [SendToMsTeamsUserId]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .serviceUrl() + * .tenantId() + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToMsTeamsUserId = + SendToMsTeamsUserId( + checkRequired("serviceUrl", serviceUrl), + checkRequired("tenantId", tenantId), + checkRequired("userId", userId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToMsTeamsUserId = apply { + if (validated) { + return@apply + } + + serviceUrl() + tenantId() + userId() + 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 (serviceUrl.asKnown().isPresent) 1 else 0) + + (if (tenantId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToMsTeamsUserId && + serviceUrl == other.serviceUrl && + tenantId == other.tenantId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(serviceUrl, tenantId, userId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToMsTeamsUserId{serviceUrl=$serviceUrl, tenantId=$tenantId, userId=$userId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackChannel.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackChannel.kt new file mode 100644 index 00000000..67b87ff7 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackChannel.kt @@ -0,0 +1,210 @@ +// 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.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 + +class SendToSlackChannel +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val accessToken: JsonField, + private val channel: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("access_token") + @ExcludeMissing + accessToken: JsonField = JsonMissing.of(), + @JsonProperty("channel") @ExcludeMissing channel: JsonField = JsonMissing.of(), + ) : this(accessToken, channel, 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 accessToken(): String = accessToken.getRequired("access_token") + + /** + * @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 channel(): String = channel.getRequired("channel") + + /** + * Returns the raw JSON value of [accessToken]. + * + * Unlike [accessToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("access_token") + @ExcludeMissing + fun _accessToken(): JsonField = accessToken + + /** + * 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 + + @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 [SendToSlackChannel]. + * + * The following fields are required: + * ```java + * .accessToken() + * .channel() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToSlackChannel]. */ + class Builder internal constructor() { + + private var accessToken: JsonField? = null + private var channel: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToSlackChannel: SendToSlackChannel) = apply { + accessToken = sendToSlackChannel.accessToken + channel = sendToSlackChannel.channel + additionalProperties = sendToSlackChannel.additionalProperties.toMutableMap() + } + + fun accessToken(accessToken: String) = accessToken(JsonField.of(accessToken)) + + /** + * Sets [Builder.accessToken] to an arbitrary JSON value. + * + * You should usually call [Builder.accessToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun accessToken(accessToken: JsonField) = apply { this.accessToken = accessToken } + + fun channel(channel: String) = channel(JsonField.of(channel)) + + /** + * Sets [Builder.channel] to an arbitrary JSON value. + * + * You should usually call [Builder.channel] with a well-typed [String] 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 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 [SendToSlackChannel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .accessToken() + * .channel() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToSlackChannel = + SendToSlackChannel( + checkRequired("accessToken", accessToken), + checkRequired("channel", channel), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToSlackChannel = apply { + if (validated) { + return@apply + } + + accessToken() + channel() + 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 (accessToken.asKnown().isPresent) 1 else 0) + + (if (channel.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToSlackChannel && + accessToken == other.accessToken && + channel == other.channel && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(accessToken, channel, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToSlackChannel{accessToken=$accessToken, channel=$channel, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackEmail.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackEmail.kt new file mode 100644 index 00000000..0a2654a2 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackEmail.kt @@ -0,0 +1,209 @@ +// 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.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 + +class SendToSlackEmail +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val accessToken: JsonField, + private val email: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("access_token") + @ExcludeMissing + accessToken: JsonField = JsonMissing.of(), + @JsonProperty("email") @ExcludeMissing email: JsonField = JsonMissing.of(), + ) : this(accessToken, email, 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 accessToken(): String = accessToken.getRequired("access_token") + + /** + * @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 email(): String = email.getRequired("email") + + /** + * Returns the raw JSON value of [accessToken]. + * + * Unlike [accessToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("access_token") + @ExcludeMissing + fun _accessToken(): JsonField = accessToken + + /** + * Returns the raw JSON value of [email]. + * + * Unlike [email], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("email") @ExcludeMissing fun _email(): JsonField = email + + @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 [SendToSlackEmail]. + * + * The following fields are required: + * ```java + * .accessToken() + * .email() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToSlackEmail]. */ + class Builder internal constructor() { + + private var accessToken: JsonField? = null + private var email: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToSlackEmail: SendToSlackEmail) = apply { + accessToken = sendToSlackEmail.accessToken + email = sendToSlackEmail.email + additionalProperties = sendToSlackEmail.additionalProperties.toMutableMap() + } + + fun accessToken(accessToken: String) = accessToken(JsonField.of(accessToken)) + + /** + * Sets [Builder.accessToken] to an arbitrary JSON value. + * + * You should usually call [Builder.accessToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun accessToken(accessToken: JsonField) = apply { this.accessToken = accessToken } + + fun email(email: String) = email(JsonField.of(email)) + + /** + * Sets [Builder.email] to an arbitrary JSON value. + * + * You should usually call [Builder.email] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun email(email: JsonField) = apply { this.email = email } + + 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 [SendToSlackEmail]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .accessToken() + * .email() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToSlackEmail = + SendToSlackEmail( + checkRequired("accessToken", accessToken), + checkRequired("email", email), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToSlackEmail = apply { + if (validated) { + return@apply + } + + accessToken() + email() + 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 (accessToken.asKnown().isPresent) 1 else 0) + (if (email.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToSlackEmail && + accessToken == other.accessToken && + email == other.email && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(accessToken, email, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToSlackEmail{accessToken=$accessToken, email=$email, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackUserId.kt b/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackUserId.kt new file mode 100644 index 00000000..72c79ff6 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SendToSlackUserId.kt @@ -0,0 +1,209 @@ +// 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.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 + +class SendToSlackUserId +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val accessToken: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("access_token") + @ExcludeMissing + accessToken: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this(accessToken, userId, 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 accessToken(): String = accessToken.getRequired("access_token") + + /** + * @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 userId(): String = userId.getRequired("user_id") + + /** + * Returns the raw JSON value of [accessToken]. + * + * Unlike [accessToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("access_token") + @ExcludeMissing + fun _accessToken(): JsonField = accessToken + + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + @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 [SendToSlackUserId]. + * + * The following fields are required: + * ```java + * .accessToken() + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendToSlackUserId]. */ + class Builder internal constructor() { + + private var accessToken: JsonField? = null + private var userId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendToSlackUserId: SendToSlackUserId) = apply { + accessToken = sendToSlackUserId.accessToken + userId = sendToSlackUserId.userId + additionalProperties = sendToSlackUserId.additionalProperties.toMutableMap() + } + + fun accessToken(accessToken: String) = accessToken(JsonField.of(accessToken)) + + /** + * Sets [Builder.accessToken] to an arbitrary JSON value. + * + * You should usually call [Builder.accessToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun accessToken(accessToken: JsonField) = apply { this.accessToken = accessToken } + + fun userId(userId: String) = userId(JsonField.of(userId)) + + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } + + 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 [SendToSlackUserId]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .accessToken() + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendToSlackUserId = + SendToSlackUserId( + checkRequired("accessToken", accessToken), + checkRequired("userId", userId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SendToSlackUserId = apply { + if (validated) { + return@apply + } + + accessToken() + userId() + 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 (accessToken.asKnown().isPresent) 1 else 0) + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SendToSlackUserId && + accessToken == other.accessToken && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(accessToken, userId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendToSlackUserId{accessToken=$accessToken, userId=$userId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Slack.kt b/courier-java-core/src/main/kotlin/com/courier/models/Slack.kt new file mode 100644 index 00000000..1bc642e0 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Slack.kt @@ -0,0 +1,224 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.BaseDeserializer +import com.courier.core.BaseSerializer +import com.courier.core.JsonValue +import com.courier.core.allMaxBy +import com.courier.core.getOrThrow +import com.courier.errors.CourierInvalidDataException +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.Objects +import java.util.Optional + +@JsonDeserialize(using = Slack.Deserializer::class) +@JsonSerialize(using = Slack.Serializer::class) +class Slack +private constructor( + private val sendToSlackChannel: SendToSlackChannel? = null, + private val sendToSlackEmail: SendToSlackEmail? = null, + private val sendToSlackUserId: SendToSlackUserId? = null, + private val _json: JsonValue? = null, +) { + + fun sendToSlackChannel(): Optional = Optional.ofNullable(sendToSlackChannel) + + fun sendToSlackEmail(): Optional = Optional.ofNullable(sendToSlackEmail) + + fun sendToSlackUserId(): Optional = Optional.ofNullable(sendToSlackUserId) + + fun isSendToSlackChannel(): Boolean = sendToSlackChannel != null + + fun isSendToSlackEmail(): Boolean = sendToSlackEmail != null + + fun isSendToSlackUserId(): Boolean = sendToSlackUserId != null + + fun asSendToSlackChannel(): SendToSlackChannel = + sendToSlackChannel.getOrThrow("sendToSlackChannel") + + fun asSendToSlackEmail(): SendToSlackEmail = sendToSlackEmail.getOrThrow("sendToSlackEmail") + + fun asSendToSlackUserId(): SendToSlackUserId = sendToSlackUserId.getOrThrow("sendToSlackUserId") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + sendToSlackChannel != null -> visitor.visitSendToSlackChannel(sendToSlackChannel) + sendToSlackEmail != null -> visitor.visitSendToSlackEmail(sendToSlackEmail) + sendToSlackUserId != null -> visitor.visitSendToSlackUserId(sendToSlackUserId) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Slack = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSendToSlackChannel(sendToSlackChannel: SendToSlackChannel) { + sendToSlackChannel.validate() + } + + override fun visitSendToSlackEmail(sendToSlackEmail: SendToSlackEmail) { + sendToSlackEmail.validate() + } + + override fun visitSendToSlackUserId(sendToSlackUserId: SendToSlackUserId) { + sendToSlackUserId.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 = + accept( + object : Visitor { + override fun visitSendToSlackChannel(sendToSlackChannel: SendToSlackChannel) = + sendToSlackChannel.validity() + + override fun visitSendToSlackEmail(sendToSlackEmail: SendToSlackEmail) = + sendToSlackEmail.validity() + + override fun visitSendToSlackUserId(sendToSlackUserId: SendToSlackUserId) = + sendToSlackUserId.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Slack && + sendToSlackChannel == other.sendToSlackChannel && + sendToSlackEmail == other.sendToSlackEmail && + sendToSlackUserId == other.sendToSlackUserId + } + + override fun hashCode(): Int = + Objects.hash(sendToSlackChannel, sendToSlackEmail, sendToSlackUserId) + + override fun toString(): String = + when { + sendToSlackChannel != null -> "Slack{sendToSlackChannel=$sendToSlackChannel}" + sendToSlackEmail != null -> "Slack{sendToSlackEmail=$sendToSlackEmail}" + sendToSlackUserId != null -> "Slack{sendToSlackUserId=$sendToSlackUserId}" + _json != null -> "Slack{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Slack") + } + + companion object { + + @JvmStatic + fun ofSendToSlackChannel(sendToSlackChannel: SendToSlackChannel) = + Slack(sendToSlackChannel = sendToSlackChannel) + + @JvmStatic + fun ofSendToSlackEmail(sendToSlackEmail: SendToSlackEmail) = + Slack(sendToSlackEmail = sendToSlackEmail) + + @JvmStatic + fun ofSendToSlackUserId(sendToSlackUserId: SendToSlackUserId) = + Slack(sendToSlackUserId = sendToSlackUserId) + } + + /** An interface that defines how to map each variant of [Slack] to a value of type [T]. */ + interface Visitor { + + fun visitSendToSlackChannel(sendToSlackChannel: SendToSlackChannel): T + + fun visitSendToSlackEmail(sendToSlackEmail: SendToSlackEmail): T + + fun visitSendToSlackUserId(sendToSlackUserId: SendToSlackUserId): T + + /** + * Maps an unknown variant of [Slack] to a value of type [T]. + * + * An instance of [Slack] 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. + */ + fun unknown(json: JsonValue?): T { + throw CourierInvalidDataException("Unknown Slack: $json") + } + } + + internal class Deserializer : BaseDeserializer(Slack::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Slack { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Slack(sendToSlackChannel = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Slack(sendToSlackEmail = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Slack(sendToSlackUserId = 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 -> Slack(_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(Slack::class) { + + override fun serialize( + value: Slack, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.sendToSlackChannel != null -> generator.writeObject(value.sendToSlackChannel) + value.sendToSlackEmail != null -> generator.writeObject(value.sendToSlackEmail) + value.sendToSlackUserId != null -> generator.writeObject(value.sendToSlackUserId) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Slack") + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SlackBaseProperties.kt b/courier-java-core/src/main/kotlin/com/courier/models/SlackBaseProperties.kt new file mode 100644 index 00000000..32405d86 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SlackBaseProperties.kt @@ -0,0 +1,175 @@ +// 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.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 + +class SlackBaseProperties +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val accessToken: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("access_token") + @ExcludeMissing + accessToken: JsonField = JsonMissing.of() + ) : this(accessToken, 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 accessToken(): String = accessToken.getRequired("access_token") + + /** + * Returns the raw JSON value of [accessToken]. + * + * Unlike [accessToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("access_token") + @ExcludeMissing + fun _accessToken(): JsonField = accessToken + + @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 [SlackBaseProperties]. + * + * The following fields are required: + * ```java + * .accessToken() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SlackBaseProperties]. */ + class Builder internal constructor() { + + private var accessToken: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(slackBaseProperties: SlackBaseProperties) = apply { + accessToken = slackBaseProperties.accessToken + additionalProperties = slackBaseProperties.additionalProperties.toMutableMap() + } + + fun accessToken(accessToken: String) = accessToken(JsonField.of(accessToken)) + + /** + * Sets [Builder.accessToken] to an arbitrary JSON value. + * + * You should usually call [Builder.accessToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun accessToken(accessToken: JsonField) = apply { this.accessToken = accessToken } + + 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 [SlackBaseProperties]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .accessToken() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SlackBaseProperties = + SlackBaseProperties( + checkRequired("accessToken", accessToken), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SlackBaseProperties = apply { + if (validated) { + return@apply + } + + accessToken() + 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 (accessToken.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SlackBaseProperties && + accessToken == other.accessToken && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(accessToken, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SlackBaseProperties{accessToken=$accessToken, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/SlackRecipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/SlackRecipient.kt new file mode 100644 index 00000000..4453cb81 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/SlackRecipient.kt @@ -0,0 +1,181 @@ +// 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.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 + +/** Send via Slack (channel, email, or user_id) */ +class SlackRecipient +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val slack: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("slack") @ExcludeMissing slack: JsonField = JsonMissing.of() + ) : this(slack, 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 slack(): Slack = slack.getRequired("slack") + + /** + * Returns the raw JSON value of [slack]. + * + * Unlike [slack], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("slack") @ExcludeMissing fun _slack(): JsonField = slack + + @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 [SlackRecipient]. + * + * The following fields are required: + * ```java + * .slack() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SlackRecipient]. */ + class Builder internal constructor() { + + private var slack: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(slackRecipient: SlackRecipient) = apply { + slack = slackRecipient.slack + additionalProperties = slackRecipient.additionalProperties.toMutableMap() + } + + fun slack(slack: Slack) = slack(JsonField.of(slack)) + + /** + * Sets [Builder.slack] to an arbitrary JSON value. + * + * You should usually call [Builder.slack] with a well-typed [Slack] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun slack(slack: JsonField) = apply { this.slack = slack } + + /** Alias for calling [slack] with `Slack.ofSendToSlackChannel(sendToSlackChannel)`. */ + fun slack(sendToSlackChannel: SendToSlackChannel) = + slack(Slack.ofSendToSlackChannel(sendToSlackChannel)) + + /** Alias for calling [slack] with `Slack.ofSendToSlackEmail(sendToSlackEmail)`. */ + fun slack(sendToSlackEmail: SendToSlackEmail) = + slack(Slack.ofSendToSlackEmail(sendToSlackEmail)) + + /** Alias for calling [slack] with `Slack.ofSendToSlackUserId(sendToSlackUserId)`. */ + fun slack(sendToSlackUserId: SendToSlackUserId) = + slack(Slack.ofSendToSlackUserId(sendToSlackUserId)) + + 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 [SlackRecipient]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .slack() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SlackRecipient = + SlackRecipient(checkRequired("slack", slack), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): SlackRecipient = apply { + if (validated) { + return@apply + } + + slack().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 = (slack.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SlackRecipient && + slack == other.slack && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(slack, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SlackRecipient{slack=$slack, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/Token.kt b/courier-java-core/src/main/kotlin/com/courier/models/Token.kt new file mode 100644 index 00000000..14d4ae35 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/Token.kt @@ -0,0 +1,166 @@ +// 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.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 + +class Token +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val token: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("token") @ExcludeMissing token: JsonField = JsonMissing.of() + ) : this(token, 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 token(): String = token.getRequired("token") + + /** + * Returns the raw JSON value of [token]. + * + * Unlike [token], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token + + @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 [Token]. + * + * The following fields are required: + * ```java + * .token() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Token]. */ + class Builder internal constructor() { + + private var token: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(token: Token) = apply { + this.token = token.token + additionalProperties = token.additionalProperties.toMutableMap() + } + + fun token(token: String) = token(JsonField.of(token)) + + /** + * Sets [Builder.token] to an arbitrary JSON value. + * + * You should usually call [Builder.token] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun token(token: JsonField) = apply { this.token = token } + + 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 [Token]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .token() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Token = + Token(checkRequired("token", token), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Token = apply { + if (validated) { + return@apply + } + + token() + 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 (token.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Token && + token == other.token && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(token, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Token{token=$token, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/UserProfile.kt b/courier-java-core/src/main/kotlin/com/courier/models/UserProfile.kt new file mode 100644 index 00000000..9ab75a1d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/UserProfile.kt @@ -0,0 +1,1860 @@ +// 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.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 + +class UserProfile +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val address: JsonField
, + private val airship: JsonField, + private val apn: JsonField, + private val birthdate: JsonField, + private val custom: JsonField, + private val discord: JsonField, + private val email: JsonField, + private val emailVerified: JsonField, + private val expo: JsonField, + private val facebookPsid: JsonField, + private val familyName: JsonField, + private val firebaseToken: JsonField, + private val gender: JsonField, + private val givenName: JsonField, + private val intercom: JsonField, + private val locale: JsonField, + private val middleName: JsonField, + private val msTeams: JsonField, + private val name: JsonField, + private val nickname: JsonField, + private val phoneNumber: JsonField, + private val phoneNumberVerified: JsonField, + private val picture: JsonField, + private val preferredName: JsonField, + private val profile: JsonField, + private val slack: JsonField, + private val sub: JsonField, + private val targetArn: JsonField, + private val updatedAt: JsonField, + private val website: JsonField, + private val zoneinfo: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("address") @ExcludeMissing address: JsonField
= JsonMissing.of(), + @JsonProperty("airship") + @ExcludeMissing + airship: JsonField = JsonMissing.of(), + @JsonProperty("apn") @ExcludeMissing apn: JsonField = JsonMissing.of(), + @JsonProperty("birthdate") @ExcludeMissing birthdate: JsonField = JsonMissing.of(), + @JsonProperty("custom") @ExcludeMissing custom: JsonField = JsonMissing.of(), + @JsonProperty("discord") @ExcludeMissing discord: JsonField = JsonMissing.of(), + @JsonProperty("email") @ExcludeMissing email: JsonField = JsonMissing.of(), + @JsonProperty("email_verified") + @ExcludeMissing + emailVerified: JsonField = JsonMissing.of(), + @JsonProperty("expo") @ExcludeMissing expo: JsonField = JsonMissing.of(), + @JsonProperty("facebookPSID") + @ExcludeMissing + facebookPsid: JsonField = JsonMissing.of(), + @JsonProperty("family_name") + @ExcludeMissing + familyName: JsonField = JsonMissing.of(), + @JsonProperty("firebaseToken") + @ExcludeMissing + firebaseToken: JsonField = JsonMissing.of(), + @JsonProperty("gender") @ExcludeMissing gender: JsonField = JsonMissing.of(), + @JsonProperty("given_name") @ExcludeMissing givenName: JsonField = JsonMissing.of(), + @JsonProperty("intercom") @ExcludeMissing intercom: JsonField = JsonMissing.of(), + @JsonProperty("locale") @ExcludeMissing locale: JsonField = JsonMissing.of(), + @JsonProperty("middle_name") + @ExcludeMissing + middleName: JsonField = JsonMissing.of(), + @JsonProperty("ms_teams") @ExcludeMissing msTeams: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("nickname") @ExcludeMissing nickname: JsonField = JsonMissing.of(), + @JsonProperty("phone_number") + @ExcludeMissing + phoneNumber: JsonField = JsonMissing.of(), + @JsonProperty("phone_number_verified") + @ExcludeMissing + phoneNumberVerified: JsonField = JsonMissing.of(), + @JsonProperty("picture") @ExcludeMissing picture: JsonField = JsonMissing.of(), + @JsonProperty("preferred_name") + @ExcludeMissing + preferredName: JsonField = JsonMissing.of(), + @JsonProperty("profile") @ExcludeMissing profile: JsonField = JsonMissing.of(), + @JsonProperty("slack") @ExcludeMissing slack: JsonField = JsonMissing.of(), + @JsonProperty("sub") @ExcludeMissing sub: JsonField = JsonMissing.of(), + @JsonProperty("target_arn") @ExcludeMissing targetArn: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("website") @ExcludeMissing website: JsonField = JsonMissing.of(), + @JsonProperty("zoneinfo") @ExcludeMissing zoneinfo: JsonField = JsonMissing.of(), + ) : this( + address, + airship, + apn, + birthdate, + custom, + discord, + email, + emailVerified, + expo, + facebookPsid, + familyName, + firebaseToken, + gender, + givenName, + intercom, + locale, + middleName, + msTeams, + name, + nickname, + phoneNumber, + phoneNumberVerified, + picture, + preferredName, + profile, + slack, + sub, + targetArn, + updatedAt, + website, + zoneinfo, + mutableMapOf(), + ) + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun address(): Optional
= address.getOptional("address") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun airship(): Optional = airship.getOptional("airship") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun apn(): Optional = apn.getOptional("apn") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun birthdate(): Optional = birthdate.getOptional("birthdate") + + /** + * A free form object. Due to a limitation of the API Explorer, you can only enter string + * key/values below, but this API accepts more complex object structures. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun custom(): Optional = custom.getOptional("custom") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun discord(): Optional = discord.getOptional("discord") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun email(): Optional = email.getOptional("email") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun emailVerified(): Optional = emailVerified.getOptional("email_verified") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun expo(): Optional = expo.getOptional("expo") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun facebookPsid(): Optional = facebookPsid.getOptional("facebookPSID") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun familyName(): Optional = familyName.getOptional("family_name") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun firebaseToken(): Optional = + firebaseToken.getOptional("firebaseToken") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun gender(): Optional = gender.getOptional("gender") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun givenName(): Optional = givenName.getOptional("given_name") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun intercom(): Optional = intercom.getOptional("intercom") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun locale(): Optional = locale.getOptional("locale") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun middleName(): Optional = middleName.getOptional("middle_name") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun msTeams(): Optional = msTeams.getOptional("ms_teams") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nickname(): Optional = nickname.getOptional("nickname") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun phoneNumber(): Optional = phoneNumber.getOptional("phone_number") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun phoneNumberVerified(): Optional = + phoneNumberVerified.getOptional("phone_number_verified") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun picture(): Optional = picture.getOptional("picture") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun preferredName(): Optional = preferredName.getOptional("preferred_name") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun profile(): Optional = profile.getOptional("profile") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun slack(): Optional = slack.getOptional("slack") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sub(): Optional = sub.getOptional("sub") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun targetArn(): Optional = targetArn.getOptional("target_arn") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun website(): Optional = website.getOptional("website") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun zoneinfo(): Optional = zoneinfo.getOptional("zoneinfo") + + /** + * Returns the raw JSON value of [address]. + * + * Unlike [address], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("address") @ExcludeMissing fun _address(): JsonField
= address + + /** + * Returns the raw JSON value of [airship]. + * + * Unlike [airship], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("airship") @ExcludeMissing fun _airship(): JsonField = airship + + /** + * Returns the raw JSON value of [apn]. + * + * Unlike [apn], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("apn") @ExcludeMissing fun _apn(): JsonField = apn + + /** + * Returns the raw JSON value of [birthdate]. + * + * Unlike [birthdate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("birthdate") @ExcludeMissing fun _birthdate(): JsonField = birthdate + + /** + * Returns the raw JSON value of [custom]. + * + * Unlike [custom], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("custom") @ExcludeMissing fun _custom(): JsonField = custom + + /** + * Returns the raw JSON value of [discord]. + * + * Unlike [discord], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("discord") @ExcludeMissing fun _discord(): JsonField = discord + + /** + * Returns the raw JSON value of [email]. + * + * Unlike [email], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("email") @ExcludeMissing fun _email(): JsonField = email + + /** + * Returns the raw JSON value of [emailVerified]. + * + * Unlike [emailVerified], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("email_verified") + @ExcludeMissing + fun _emailVerified(): JsonField = emailVerified + + /** + * Returns the raw JSON value of [expo]. + * + * Unlike [expo], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("expo") @ExcludeMissing fun _expo(): JsonField = expo + + /** + * Returns the raw JSON value of [facebookPsid]. + * + * Unlike [facebookPsid], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("facebookPSID") + @ExcludeMissing + fun _facebookPsid(): JsonField = facebookPsid + + /** + * Returns the raw JSON value of [familyName]. + * + * Unlike [familyName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("family_name") @ExcludeMissing fun _familyName(): JsonField = familyName + + /** + * Returns the raw JSON value of [firebaseToken]. + * + * Unlike [firebaseToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("firebaseToken") + @ExcludeMissing + fun _firebaseToken(): JsonField = firebaseToken + + /** + * Returns the raw JSON value of [gender]. + * + * Unlike [gender], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("gender") @ExcludeMissing fun _gender(): JsonField = gender + + /** + * Returns the raw JSON value of [givenName]. + * + * Unlike [givenName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("given_name") @ExcludeMissing fun _givenName(): JsonField = givenName + + /** + * Returns the raw JSON value of [intercom]. + * + * Unlike [intercom], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("intercom") @ExcludeMissing fun _intercom(): JsonField = intercom + + /** + * Returns the raw JSON value of [locale]. + * + * Unlike [locale], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("locale") @ExcludeMissing fun _locale(): JsonField = locale + + /** + * Returns the raw JSON value of [middleName]. + * + * Unlike [middleName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("middle_name") @ExcludeMissing fun _middleName(): JsonField = middleName + + /** + * Returns the raw JSON value of [msTeams]. + * + * Unlike [msTeams], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("ms_teams") @ExcludeMissing fun _msTeams(): JsonField = msTeams + + /** + * 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 [nickname]. + * + * Unlike [nickname], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("nickname") @ExcludeMissing fun _nickname(): JsonField = nickname + + /** + * Returns the raw JSON value of [phoneNumber]. + * + * Unlike [phoneNumber], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("phone_number") + @ExcludeMissing + fun _phoneNumber(): JsonField = phoneNumber + + /** + * Returns the raw JSON value of [phoneNumberVerified]. + * + * Unlike [phoneNumberVerified], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("phone_number_verified") + @ExcludeMissing + fun _phoneNumberVerified(): JsonField = phoneNumberVerified + + /** + * Returns the raw JSON value of [picture]. + * + * Unlike [picture], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("picture") @ExcludeMissing fun _picture(): JsonField = picture + + /** + * Returns the raw JSON value of [preferredName]. + * + * Unlike [preferredName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("preferred_name") + @ExcludeMissing + fun _preferredName(): JsonField = preferredName + + /** + * Returns the raw JSON value of [profile]. + * + * Unlike [profile], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("profile") @ExcludeMissing fun _profile(): JsonField = profile + + /** + * Returns the raw JSON value of [slack]. + * + * Unlike [slack], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("slack") @ExcludeMissing fun _slack(): JsonField = slack + + /** + * Returns the raw JSON value of [sub]. + * + * Unlike [sub], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sub") @ExcludeMissing fun _sub(): JsonField = sub + + /** + * Returns the raw JSON value of [targetArn]. + * + * Unlike [targetArn], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("target_arn") @ExcludeMissing fun _targetArn(): JsonField = targetArn + + /** + * 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 + + /** + * Returns the raw JSON value of [website]. + * + * Unlike [website], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("website") @ExcludeMissing fun _website(): JsonField = website + + /** + * Returns the raw JSON value of [zoneinfo]. + * + * Unlike [zoneinfo], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("zoneinfo") @ExcludeMissing fun _zoneinfo(): JsonField = zoneinfo + + @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 [UserProfile]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UserProfile]. */ + class Builder internal constructor() { + + private var address: JsonField
= JsonMissing.of() + private var airship: JsonField = JsonMissing.of() + private var apn: JsonField = JsonMissing.of() + private var birthdate: JsonField = JsonMissing.of() + private var custom: JsonField = JsonMissing.of() + private var discord: JsonField = JsonMissing.of() + private var email: JsonField = JsonMissing.of() + private var emailVerified: JsonField = JsonMissing.of() + private var expo: JsonField = JsonMissing.of() + private var facebookPsid: JsonField = JsonMissing.of() + private var familyName: JsonField = JsonMissing.of() + private var firebaseToken: JsonField = JsonMissing.of() + private var gender: JsonField = JsonMissing.of() + private var givenName: JsonField = JsonMissing.of() + private var intercom: JsonField = JsonMissing.of() + private var locale: JsonField = JsonMissing.of() + private var middleName: JsonField = JsonMissing.of() + private var msTeams: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var nickname: JsonField = JsonMissing.of() + private var phoneNumber: JsonField = JsonMissing.of() + private var phoneNumberVerified: JsonField = JsonMissing.of() + private var picture: JsonField = JsonMissing.of() + private var preferredName: JsonField = JsonMissing.of() + private var profile: JsonField = JsonMissing.of() + private var slack: JsonField = JsonMissing.of() + private var sub: JsonField = JsonMissing.of() + private var targetArn: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var website: JsonField = JsonMissing.of() + private var zoneinfo: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(userProfile: UserProfile) = apply { + address = userProfile.address + airship = userProfile.airship + apn = userProfile.apn + birthdate = userProfile.birthdate + custom = userProfile.custom + discord = userProfile.discord + email = userProfile.email + emailVerified = userProfile.emailVerified + expo = userProfile.expo + facebookPsid = userProfile.facebookPsid + familyName = userProfile.familyName + firebaseToken = userProfile.firebaseToken + gender = userProfile.gender + givenName = userProfile.givenName + intercom = userProfile.intercom + locale = userProfile.locale + middleName = userProfile.middleName + msTeams = userProfile.msTeams + name = userProfile.name + nickname = userProfile.nickname + phoneNumber = userProfile.phoneNumber + phoneNumberVerified = userProfile.phoneNumberVerified + picture = userProfile.picture + preferredName = userProfile.preferredName + profile = userProfile.profile + slack = userProfile.slack + sub = userProfile.sub + targetArn = userProfile.targetArn + updatedAt = userProfile.updatedAt + website = userProfile.website + zoneinfo = userProfile.zoneinfo + additionalProperties = userProfile.additionalProperties.toMutableMap() + } + + fun address(address: Address?) = address(JsonField.ofNullable(address)) + + /** Alias for calling [Builder.address] with `address.orElse(null)`. */ + fun address(address: Optional
) = address(address.getOrNull()) + + /** + * Sets [Builder.address] to an arbitrary JSON value. + * + * You should usually call [Builder.address] with a well-typed [Address] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun address(address: JsonField
) = apply { this.address = address } + + fun airship(airship: AirshipProfile?) = airship(JsonField.ofNullable(airship)) + + /** Alias for calling [Builder.airship] with `airship.orElse(null)`. */ + fun airship(airship: Optional) = airship(airship.getOrNull()) + + /** + * Sets [Builder.airship] to an arbitrary JSON value. + * + * You should usually call [Builder.airship] with a well-typed [AirshipProfile] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun airship(airship: JsonField) = apply { this.airship = airship } + + fun apn(apn: String?) = apn(JsonField.ofNullable(apn)) + + /** Alias for calling [Builder.apn] with `apn.orElse(null)`. */ + fun apn(apn: Optional) = apn(apn.getOrNull()) + + /** + * Sets [Builder.apn] to an arbitrary JSON value. + * + * You should usually call [Builder.apn] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun apn(apn: JsonField) = apply { this.apn = apn } + + fun birthdate(birthdate: String?) = birthdate(JsonField.ofNullable(birthdate)) + + /** Alias for calling [Builder.birthdate] with `birthdate.orElse(null)`. */ + fun birthdate(birthdate: Optional) = birthdate(birthdate.getOrNull()) + + /** + * Sets [Builder.birthdate] to an arbitrary JSON value. + * + * You should usually call [Builder.birthdate] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun birthdate(birthdate: JsonField) = apply { this.birthdate = birthdate } + + /** + * A free form object. Due to a limitation of the API Explorer, you can only enter string + * key/values below, but this API accepts more complex object structures. + */ + fun custom(custom: Custom?) = custom(JsonField.ofNullable(custom)) + + /** Alias for calling [Builder.custom] with `custom.orElse(null)`. */ + fun custom(custom: Optional) = custom(custom.getOrNull()) + + /** + * Sets [Builder.custom] to an arbitrary JSON value. + * + * You should usually call [Builder.custom] with a well-typed [Custom] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun custom(custom: JsonField) = apply { this.custom = custom } + + fun discord(discord: Discord?) = discord(JsonField.ofNullable(discord)) + + /** Alias for calling [Builder.discord] with `discord.orElse(null)`. */ + fun discord(discord: Optional) = discord(discord.getOrNull()) + + /** + * Sets [Builder.discord] to an arbitrary JSON value. + * + * You should usually call [Builder.discord] with a well-typed [Discord] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun discord(discord: JsonField) = apply { this.discord = discord } + + /** Alias for calling [discord] with `Discord.ofSendToChannel(sendToChannel)`. */ + fun discord(sendToChannel: SendToChannel) = discord(Discord.ofSendToChannel(sendToChannel)) + + /** Alias for calling [discord] with `Discord.ofSendDirectMessage(sendDirectMessage)`. */ + fun discord(sendDirectMessage: SendDirectMessage) = + discord(Discord.ofSendDirectMessage(sendDirectMessage)) + + fun email(email: String?) = email(JsonField.ofNullable(email)) + + /** Alias for calling [Builder.email] with `email.orElse(null)`. */ + fun email(email: Optional) = email(email.getOrNull()) + + /** + * Sets [Builder.email] to an arbitrary JSON value. + * + * You should usually call [Builder.email] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun email(email: JsonField) = apply { this.email = email } + + fun emailVerified(emailVerified: Boolean?) = + emailVerified(JsonField.ofNullable(emailVerified)) + + /** + * Alias for [Builder.emailVerified]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun emailVerified(emailVerified: Boolean) = emailVerified(emailVerified as Boolean?) + + /** Alias for calling [Builder.emailVerified] with `emailVerified.orElse(null)`. */ + fun emailVerified(emailVerified: Optional) = + emailVerified(emailVerified.getOrNull()) + + /** + * Sets [Builder.emailVerified] to an arbitrary JSON value. + * + * You should usually call [Builder.emailVerified] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun emailVerified(emailVerified: JsonField) = apply { + this.emailVerified = emailVerified + } + + fun expo(expo: Expo?) = expo(JsonField.ofNullable(expo)) + + /** Alias for calling [Builder.expo] with `expo.orElse(null)`. */ + fun expo(expo: Optional) = expo(expo.getOrNull()) + + /** + * Sets [Builder.expo] to an arbitrary JSON value. + * + * You should usually call [Builder.expo] with a well-typed [Expo] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun expo(expo: JsonField) = apply { this.expo = expo } + + /** Alias for calling [expo] with `Expo.ofToken(token)`. */ + fun expo(token: Token) = expo(Expo.ofToken(token)) + + /** Alias for calling [expo] with `Expo.ofMultipleTokens(multipleTokens)`. */ + fun expo(multipleTokens: MultipleTokens) = expo(Expo.ofMultipleTokens(multipleTokens)) + + fun facebookPsid(facebookPsid: String?) = facebookPsid(JsonField.ofNullable(facebookPsid)) + + /** Alias for calling [Builder.facebookPsid] with `facebookPsid.orElse(null)`. */ + fun facebookPsid(facebookPsid: Optional) = facebookPsid(facebookPsid.getOrNull()) + + /** + * Sets [Builder.facebookPsid] to an arbitrary JSON value. + * + * You should usually call [Builder.facebookPsid] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun facebookPsid(facebookPsid: JsonField) = apply { + this.facebookPsid = facebookPsid + } + + fun familyName(familyName: String?) = familyName(JsonField.ofNullable(familyName)) + + /** Alias for calling [Builder.familyName] with `familyName.orElse(null)`. */ + fun familyName(familyName: Optional) = familyName(familyName.getOrNull()) + + /** + * Sets [Builder.familyName] to an arbitrary JSON value. + * + * You should usually call [Builder.familyName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun familyName(familyName: JsonField) = apply { this.familyName = familyName } + + fun firebaseToken(firebaseToken: UserProfileFirebaseToken?) = + firebaseToken(JsonField.ofNullable(firebaseToken)) + + /** Alias for calling [Builder.firebaseToken] with `firebaseToken.orElse(null)`. */ + fun firebaseToken(firebaseToken: Optional) = + firebaseToken(firebaseToken.getOrNull()) + + /** + * Sets [Builder.firebaseToken] to an arbitrary JSON value. + * + * You should usually call [Builder.firebaseToken] with a well-typed + * [UserProfileFirebaseToken] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun firebaseToken(firebaseToken: JsonField) = apply { + this.firebaseToken = firebaseToken + } + + /** Alias for calling [firebaseToken] with `UserProfileFirebaseToken.ofString(string)`. */ + fun firebaseToken(string: String) = firebaseToken(UserProfileFirebaseToken.ofString(string)) + + /** Alias for calling [firebaseToken] with `UserProfileFirebaseToken.ofStrings(strings)`. */ + fun firebaseTokenOfStrings(strings: List) = + firebaseToken(UserProfileFirebaseToken.ofStrings(strings)) + + fun gender(gender: String?) = gender(JsonField.ofNullable(gender)) + + /** Alias for calling [Builder.gender] with `gender.orElse(null)`. */ + fun gender(gender: Optional) = gender(gender.getOrNull()) + + /** + * Sets [Builder.gender] to an arbitrary JSON value. + * + * You should usually call [Builder.gender] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun gender(gender: JsonField) = apply { this.gender = gender } + + fun givenName(givenName: String?) = givenName(JsonField.ofNullable(givenName)) + + /** Alias for calling [Builder.givenName] with `givenName.orElse(null)`. */ + fun givenName(givenName: Optional) = givenName(givenName.getOrNull()) + + /** + * Sets [Builder.givenName] to an arbitrary JSON value. + * + * You should usually call [Builder.givenName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun givenName(givenName: JsonField) = apply { this.givenName = givenName } + + fun intercom(intercom: Intercom?) = intercom(JsonField.ofNullable(intercom)) + + /** Alias for calling [Builder.intercom] with `intercom.orElse(null)`. */ + fun intercom(intercom: Optional) = intercom(intercom.getOrNull()) + + /** + * Sets [Builder.intercom] to an arbitrary JSON value. + * + * You should usually call [Builder.intercom] with a well-typed [Intercom] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun intercom(intercom: JsonField) = apply { this.intercom = intercom } + + fun locale(locale: String?) = locale(JsonField.ofNullable(locale)) + + /** Alias for calling [Builder.locale] with `locale.orElse(null)`. */ + fun locale(locale: Optional) = locale(locale.getOrNull()) + + /** + * Sets [Builder.locale] to an arbitrary JSON value. + * + * You should usually call [Builder.locale] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun locale(locale: JsonField) = apply { this.locale = locale } + + fun middleName(middleName: String?) = middleName(JsonField.ofNullable(middleName)) + + /** Alias for calling [Builder.middleName] with `middleName.orElse(null)`. */ + fun middleName(middleName: Optional) = middleName(middleName.getOrNull()) + + /** + * Sets [Builder.middleName] to an arbitrary JSON value. + * + * You should usually call [Builder.middleName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun middleName(middleName: JsonField) = apply { this.middleName = middleName } + + fun msTeams(msTeams: MsTeams?) = msTeams(JsonField.ofNullable(msTeams)) + + /** Alias for calling [Builder.msTeams] with `msTeams.orElse(null)`. */ + fun msTeams(msTeams: Optional) = msTeams(msTeams.getOrNull()) + + /** + * Sets [Builder.msTeams] to an arbitrary JSON value. + * + * You should usually call [Builder.msTeams] with a well-typed [MsTeams] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun msTeams(msTeams: JsonField) = apply { this.msTeams = msTeams } + + /** + * Alias for calling [msTeams] with `MsTeams.ofSendToMsTeamsUserId(sendToMsTeamsUserId)`. + */ + fun msTeams(sendToMsTeamsUserId: SendToMsTeamsUserId) = + msTeams(MsTeams.ofSendToMsTeamsUserId(sendToMsTeamsUserId)) + + /** Alias for calling [msTeams] with `MsTeams.ofSendToMsTeamsEmail(sendToMsTeamsEmail)`. */ + fun msTeams(sendToMsTeamsEmail: SendToMsTeamsEmail) = + msTeams(MsTeams.ofSendToMsTeamsEmail(sendToMsTeamsEmail)) + + /** + * Alias for calling [msTeams] with + * `MsTeams.ofSendToMsTeamsChannelId(sendToMsTeamsChannelId)`. + */ + fun msTeams(sendToMsTeamsChannelId: SendToMsTeamsChannelId) = + msTeams(MsTeams.ofSendToMsTeamsChannelId(sendToMsTeamsChannelId)) + + /** + * Alias for calling [msTeams] with + * `MsTeams.ofSendToMsTeamsConversationId(sendToMsTeamsConversationId)`. + */ + fun msTeams(sendToMsTeamsConversationId: SendToMsTeamsConversationId) = + msTeams(MsTeams.ofSendToMsTeamsConversationId(sendToMsTeamsConversationId)) + + /** + * Alias for calling [msTeams] with + * `MsTeams.ofSendToMsTeamsChannelName(sendToMsTeamsChannelName)`. + */ + fun msTeams(sendToMsTeamsChannelName: SendToMsTeamsChannelName) = + msTeams(MsTeams.ofSendToMsTeamsChannelName(sendToMsTeamsChannelName)) + + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * 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 nickname(nickname: String?) = nickname(JsonField.ofNullable(nickname)) + + /** Alias for calling [Builder.nickname] with `nickname.orElse(null)`. */ + fun nickname(nickname: Optional) = nickname(nickname.getOrNull()) + + /** + * Sets [Builder.nickname] to an arbitrary JSON value. + * + * You should usually call [Builder.nickname] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun nickname(nickname: JsonField) = apply { this.nickname = nickname } + + fun phoneNumber(phoneNumber: String?) = phoneNumber(JsonField.ofNullable(phoneNumber)) + + /** Alias for calling [Builder.phoneNumber] with `phoneNumber.orElse(null)`. */ + fun phoneNumber(phoneNumber: Optional) = phoneNumber(phoneNumber.getOrNull()) + + /** + * Sets [Builder.phoneNumber] to an arbitrary JSON value. + * + * You should usually call [Builder.phoneNumber] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun phoneNumber(phoneNumber: JsonField) = apply { this.phoneNumber = phoneNumber } + + fun phoneNumberVerified(phoneNumberVerified: Boolean?) = + phoneNumberVerified(JsonField.ofNullable(phoneNumberVerified)) + + /** + * Alias for [Builder.phoneNumberVerified]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun phoneNumberVerified(phoneNumberVerified: Boolean) = + phoneNumberVerified(phoneNumberVerified as Boolean?) + + /** + * Alias for calling [Builder.phoneNumberVerified] with `phoneNumberVerified.orElse(null)`. + */ + fun phoneNumberVerified(phoneNumberVerified: Optional) = + phoneNumberVerified(phoneNumberVerified.getOrNull()) + + /** + * Sets [Builder.phoneNumberVerified] to an arbitrary JSON value. + * + * You should usually call [Builder.phoneNumberVerified] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun phoneNumberVerified(phoneNumberVerified: JsonField) = apply { + this.phoneNumberVerified = phoneNumberVerified + } + + fun picture(picture: String?) = picture(JsonField.ofNullable(picture)) + + /** Alias for calling [Builder.picture] with `picture.orElse(null)`. */ + fun picture(picture: Optional) = picture(picture.getOrNull()) + + /** + * Sets [Builder.picture] to an arbitrary JSON value. + * + * You should usually call [Builder.picture] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun picture(picture: JsonField) = apply { this.picture = picture } + + fun preferredName(preferredName: String?) = + preferredName(JsonField.ofNullable(preferredName)) + + /** Alias for calling [Builder.preferredName] with `preferredName.orElse(null)`. */ + fun preferredName(preferredName: Optional) = + preferredName(preferredName.getOrNull()) + + /** + * Sets [Builder.preferredName] to an arbitrary JSON value. + * + * You should usually call [Builder.preferredName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun preferredName(preferredName: JsonField) = apply { + this.preferredName = preferredName + } + + fun profile(profile: String?) = profile(JsonField.ofNullable(profile)) + + /** Alias for calling [Builder.profile] with `profile.orElse(null)`. */ + fun profile(profile: Optional) = profile(profile.getOrNull()) + + /** + * Sets [Builder.profile] to an arbitrary JSON value. + * + * You should usually call [Builder.profile] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun profile(profile: JsonField) = apply { this.profile = profile } + + fun slack(slack: Slack?) = slack(JsonField.ofNullable(slack)) + + /** Alias for calling [Builder.slack] with `slack.orElse(null)`. */ + fun slack(slack: Optional) = slack(slack.getOrNull()) + + /** + * Sets [Builder.slack] to an arbitrary JSON value. + * + * You should usually call [Builder.slack] with a well-typed [Slack] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun slack(slack: JsonField) = apply { this.slack = slack } + + /** Alias for calling [slack] with `Slack.ofSendToSlackChannel(sendToSlackChannel)`. */ + fun slack(sendToSlackChannel: SendToSlackChannel) = + slack(Slack.ofSendToSlackChannel(sendToSlackChannel)) + + /** Alias for calling [slack] with `Slack.ofSendToSlackEmail(sendToSlackEmail)`. */ + fun slack(sendToSlackEmail: SendToSlackEmail) = + slack(Slack.ofSendToSlackEmail(sendToSlackEmail)) + + /** Alias for calling [slack] with `Slack.ofSendToSlackUserId(sendToSlackUserId)`. */ + fun slack(sendToSlackUserId: SendToSlackUserId) = + slack(Slack.ofSendToSlackUserId(sendToSlackUserId)) + + fun sub(sub: String?) = sub(JsonField.ofNullable(sub)) + + /** Alias for calling [Builder.sub] with `sub.orElse(null)`. */ + fun sub(sub: Optional) = sub(sub.getOrNull()) + + /** + * Sets [Builder.sub] to an arbitrary JSON value. + * + * You should usually call [Builder.sub] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun sub(sub: JsonField) = apply { this.sub = sub } + + fun targetArn(targetArn: String?) = targetArn(JsonField.ofNullable(targetArn)) + + /** Alias for calling [Builder.targetArn] with `targetArn.orElse(null)`. */ + fun targetArn(targetArn: Optional) = targetArn(targetArn.getOrNull()) + + /** + * Sets [Builder.targetArn] to an arbitrary JSON value. + * + * You should usually call [Builder.targetArn] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun targetArn(targetArn: JsonField) = apply { this.targetArn = targetArn } + + fun updatedAt(updatedAt: String?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [String] 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 website(website: String?) = website(JsonField.ofNullable(website)) + + /** Alias for calling [Builder.website] with `website.orElse(null)`. */ + fun website(website: Optional) = website(website.getOrNull()) + + /** + * Sets [Builder.website] to an arbitrary JSON value. + * + * You should usually call [Builder.website] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun website(website: JsonField) = apply { this.website = website } + + fun zoneinfo(zoneinfo: String?) = zoneinfo(JsonField.ofNullable(zoneinfo)) + + /** Alias for calling [Builder.zoneinfo] with `zoneinfo.orElse(null)`. */ + fun zoneinfo(zoneinfo: Optional) = zoneinfo(zoneinfo.getOrNull()) + + /** + * Sets [Builder.zoneinfo] to an arbitrary JSON value. + * + * You should usually call [Builder.zoneinfo] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun zoneinfo(zoneinfo: JsonField) = apply { this.zoneinfo = zoneinfo } + + 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 [UserProfile]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): UserProfile = + UserProfile( + address, + airship, + apn, + birthdate, + custom, + discord, + email, + emailVerified, + expo, + facebookPsid, + familyName, + firebaseToken, + gender, + givenName, + intercom, + locale, + middleName, + msTeams, + name, + nickname, + phoneNumber, + phoneNumberVerified, + picture, + preferredName, + profile, + slack, + sub, + targetArn, + updatedAt, + website, + zoneinfo, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UserProfile = apply { + if (validated) { + return@apply + } + + address().ifPresent { it.validate() } + airship().ifPresent { it.validate() } + apn() + birthdate() + custom().ifPresent { it.validate() } + discord().ifPresent { it.validate() } + email() + emailVerified() + expo().ifPresent { it.validate() } + facebookPsid() + familyName() + firebaseToken().ifPresent { it.validate() } + gender() + givenName() + intercom().ifPresent { it.validate() } + locale() + middleName() + msTeams().ifPresent { it.validate() } + name() + nickname() + phoneNumber() + phoneNumberVerified() + picture() + preferredName() + profile() + slack().ifPresent { it.validate() } + sub() + targetArn() + updatedAt() + website() + zoneinfo() + 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 = + (address.asKnown().getOrNull()?.validity() ?: 0) + + (airship.asKnown().getOrNull()?.validity() ?: 0) + + (if (apn.asKnown().isPresent) 1 else 0) + + (if (birthdate.asKnown().isPresent) 1 else 0) + + (custom.asKnown().getOrNull()?.validity() ?: 0) + + (discord.asKnown().getOrNull()?.validity() ?: 0) + + (if (email.asKnown().isPresent) 1 else 0) + + (if (emailVerified.asKnown().isPresent) 1 else 0) + + (expo.asKnown().getOrNull()?.validity() ?: 0) + + (if (facebookPsid.asKnown().isPresent) 1 else 0) + + (if (familyName.asKnown().isPresent) 1 else 0) + + (firebaseToken.asKnown().getOrNull()?.validity() ?: 0) + + (if (gender.asKnown().isPresent) 1 else 0) + + (if (givenName.asKnown().isPresent) 1 else 0) + + (intercom.asKnown().getOrNull()?.validity() ?: 0) + + (if (locale.asKnown().isPresent) 1 else 0) + + (if (middleName.asKnown().isPresent) 1 else 0) + + (msTeams.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (nickname.asKnown().isPresent) 1 else 0) + + (if (phoneNumber.asKnown().isPresent) 1 else 0) + + (if (phoneNumberVerified.asKnown().isPresent) 1 else 0) + + (if (picture.asKnown().isPresent) 1 else 0) + + (if (preferredName.asKnown().isPresent) 1 else 0) + + (if (profile.asKnown().isPresent) 1 else 0) + + (slack.asKnown().getOrNull()?.validity() ?: 0) + + (if (sub.asKnown().isPresent) 1 else 0) + + (if (targetArn.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (if (website.asKnown().isPresent) 1 else 0) + + (if (zoneinfo.asKnown().isPresent) 1 else 0) + + class Address + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val country: JsonField, + private val formatted: JsonField, + private val locality: JsonField, + private val postalCode: JsonField, + private val region: JsonField, + private val streetAddress: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("country") @ExcludeMissing country: JsonField = JsonMissing.of(), + @JsonProperty("formatted") + @ExcludeMissing + formatted: JsonField = JsonMissing.of(), + @JsonProperty("locality") + @ExcludeMissing + locality: JsonField = JsonMissing.of(), + @JsonProperty("postal_code") + @ExcludeMissing + postalCode: JsonField = JsonMissing.of(), + @JsonProperty("region") @ExcludeMissing region: JsonField = JsonMissing.of(), + @JsonProperty("street_address") + @ExcludeMissing + streetAddress: JsonField = JsonMissing.of(), + ) : this(country, formatted, locality, postalCode, region, streetAddress, 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 country(): String = country.getRequired("country") + + /** + * @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 formatted(): String = formatted.getRequired("formatted") + + /** + * @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 locality(): String = locality.getRequired("locality") + + /** + * @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 postalCode(): String = postalCode.getRequired("postal_code") + + /** + * @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 region(): String = region.getRequired("region") + + /** + * @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 streetAddress(): String = streetAddress.getRequired("street_address") + + /** + * Returns the raw JSON value of [country]. + * + * Unlike [country], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("country") @ExcludeMissing fun _country(): JsonField = country + + /** + * Returns the raw JSON value of [formatted]. + * + * Unlike [formatted], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("formatted") @ExcludeMissing fun _formatted(): JsonField = formatted + + /** + * Returns the raw JSON value of [locality]. + * + * Unlike [locality], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("locality") @ExcludeMissing fun _locality(): JsonField = locality + + /** + * Returns the raw JSON value of [postalCode]. + * + * Unlike [postalCode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("postal_code") + @ExcludeMissing + fun _postalCode(): JsonField = postalCode + + /** + * Returns the raw JSON value of [region]. + * + * Unlike [region], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("region") @ExcludeMissing fun _region(): JsonField = region + + /** + * Returns the raw JSON value of [streetAddress]. + * + * Unlike [streetAddress], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("street_address") + @ExcludeMissing + fun _streetAddress(): JsonField = streetAddress + + @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 [Address]. + * + * The following fields are required: + * ```java + * .country() + * .formatted() + * .locality() + * .postalCode() + * .region() + * .streetAddress() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Address]. */ + class Builder internal constructor() { + + private var country: JsonField? = null + private var formatted: JsonField? = null + private var locality: JsonField? = null + private var postalCode: JsonField? = null + private var region: JsonField? = null + private var streetAddress: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(address: Address) = apply { + country = address.country + formatted = address.formatted + locality = address.locality + postalCode = address.postalCode + region = address.region + streetAddress = address.streetAddress + additionalProperties = address.additionalProperties.toMutableMap() + } + + fun country(country: String) = country(JsonField.of(country)) + + /** + * Sets [Builder.country] to an arbitrary JSON value. + * + * You should usually call [Builder.country] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun country(country: JsonField) = apply { this.country = country } + + fun formatted(formatted: String) = formatted(JsonField.of(formatted)) + + /** + * Sets [Builder.formatted] to an arbitrary JSON value. + * + * You should usually call [Builder.formatted] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun formatted(formatted: JsonField) = apply { this.formatted = formatted } + + fun locality(locality: String) = locality(JsonField.of(locality)) + + /** + * Sets [Builder.locality] to an arbitrary JSON value. + * + * You should usually call [Builder.locality] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun locality(locality: JsonField) = apply { this.locality = locality } + + fun postalCode(postalCode: String) = postalCode(JsonField.of(postalCode)) + + /** + * Sets [Builder.postalCode] to an arbitrary JSON value. + * + * You should usually call [Builder.postalCode] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun postalCode(postalCode: JsonField) = apply { this.postalCode = postalCode } + + fun region(region: String) = region(JsonField.of(region)) + + /** + * Sets [Builder.region] to an arbitrary JSON value. + * + * You should usually call [Builder.region] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun region(region: JsonField) = apply { this.region = region } + + fun streetAddress(streetAddress: String) = streetAddress(JsonField.of(streetAddress)) + + /** + * Sets [Builder.streetAddress] to an arbitrary JSON value. + * + * You should usually call [Builder.streetAddress] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun streetAddress(streetAddress: JsonField) = apply { + this.streetAddress = streetAddress + } + + 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 [Address]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .country() + * .formatted() + * .locality() + * .postalCode() + * .region() + * .streetAddress() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Address = + Address( + checkRequired("country", country), + checkRequired("formatted", formatted), + checkRequired("locality", locality), + checkRequired("postalCode", postalCode), + checkRequired("region", region), + checkRequired("streetAddress", streetAddress), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Address = apply { + if (validated) { + return@apply + } + + country() + formatted() + locality() + postalCode() + region() + streetAddress() + 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 (country.asKnown().isPresent) 1 else 0) + + (if (formatted.asKnown().isPresent) 1 else 0) + + (if (locality.asKnown().isPresent) 1 else 0) + + (if (postalCode.asKnown().isPresent) 1 else 0) + + (if (region.asKnown().isPresent) 1 else 0) + + (if (streetAddress.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Address && + country == other.country && + formatted == other.formatted && + locality == other.locality && + postalCode == other.postalCode && + region == other.region && + streetAddress == other.streetAddress && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + country, + formatted, + locality, + postalCode, + region, + streetAddress, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Address{country=$country, formatted=$formatted, locality=$locality, postalCode=$postalCode, region=$region, streetAddress=$streetAddress, additionalProperties=$additionalProperties}" + } + + /** + * A free form object. Due to a limitation of the API Explorer, you can only enter string + * key/values below, but this API accepts more complex object structures. + */ + class Custom + @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 [Custom]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Custom]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(custom: Custom) = apply { + additionalProperties = custom.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 [Custom]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Custom = Custom(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Custom = 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 Custom && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Custom{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UserProfile && + address == other.address && + airship == other.airship && + apn == other.apn && + birthdate == other.birthdate && + custom == other.custom && + discord == other.discord && + email == other.email && + emailVerified == other.emailVerified && + expo == other.expo && + facebookPsid == other.facebookPsid && + familyName == other.familyName && + firebaseToken == other.firebaseToken && + gender == other.gender && + givenName == other.givenName && + intercom == other.intercom && + locale == other.locale && + middleName == other.middleName && + msTeams == other.msTeams && + name == other.name && + nickname == other.nickname && + phoneNumber == other.phoneNumber && + phoneNumberVerified == other.phoneNumberVerified && + picture == other.picture && + preferredName == other.preferredName && + profile == other.profile && + slack == other.slack && + sub == other.sub && + targetArn == other.targetArn && + updatedAt == other.updatedAt && + website == other.website && + zoneinfo == other.zoneinfo && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + address, + airship, + apn, + birthdate, + custom, + discord, + email, + emailVerified, + expo, + facebookPsid, + familyName, + firebaseToken, + gender, + givenName, + intercom, + locale, + middleName, + msTeams, + name, + nickname, + phoneNumber, + phoneNumberVerified, + picture, + preferredName, + profile, + slack, + sub, + targetArn, + updatedAt, + website, + zoneinfo, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UserProfile{address=$address, airship=$airship, apn=$apn, birthdate=$birthdate, custom=$custom, discord=$discord, email=$email, emailVerified=$emailVerified, expo=$expo, facebookPsid=$facebookPsid, familyName=$familyName, firebaseToken=$firebaseToken, gender=$gender, givenName=$givenName, intercom=$intercom, locale=$locale, middleName=$middleName, msTeams=$msTeams, name=$name, nickname=$nickname, phoneNumber=$phoneNumber, phoneNumberVerified=$phoneNumberVerified, picture=$picture, preferredName=$preferredName, profile=$profile, slack=$slack, sub=$sub, targetArn=$targetArn, updatedAt=$updatedAt, website=$website, zoneinfo=$zoneinfo, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/UserProfileFirebaseToken.kt b/courier-java-core/src/main/kotlin/com/courier/models/UserProfileFirebaseToken.kt new file mode 100644 index 00000000..3f825320 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/UserProfileFirebaseToken.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.BaseDeserializer +import com.courier.core.BaseSerializer +import com.courier.core.JsonValue +import com.courier.core.allMaxBy +import com.courier.core.getOrThrow +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +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.Objects +import java.util.Optional + +@JsonDeserialize(using = UserProfileFirebaseToken.Deserializer::class) +@JsonSerialize(using = UserProfileFirebaseToken.Serializer::class) +class UserProfileFirebaseToken +private constructor( + private val string: String? = null, + private val strings: List? = null, + private val _json: JsonValue? = null, +) { + + fun string(): Optional = Optional.ofNullable(string) + + fun strings(): Optional> = Optional.ofNullable(strings) + + fun isString(): Boolean = string != null + + fun isStrings(): Boolean = strings != null + + fun asString(): String = string.getOrThrow("string") + + fun asStrings(): List = strings.getOrThrow("strings") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + strings != null -> visitor.visitStrings(strings) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): UserProfileFirebaseToken = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitStrings(strings: List) {} + } + ) + 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 = + accept( + object : Visitor { + override fun visitString(string: String) = 1 + + override fun visitStrings(strings: List) = strings.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UserProfileFirebaseToken && + string == other.string && + strings == other.strings + } + + override fun hashCode(): Int = Objects.hash(string, strings) + + override fun toString(): String = + when { + string != null -> "UserProfileFirebaseToken{string=$string}" + strings != null -> "UserProfileFirebaseToken{strings=$strings}" + _json != null -> "UserProfileFirebaseToken{_unknown=$_json}" + else -> throw IllegalStateException("Invalid UserProfileFirebaseToken") + } + + companion object { + + @JvmStatic fun ofString(string: String) = UserProfileFirebaseToken(string = string) + + @JvmStatic + fun ofStrings(strings: List) = + UserProfileFirebaseToken(strings = strings.toImmutable()) + } + + /** + * An interface that defines how to map each variant of [UserProfileFirebaseToken] to a value of + * type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitStrings(strings: List): T + + /** + * Maps an unknown variant of [UserProfileFirebaseToken] to a value of type [T]. + * + * An instance of [UserProfileFirebaseToken] 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. + */ + fun unknown(json: JsonValue?): T { + throw CourierInvalidDataException("Unknown UserProfileFirebaseToken: $json") + } + } + + internal class Deserializer : + BaseDeserializer(UserProfileFirebaseToken::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): UserProfileFirebaseToken { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + UserProfileFirebaseToken(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>())?.let { + UserProfileFirebaseToken(strings = 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 object). + 0 -> UserProfileFirebaseToken(_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(UserProfileFirebaseToken::class) { + + override fun serialize( + value: UserProfileFirebaseToken, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.strings != null -> generator.writeObject(value.strings) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid UserProfileFirebaseToken") + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/WebhookAuthMode.kt b/courier-java-core/src/main/kotlin/com/courier/models/WebhookAuthMode.kt new file mode 100644 index 00000000..baec95bb --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/WebhookAuthMode.kt @@ -0,0 +1,139 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.Enum +import com.courier.core.JsonField +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +class WebhookAuthMode @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 NONE = of("none") + + @JvmField val BASIC = of("basic") + + @JvmField val BEARER = of("bearer") + + @JvmStatic fun of(value: String) = WebhookAuthMode(JsonField.of(value)) + } + + /** An enum containing [WebhookAuthMode]'s known values. */ + enum class Known { + NONE, + BASIC, + BEARER, + } + + /** + * An enum containing [WebhookAuthMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [WebhookAuthMode] 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 { + NONE, + BASIC, + BEARER, + /** + * An enum member indicating that [WebhookAuthMode] 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) { + NONE -> Value.NONE + BASIC -> Value.BASIC + BEARER -> Value.BEARER + 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) { + NONE -> Known.NONE + BASIC -> Known.BASIC + BEARER -> Known.BEARER + else -> throw CourierInvalidDataException("Unknown WebhookAuthMode: $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(): WebhookAuthMode = 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 WebhookAuthMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/WebhookAuthentication.kt b/courier-java-core/src/main/kotlin/com/courier/models/WebhookAuthentication.kt new file mode 100644 index 00000000..9883e9fa --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/WebhookAuthentication.kt @@ -0,0 +1,291 @@ +// 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.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 + +class WebhookAuthentication +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val mode: JsonField, + private val token: JsonField, + private val password: JsonField, + private val username: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("mode") @ExcludeMissing mode: JsonField = JsonMissing.of(), + @JsonProperty("token") @ExcludeMissing token: JsonField = JsonMissing.of(), + @JsonProperty("password") @ExcludeMissing password: JsonField = JsonMissing.of(), + @JsonProperty("username") @ExcludeMissing username: JsonField = JsonMissing.of(), + ) : this(mode, token, password, username, mutableMapOf()) + + /** + * The authentication mode to use. Defaults to 'none' if not specified. + * + * @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 mode(): WebhookAuthMode = mode.getRequired("mode") + + /** + * Token for bearer authentication. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun token(): Optional = token.getOptional("token") + + /** + * Password for basic authentication. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun password(): Optional = password.getOptional("password") + + /** + * Username for basic authentication. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun username(): Optional = username.getOptional("username") + + /** + * Returns the raw JSON value of [mode]. + * + * Unlike [mode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mode") @ExcludeMissing fun _mode(): JsonField = mode + + /** + * Returns the raw JSON value of [token]. + * + * Unlike [token], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token + + /** + * Returns the raw JSON value of [password]. + * + * Unlike [password], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("password") @ExcludeMissing fun _password(): JsonField = password + + /** + * Returns the raw JSON value of [username]. + * + * Unlike [username], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("username") @ExcludeMissing fun _username(): JsonField = username + + @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 [WebhookAuthentication]. + * + * The following fields are required: + * ```java + * .mode() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [WebhookAuthentication]. */ + class Builder internal constructor() { + + private var mode: JsonField? = null + private var token: JsonField = JsonMissing.of() + private var password: JsonField = JsonMissing.of() + private var username: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(webhookAuthentication: WebhookAuthentication) = apply { + mode = webhookAuthentication.mode + token = webhookAuthentication.token + password = webhookAuthentication.password + username = webhookAuthentication.username + additionalProperties = webhookAuthentication.additionalProperties.toMutableMap() + } + + /** The authentication mode to use. Defaults to 'none' if not specified. */ + fun mode(mode: WebhookAuthMode) = mode(JsonField.of(mode)) + + /** + * Sets [Builder.mode] to an arbitrary JSON value. + * + * You should usually call [Builder.mode] with a well-typed [WebhookAuthMode] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun mode(mode: JsonField) = apply { this.mode = mode } + + /** Token for bearer authentication. */ + fun token(token: String?) = token(JsonField.ofNullable(token)) + + /** Alias for calling [Builder.token] with `token.orElse(null)`. */ + fun token(token: Optional) = token(token.getOrNull()) + + /** + * Sets [Builder.token] to an arbitrary JSON value. + * + * You should usually call [Builder.token] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun token(token: JsonField) = apply { this.token = token } + + /** Password for basic authentication. */ + fun password(password: String?) = password(JsonField.ofNullable(password)) + + /** Alias for calling [Builder.password] with `password.orElse(null)`. */ + fun password(password: Optional) = password(password.getOrNull()) + + /** + * Sets [Builder.password] to an arbitrary JSON value. + * + * You should usually call [Builder.password] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun password(password: JsonField) = apply { this.password = password } + + /** Username for basic authentication. */ + fun username(username: String?) = username(JsonField.ofNullable(username)) + + /** Alias for calling [Builder.username] with `username.orElse(null)`. */ + fun username(username: Optional) = username(username.getOrNull()) + + /** + * Sets [Builder.username] to an arbitrary JSON value. + * + * You should usually call [Builder.username] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun username(username: JsonField) = apply { this.username = username } + + 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 [WebhookAuthentication]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .mode() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): WebhookAuthentication = + WebhookAuthentication( + checkRequired("mode", mode), + token, + password, + username, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): WebhookAuthentication = apply { + if (validated) { + return@apply + } + + mode().validate() + token() + password() + username() + 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 = + (mode.asKnown().getOrNull()?.validity() ?: 0) + + (if (token.asKnown().isPresent) 1 else 0) + + (if (password.asKnown().isPresent) 1 else 0) + + (if (username.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WebhookAuthentication && + mode == other.mode && + token == other.token && + password == other.password && + username == other.username && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(mode, token, password, username, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "WebhookAuthentication{mode=$mode, token=$token, password=$password, username=$username, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/WebhookMethod.kt b/courier-java-core/src/main/kotlin/com/courier/models/WebhookMethod.kt new file mode 100644 index 00000000..582cf21a --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/WebhookMethod.kt @@ -0,0 +1,132 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.Enum +import com.courier.core.JsonField +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +class WebhookMethod @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 POST = of("POST") + + @JvmField val PUT = of("PUT") + + @JvmStatic fun of(value: String) = WebhookMethod(JsonField.of(value)) + } + + /** An enum containing [WebhookMethod]'s known values. */ + enum class Known { + POST, + PUT, + } + + /** + * An enum containing [WebhookMethod]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [WebhookMethod] 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 { + POST, + PUT, + /** + * An enum member indicating that [WebhookMethod] 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) { + POST -> Value.POST + PUT -> Value.PUT + 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) { + POST -> Known.POST + PUT -> Known.PUT + else -> throw CourierInvalidDataException("Unknown WebhookMethod: $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(): WebhookMethod = 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 WebhookMethod && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/WebhookProfile.kt b/courier-java-core/src/main/kotlin/com/courier/models/WebhookProfile.kt new file mode 100644 index 00000000..eba2a34d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/WebhookProfile.kt @@ -0,0 +1,446 @@ +// 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.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 + +class WebhookProfile +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val url: JsonField, + private val authentication: JsonField, + private val headers: JsonField, + private val method: JsonField, + private val profile: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + @JsonProperty("authentication") + @ExcludeMissing + authentication: JsonField = JsonMissing.of(), + @JsonProperty("headers") @ExcludeMissing headers: JsonField = JsonMissing.of(), + @JsonProperty("method") @ExcludeMissing method: JsonField = JsonMissing.of(), + @JsonProperty("profile") + @ExcludeMissing + profile: JsonField = JsonMissing.of(), + ) : this(url, authentication, headers, method, profile, mutableMapOf()) + + /** + * The URL to send the webhook request to. + * + * @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 url(): String = url.getRequired("url") + + /** + * Authentication configuration for the webhook request. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun authentication(): Optional = + authentication.getOptional("authentication") + + /** + * Custom headers to include in the webhook request. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * The HTTP method to use for the webhook request. Defaults to POST if not specified. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun method(): Optional = method.getOptional("method") + + /** + * Specifies what profile information is included in the request payload. Defaults to 'limited' + * if not specified. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun profile(): Optional = profile.getOptional("profile") + + /** + * Returns the raw JSON value of [url]. + * + * Unlike [url], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url + + /** + * Returns the raw JSON value of [authentication]. + * + * Unlike [authentication], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("authentication") + @ExcludeMissing + fun _authentication(): JsonField = authentication + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("headers") @ExcludeMissing fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [method]. + * + * Unlike [method], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("method") @ExcludeMissing fun _method(): JsonField = method + + /** + * Returns the raw JSON value of [profile]. + * + * Unlike [profile], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("profile") @ExcludeMissing fun _profile(): JsonField = profile + + @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 [WebhookProfile]. + * + * The following fields are required: + * ```java + * .url() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [WebhookProfile]. */ + class Builder internal constructor() { + + private var url: JsonField? = null + private var authentication: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var method: JsonField = JsonMissing.of() + private var profile: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(webhookProfile: WebhookProfile) = apply { + url = webhookProfile.url + authentication = webhookProfile.authentication + headers = webhookProfile.headers + method = webhookProfile.method + profile = webhookProfile.profile + additionalProperties = webhookProfile.additionalProperties.toMutableMap() + } + + /** The URL to send the webhook request to. */ + fun url(url: String) = url(JsonField.of(url)) + + /** + * Sets [Builder.url] to an arbitrary JSON value. + * + * You should usually call [Builder.url] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun url(url: JsonField) = apply { this.url = url } + + /** Authentication configuration for the webhook request. */ + fun authentication(authentication: WebhookAuthentication?) = + authentication(JsonField.ofNullable(authentication)) + + /** Alias for calling [Builder.authentication] with `authentication.orElse(null)`. */ + fun authentication(authentication: Optional) = + authentication(authentication.getOrNull()) + + /** + * Sets [Builder.authentication] to an arbitrary JSON value. + * + * You should usually call [Builder.authentication] with a well-typed + * [WebhookAuthentication] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun authentication(authentication: JsonField) = apply { + this.authentication = authentication + } + + /** Custom headers to include in the webhook request. */ + fun headers(headers: Headers?) = headers(JsonField.ofNullable(headers)) + + /** Alias for calling [Builder.headers] with `headers.orElse(null)`. */ + fun headers(headers: Optional) = headers(headers.getOrNull()) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + /** The HTTP method to use for the webhook request. Defaults to POST if not specified. */ + fun method(method: WebhookMethod?) = method(JsonField.ofNullable(method)) + + /** Alias for calling [Builder.method] with `method.orElse(null)`. */ + fun method(method: Optional) = method(method.getOrNull()) + + /** + * Sets [Builder.method] to an arbitrary JSON value. + * + * You should usually call [Builder.method] with a well-typed [WebhookMethod] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun method(method: JsonField) = apply { this.method = method } + + /** + * Specifies what profile information is included in the request payload. Defaults to + * 'limited' if not specified. + */ + fun profile(profile: WebhookProfileType?) = profile(JsonField.ofNullable(profile)) + + /** Alias for calling [Builder.profile] with `profile.orElse(null)`. */ + fun profile(profile: Optional) = profile(profile.getOrNull()) + + /** + * Sets [Builder.profile] to an arbitrary JSON value. + * + * You should usually call [Builder.profile] with a well-typed [WebhookProfileType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun profile(profile: JsonField) = apply { this.profile = profile } + + 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 [WebhookProfile]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .url() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): WebhookProfile = + WebhookProfile( + checkRequired("url", url), + authentication, + headers, + method, + profile, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): WebhookProfile = apply { + if (validated) { + return@apply + } + + url() + authentication().ifPresent { it.validate() } + headers().ifPresent { it.validate() } + method().ifPresent { it.validate() } + profile().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 (url.asKnown().isPresent) 1 else 0) + + (authentication.asKnown().getOrNull()?.validity() ?: 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (method.asKnown().getOrNull()?.validity() ?: 0) + + (profile.asKnown().getOrNull()?.validity() ?: 0) + + /** Custom headers to include in the webhook request. */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Headers = 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 Headers && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WebhookProfile && + url == other.url && + authentication == other.authentication && + headers == other.headers && + method == other.method && + profile == other.profile && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(url, authentication, headers, method, profile, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "WebhookProfile{url=$url, authentication=$authentication, headers=$headers, method=$method, profile=$profile, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/WebhookProfileType.kt b/courier-java-core/src/main/kotlin/com/courier/models/WebhookProfileType.kt new file mode 100644 index 00000000..b6483a41 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/WebhookProfileType.kt @@ -0,0 +1,134 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.Enum +import com.courier.core.JsonField +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +class WebhookProfileType @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 LIMITED = of("limited") + + @JvmField val EXPANDED = of("expanded") + + @JvmStatic fun of(value: String) = WebhookProfileType(JsonField.of(value)) + } + + /** An enum containing [WebhookProfileType]'s known values. */ + enum class Known { + LIMITED, + EXPANDED, + } + + /** + * An enum containing [WebhookProfileType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [WebhookProfileType] 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 { + LIMITED, + EXPANDED, + /** + * An enum member indicating that [WebhookProfileType] 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) { + LIMITED -> Value.LIMITED + EXPANDED -> Value.EXPANDED + 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) { + LIMITED -> Known.LIMITED + EXPANDED -> Known.EXPANDED + else -> throw CourierInvalidDataException("Unknown WebhookProfileType: $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(): WebhookProfileType = 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 WebhookProfileType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/WebhookRecipient.kt b/courier-java-core/src/main/kotlin/com/courier/models/WebhookRecipient.kt new file mode 100644 index 00000000..52893c35 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/WebhookRecipient.kt @@ -0,0 +1,172 @@ +// 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.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 + +/** Send via webhook */ +class WebhookRecipient +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val webhook: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("webhook") + @ExcludeMissing + webhook: JsonField = JsonMissing.of() + ) : this(webhook, 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 webhook(): WebhookProfile = webhook.getRequired("webhook") + + /** + * Returns the raw JSON value of [webhook]. + * + * Unlike [webhook], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("webhook") @ExcludeMissing fun _webhook(): JsonField = webhook + + @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 [WebhookRecipient]. + * + * The following fields are required: + * ```java + * .webhook() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [WebhookRecipient]. */ + class Builder internal constructor() { + + private var webhook: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(webhookRecipient: WebhookRecipient) = apply { + webhook = webhookRecipient.webhook + additionalProperties = webhookRecipient.additionalProperties.toMutableMap() + } + + fun webhook(webhook: WebhookProfile) = webhook(JsonField.of(webhook)) + + /** + * Sets [Builder.webhook] to an arbitrary JSON value. + * + * You should usually call [Builder.webhook] with a well-typed [WebhookProfile] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun webhook(webhook: JsonField) = apply { this.webhook = webhook } + + 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 [WebhookRecipient]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .webhook() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): WebhookRecipient = + WebhookRecipient(checkRequired("webhook", webhook), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): WebhookRecipient = apply { + if (validated) { + return@apply + } + + webhook().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 = (webhook.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WebhookRecipient && + webhook == other.webhook && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(webhook, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "WebhookRecipient{webhook=$webhook, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/audiences/Audience.kt b/courier-java-core/src/main/kotlin/com/courier/models/audiences/Audience.kt index 433c3f28..4cdf514a 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/audiences/Audience.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/audiences/Audience.kt @@ -223,6 +223,14 @@ private constructor( */ fun filter(filter: JsonField) = apply { this.filter = filter } + /** Alias for calling [filter] with `Filter.ofSingleFilterConfig(singleFilterConfig)`. */ + fun filter(singleFilterConfig: SingleFilterConfig) = + filter(Filter.ofSingleFilterConfig(singleFilterConfig)) + + /** Alias for calling [filter] with `Filter.ofNestedFilterConfig(nestedFilterConfig)`. */ + fun filter(nestedFilterConfig: NestedFilterConfig) = + filter(Filter.ofNestedFilterConfig(nestedFilterConfig)) + /** The name of the audience */ fun name(name: String) = name(JsonField.of(name)) diff --git a/courier-java-core/src/main/kotlin/com/courier/models/audiences/AudienceUpdateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/audiences/AudienceUpdateParams.kt index fef71921..415505bb 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/audiences/AudienceUpdateParams.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/audiences/AudienceUpdateParams.kt @@ -154,6 +154,16 @@ private constructor( */ fun filter(filter: JsonField) = apply { body.filter(filter) } + /** Alias for calling [filter] with `Filter.ofSingleFilterConfig(singleFilterConfig)`. */ + fun filter(singleFilterConfig: SingleFilterConfig) = apply { + body.filter(singleFilterConfig) + } + + /** Alias for calling [filter] with `Filter.ofNestedFilterConfig(nestedFilterConfig)`. */ + fun filter(nestedFilterConfig: NestedFilterConfig) = apply { + body.filter(nestedFilterConfig) + } + /** The name of the audience */ fun name(name: String?) = apply { body.name(name) } @@ -442,6 +452,18 @@ private constructor( */ fun filter(filter: JsonField) = apply { this.filter = filter } + /** + * Alias for calling [filter] with `Filter.ofSingleFilterConfig(singleFilterConfig)`. + */ + fun filter(singleFilterConfig: SingleFilterConfig) = + filter(Filter.ofSingleFilterConfig(singleFilterConfig)) + + /** + * Alias for calling [filter] with `Filter.ofNestedFilterConfig(nestedFilterConfig)`. + */ + fun filter(nestedFilterConfig: NestedFilterConfig) = + filter(Filter.ofNestedFilterConfig(nestedFilterConfig)) + /** The name of the audience */ fun name(name: String?) = name(JsonField.ofNullable(name)) diff --git a/courier-java-core/src/main/kotlin/com/courier/models/audiences/Filter.kt b/courier-java-core/src/main/kotlin/com/courier/models/audiences/Filter.kt index caa5f4ff..14dab282 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/audiences/Filter.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/audiences/Filter.kt @@ -2,201 +2,59 @@ package com.courier.models.audiences -import com.courier.core.Enum -import com.courier.core.ExcludeMissing -import com.courier.core.JsonField -import com.courier.core.JsonMissing +import com.courier.core.BaseDeserializer +import com.courier.core.BaseSerializer import com.courier.core.JsonValue -import com.courier.core.checkRequired +import com.courier.core.allMaxBy +import com.courier.core.getOrThrow 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 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.Objects -import kotlin.jvm.optionals.getOrNull +import java.util.Optional +/** A single filter to use for filtering */ +@JsonDeserialize(using = Filter.Deserializer::class) +@JsonSerialize(using = Filter.Serializer::class) class Filter -@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val operator: JsonField, - private val path: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, + private val singleFilterConfig: SingleFilterConfig? = null, + private val nestedFilterConfig: NestedFilterConfig? = null, + private val _json: JsonValue? = null, ) { - @JsonCreator - private constructor( - @JsonProperty("operator") @ExcludeMissing operator: JsonField = JsonMissing.of(), - @JsonProperty("path") @ExcludeMissing path: JsonField = JsonMissing.of(), - @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), - ) : this(operator, path, value, mutableMapOf()) + /** A single filter to use for filtering */ + fun singleFilterConfig(): Optional = Optional.ofNullable(singleFilterConfig) - /** - * The operator to use for filtering - * - * @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 operator(): Operator = operator.getRequired("operator") - - /** - * The attribe name from profile whose value will be operated against the filter 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 path(): String = path.getRequired("path") - - /** - * The value to use for filtering - * - * @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 value(): String = value.getRequired("value") - - /** - * Returns the raw JSON value of [operator]. - * - * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator - - /** - * Returns the raw JSON value of [path]. - * - * Unlike [path], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @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 [Filter]. - * - * The following fields are required: - * ```java - * .operator() - * .path() - * .value() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Filter]. */ - class Builder internal constructor() { - - private var operator: JsonField? = null - private var path: JsonField? = null - private var value: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(filter: Filter) = apply { - operator = filter.operator - path = filter.path - value = filter.value - additionalProperties = filter.additionalProperties.toMutableMap() - } - - /** The operator to use for filtering */ - fun operator(operator: Operator) = operator(JsonField.of(operator)) - - /** - * Sets [Builder.operator] to an arbitrary JSON value. - * - * You should usually call [Builder.operator] with a well-typed [Operator] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun operator(operator: JsonField) = apply { this.operator = operator } - - /** The attribe name from profile whose value will be operated against the filter value */ - fun path(path: String) = path(JsonField.of(path)) - - /** - * Sets [Builder.path] to an arbitrary JSON value. - * - * You should usually call [Builder.path] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun path(path: JsonField) = apply { this.path = path } - - /** The value to use for filtering */ - fun value(value: String) = value(JsonField.of(value)) + /** The operator to use for filtering */ + fun nestedFilterConfig(): Optional = Optional.ofNullable(nestedFilterConfig) - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } + fun isSingleFilterConfig(): Boolean = singleFilterConfig != null - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun isNestedFilterConfig(): Boolean = nestedFilterConfig != null - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** A single filter to use for filtering */ + fun asSingleFilterConfig(): SingleFilterConfig = + singleFilterConfig.getOrThrow("singleFilterConfig") - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** The operator to use for filtering */ + fun asNestedFilterConfig(): NestedFilterConfig = + nestedFilterConfig.getOrThrow("nestedFilterConfig") - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun _json(): Optional = Optional.ofNullable(_json) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) + fun accept(visitor: Visitor): T = + when { + singleFilterConfig != null -> visitor.visitSingleFilterConfig(singleFilterConfig) + nestedFilterConfig != null -> visitor.visitNestedFilterConfig(nestedFilterConfig) + else -> visitor.unknown(_json) } - /** - * Returns an immutable instance of [Filter]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .operator() - * .path() - * .value() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Filter = - Filter( - checkRequired("operator", operator), - checkRequired("path", path), - checkRequired("value", value), - additionalProperties.toMutableMap(), - ) - } - private var validated: Boolean = false fun validate(): Filter = apply { @@ -204,9 +62,17 @@ private constructor( return@apply } - operator().validate() - path() - value() + accept( + object : Visitor { + override fun visitSingleFilterConfig(singleFilterConfig: SingleFilterConfig) { + singleFilterConfig.validate() + } + + override fun visitNestedFilterConfig(nestedFilterConfig: NestedFilterConfig) { + nestedFilterConfig.validate() + } + } + ) validated = true } @@ -225,230 +91,116 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (operator.asKnown().getOrNull()?.validity() ?: 0) + - (if (path.asKnown().isPresent) 1 else 0) + - (if (value.asKnown().isPresent) 1 else 0) - - /** The operator to use for filtering */ - class Operator @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 ENDS_WITH = of("ENDS_WITH") + accept( + object : Visitor { + override fun visitSingleFilterConfig(singleFilterConfig: SingleFilterConfig) = + singleFilterConfig.validity() - @JvmField val EQ = of("EQ") + override fun visitNestedFilterConfig(nestedFilterConfig: NestedFilterConfig) = + nestedFilterConfig.validity() - @JvmField val EXISTS = of("EXISTS") - - @JvmField val GT = of("GT") - - @JvmField val GTE = of("GTE") - - @JvmField val INCLUDES = of("INCLUDES") - - @JvmField val IS_AFTER = of("IS_AFTER") - - @JvmField val IS_BEFORE = of("IS_BEFORE") - - @JvmField val LT = of("LT") - - @JvmField val LTE = of("LTE") + override fun unknown(json: JsonValue?) = 0 + } + ) - @JvmField val NEQ = of("NEQ") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - @JvmField val OMIT = of("OMIT") + return other is Filter && + singleFilterConfig == other.singleFilterConfig && + nestedFilterConfig == other.nestedFilterConfig + } - @JvmField val STARTS_WITH = of("STARTS_WITH") + override fun hashCode(): Int = Objects.hash(singleFilterConfig, nestedFilterConfig) - @JvmField val AND = of("AND") + override fun toString(): String = + when { + singleFilterConfig != null -> "Filter{singleFilterConfig=$singleFilterConfig}" + nestedFilterConfig != null -> "Filter{nestedFilterConfig=$nestedFilterConfig}" + _json != null -> "Filter{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Filter") + } - @JvmField val OR = of("OR") + companion object { - @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) - } + /** A single filter to use for filtering */ + @JvmStatic + fun ofSingleFilterConfig(singleFilterConfig: SingleFilterConfig) = + Filter(singleFilterConfig = singleFilterConfig) - /** An enum containing [Operator]'s known values. */ - enum class Known { - ENDS_WITH, - EQ, - EXISTS, - GT, - GTE, - INCLUDES, - IS_AFTER, - IS_BEFORE, - LT, - LTE, - NEQ, - OMIT, - STARTS_WITH, - AND, - OR, - } + /** The operator to use for filtering */ + @JvmStatic + fun ofNestedFilterConfig(nestedFilterConfig: NestedFilterConfig) = + Filter(nestedFilterConfig = nestedFilterConfig) + } - /** - * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Operator] 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 { - ENDS_WITH, - EQ, - EXISTS, - GT, - GTE, - INCLUDES, - IS_AFTER, - IS_BEFORE, - LT, - LTE, - NEQ, - OMIT, - STARTS_WITH, - AND, - OR, - /** An enum member indicating that [Operator] was instantiated with an unknown value. */ - _UNKNOWN, - } + /** An interface that defines how to map each variant of [Filter] to a value of type [T]. */ + interface Visitor { - /** - * 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) { - ENDS_WITH -> Value.ENDS_WITH - EQ -> Value.EQ - EXISTS -> Value.EXISTS - GT -> Value.GT - GTE -> Value.GTE - INCLUDES -> Value.INCLUDES - IS_AFTER -> Value.IS_AFTER - IS_BEFORE -> Value.IS_BEFORE - LT -> Value.LT - LTE -> Value.LTE - NEQ -> Value.NEQ - OMIT -> Value.OMIT - STARTS_WITH -> Value.STARTS_WITH - AND -> Value.AND - OR -> Value.OR - else -> Value._UNKNOWN - } + /** A single filter to use for filtering */ + fun visitSingleFilterConfig(singleFilterConfig: SingleFilterConfig): T - /** - * 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) { - ENDS_WITH -> Known.ENDS_WITH - EQ -> Known.EQ - EXISTS -> Known.EXISTS - GT -> Known.GT - GTE -> Known.GTE - INCLUDES -> Known.INCLUDES - IS_AFTER -> Known.IS_AFTER - IS_BEFORE -> Known.IS_BEFORE - LT -> Known.LT - LTE -> Known.LTE - NEQ -> Known.NEQ - OMIT -> Known.OMIT - STARTS_WITH -> Known.STARTS_WITH - AND -> Known.AND - OR -> Known.OR - else -> throw CourierInvalidDataException("Unknown Operator: $value") - } + /** The operator to use for filtering */ + fun visitNestedFilterConfig(nestedFilterConfig: NestedFilterConfig): T /** - * Returns this class instance's primitive wire representation. + * Maps an unknown variant of [Filter] to a value of type [T]. * - * This differs from the [toString] method because that method is primarily for debugging - * and generally doesn't throw. + * An instance of [Filter] 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 if this class instance's value does not have the - * expected primitive type. + * @throws CourierInvalidDataException in the default implementation. */ - fun asString(): String = - _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } - - private var validated: Boolean = false - - fun validate(): Operator = apply { - if (validated) { - return@apply - } - - known() - validated = true + fun unknown(json: JsonValue?): T { + throw CourierInvalidDataException("Unknown Filter: $json") } + } - 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 + internal class Deserializer : BaseDeserializer(Filter::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Filter { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Filter(singleFilterConfig = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Filter(nestedFilterConfig = 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 -> Filter(_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() } - - return other is Operator && value == other.value } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + internal class Serializer : BaseSerializer(Filter::class) { + + override fun serialize( + value: Filter, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.singleFilterConfig != null -> generator.writeObject(value.singleFilterConfig) + value.nestedFilterConfig != null -> generator.writeObject(value.nestedFilterConfig) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Filter") + } } - - return other is Filter && - operator == other.operator && - path == other.path && - value == other.value && - additionalProperties == other.additionalProperties } - - private val hashCode: Int by lazy { Objects.hash(operator, path, value, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Filter{operator=$operator, path=$path, value=$value, additionalProperties=$additionalProperties}" } diff --git a/courier-java-core/src/main/kotlin/com/courier/models/audiences/FilterConfig.kt b/courier-java-core/src/main/kotlin/com/courier/models/audiences/FilterConfig.kt index b0865d65..8893376e 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/audiences/FilterConfig.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/audiences/FilterConfig.kt @@ -2,201 +2,57 @@ package com.courier.models.audiences -import com.courier.core.Enum -import com.courier.core.ExcludeMissing -import com.courier.core.JsonField -import com.courier.core.JsonMissing +import com.courier.core.BaseDeserializer +import com.courier.core.BaseSerializer import com.courier.core.JsonValue -import com.courier.core.checkRequired +import com.courier.core.allMaxBy +import com.courier.core.getOrThrow 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 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.Objects -import kotlin.jvm.optionals.getOrNull +import java.util.Optional +/** A single filter to use for filtering */ +@JsonDeserialize(using = FilterConfig.Deserializer::class) +@JsonSerialize(using = FilterConfig.Serializer::class) class FilterConfig -@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val operator: JsonField, - private val path: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, + private val single: SingleFilterConfig? = null, + private val nested: NestedFilterConfig? = null, + private val _json: JsonValue? = null, ) { - @JsonCreator - private constructor( - @JsonProperty("operator") @ExcludeMissing operator: JsonField = JsonMissing.of(), - @JsonProperty("path") @ExcludeMissing path: JsonField = JsonMissing.of(), - @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), - ) : this(operator, path, value, mutableMapOf()) + /** A single filter to use for filtering */ + fun single(): Optional = Optional.ofNullable(single) - /** - * The operator to use for filtering - * - * @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 operator(): Operator = operator.getRequired("operator") - - /** - * The attribe name from profile whose value will be operated against the filter 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 path(): String = path.getRequired("path") - - /** - * The value to use for filtering - * - * @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 value(): String = value.getRequired("value") - - /** - * Returns the raw JSON value of [operator]. - * - * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator - - /** - * Returns the raw JSON value of [path]. - * - * Unlike [path], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @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 [FilterConfig]. - * - * The following fields are required: - * ```java - * .operator() - * .path() - * .value() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [FilterConfig]. */ - class Builder internal constructor() { - - private var operator: JsonField? = null - private var path: JsonField? = null - private var value: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(filterConfig: FilterConfig) = apply { - operator = filterConfig.operator - path = filterConfig.path - value = filterConfig.value - additionalProperties = filterConfig.additionalProperties.toMutableMap() - } - - /** The operator to use for filtering */ - fun operator(operator: Operator) = operator(JsonField.of(operator)) - - /** - * Sets [Builder.operator] to an arbitrary JSON value. - * - * You should usually call [Builder.operator] with a well-typed [Operator] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun operator(operator: JsonField) = apply { this.operator = operator } - - /** The attribe name from profile whose value will be operated against the filter value */ - fun path(path: String) = path(JsonField.of(path)) - - /** - * Sets [Builder.path] to an arbitrary JSON value. - * - * You should usually call [Builder.path] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun path(path: JsonField) = apply { this.path = path } - - /** The value to use for filtering */ - fun value(value: String) = value(JsonField.of(value)) + /** The operator to use for filtering */ + fun nested(): Optional = Optional.ofNullable(nested) - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } + fun isSingle(): Boolean = single != null - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun isNested(): Boolean = nested != null - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** A single filter to use for filtering */ + fun asSingle(): SingleFilterConfig = single.getOrThrow("single") - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** The operator to use for filtering */ + fun asNested(): NestedFilterConfig = nested.getOrThrow("nested") - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun _json(): Optional = Optional.ofNullable(_json) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) + fun accept(visitor: Visitor): T = + when { + single != null -> visitor.visitSingle(single) + nested != null -> visitor.visitNested(nested) + else -> visitor.unknown(_json) } - /** - * Returns an immutable instance of [FilterConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .operator() - * .path() - * .value() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): FilterConfig = - FilterConfig( - checkRequired("operator", operator), - checkRequired("path", path), - checkRequired("value", value), - additionalProperties.toMutableMap(), - ) - } - private var validated: Boolean = false fun validate(): FilterConfig = apply { @@ -204,9 +60,17 @@ private constructor( return@apply } - operator().validate() - path() - value() + accept( + object : Visitor { + override fun visitSingle(single: SingleFilterConfig) { + single.validate() + } + + override fun visitNested(nested: NestedFilterConfig) { + nested.validate() + } + } + ) validated = true } @@ -225,230 +89,110 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (operator.asKnown().getOrNull()?.validity() ?: 0) + - (if (path.asKnown().isPresent) 1 else 0) + - (if (value.asKnown().isPresent) 1 else 0) - - /** The operator to use for filtering */ - class Operator @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 ENDS_WITH = of("ENDS_WITH") + accept( + object : Visitor { + override fun visitSingle(single: SingleFilterConfig) = single.validity() - @JvmField val EQ = of("EQ") + override fun visitNested(nested: NestedFilterConfig) = nested.validity() - @JvmField val EXISTS = of("EXISTS") - - @JvmField val GT = of("GT") - - @JvmField val GTE = of("GTE") - - @JvmField val INCLUDES = of("INCLUDES") - - @JvmField val IS_AFTER = of("IS_AFTER") - - @JvmField val IS_BEFORE = of("IS_BEFORE") - - @JvmField val LT = of("LT") - - @JvmField val LTE = of("LTE") + override fun unknown(json: JsonValue?) = 0 + } + ) - @JvmField val NEQ = of("NEQ") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - @JvmField val OMIT = of("OMIT") + return other is FilterConfig && single == other.single && nested == other.nested + } - @JvmField val STARTS_WITH = of("STARTS_WITH") + override fun hashCode(): Int = Objects.hash(single, nested) - @JvmField val AND = of("AND") + override fun toString(): String = + when { + single != null -> "FilterConfig{single=$single}" + nested != null -> "FilterConfig{nested=$nested}" + _json != null -> "FilterConfig{_unknown=$_json}" + else -> throw IllegalStateException("Invalid FilterConfig") + } - @JvmField val OR = of("OR") + companion object { - @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) - } + /** A single filter to use for filtering */ + @JvmStatic fun ofSingle(single: SingleFilterConfig) = FilterConfig(single = single) - /** An enum containing [Operator]'s known values. */ - enum class Known { - ENDS_WITH, - EQ, - EXISTS, - GT, - GTE, - INCLUDES, - IS_AFTER, - IS_BEFORE, - LT, - LTE, - NEQ, - OMIT, - STARTS_WITH, - AND, - OR, - } + /** The operator to use for filtering */ + @JvmStatic fun ofNested(nested: NestedFilterConfig) = FilterConfig(nested = nested) + } - /** - * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Operator] 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 { - ENDS_WITH, - EQ, - EXISTS, - GT, - GTE, - INCLUDES, - IS_AFTER, - IS_BEFORE, - LT, - LTE, - NEQ, - OMIT, - STARTS_WITH, - AND, - OR, - /** An enum member indicating that [Operator] was instantiated with an unknown value. */ - _UNKNOWN, - } + /** + * An interface that defines how to map each variant of [FilterConfig] to a value of type [T]. + */ + interface Visitor { - /** - * 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) { - ENDS_WITH -> Value.ENDS_WITH - EQ -> Value.EQ - EXISTS -> Value.EXISTS - GT -> Value.GT - GTE -> Value.GTE - INCLUDES -> Value.INCLUDES - IS_AFTER -> Value.IS_AFTER - IS_BEFORE -> Value.IS_BEFORE - LT -> Value.LT - LTE -> Value.LTE - NEQ -> Value.NEQ - OMIT -> Value.OMIT - STARTS_WITH -> Value.STARTS_WITH - AND -> Value.AND - OR -> Value.OR - else -> Value._UNKNOWN - } + /** A single filter to use for filtering */ + fun visitSingle(single: SingleFilterConfig): T - /** - * 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) { - ENDS_WITH -> Known.ENDS_WITH - EQ -> Known.EQ - EXISTS -> Known.EXISTS - GT -> Known.GT - GTE -> Known.GTE - INCLUDES -> Known.INCLUDES - IS_AFTER -> Known.IS_AFTER - IS_BEFORE -> Known.IS_BEFORE - LT -> Known.LT - LTE -> Known.LTE - NEQ -> Known.NEQ - OMIT -> Known.OMIT - STARTS_WITH -> Known.STARTS_WITH - AND -> Known.AND - OR -> Known.OR - else -> throw CourierInvalidDataException("Unknown Operator: $value") - } + /** The operator to use for filtering */ + fun visitNested(nested: NestedFilterConfig): T /** - * Returns this class instance's primitive wire representation. + * Maps an unknown variant of [FilterConfig] to a value of type [T]. * - * This differs from the [toString] method because that method is primarily for debugging - * and generally doesn't throw. + * An instance of [FilterConfig] 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 if this class instance's value does not have the - * expected primitive type. + * @throws CourierInvalidDataException in the default implementation. */ - fun asString(): String = - _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } - - private var validated: Boolean = false - - fun validate(): Operator = apply { - if (validated) { - return@apply - } - - known() - validated = true + fun unknown(json: JsonValue?): T { + throw CourierInvalidDataException("Unknown FilterConfig: $json") } + } - 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 + internal class Deserializer : BaseDeserializer(FilterConfig::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): FilterConfig { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + FilterConfig(single = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FilterConfig(nested = 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 -> FilterConfig(_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() } - - return other is Operator && value == other.value } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + internal class Serializer : BaseSerializer(FilterConfig::class) { + + override fun serialize( + value: FilterConfig, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.single != null -> generator.writeObject(value.single) + value.nested != null -> generator.writeObject(value.nested) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid FilterConfig") + } } - - return other is FilterConfig && - operator == other.operator && - path == other.path && - value == other.value && - additionalProperties == other.additionalProperties } - - private val hashCode: Int by lazy { Objects.hash(operator, path, value, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "FilterConfig{operator=$operator, path=$path, value=$value, additionalProperties=$additionalProperties}" } diff --git a/courier-java-core/src/main/kotlin/com/courier/models/audiences/NestedFilterConfig.kt b/courier-java-core/src/main/kotlin/com/courier/models/audiences/NestedFilterConfig.kt new file mode 100644 index 00000000..2f691053 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/audiences/NestedFilterConfig.kt @@ -0,0 +1,438 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.audiences + +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 kotlin.jvm.optionals.getOrNull + +class NestedFilterConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val operator: JsonField, + private val rules: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("operator") @ExcludeMissing operator: JsonField = JsonMissing.of(), + @JsonProperty("rules") + @ExcludeMissing + rules: JsonField> = JsonMissing.of(), + ) : this(operator, rules, mutableMapOf()) + + /** + * The operator to use for filtering + * + * @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 operator(): Operator = operator.getRequired("operator") + + /** + * @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 rules(): List = rules.getRequired("rules") + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [rules]. + * + * Unlike [rules], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rules") @ExcludeMissing fun _rules(): JsonField> = rules + + @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 [NestedFilterConfig]. + * + * The following fields are required: + * ```java + * .operator() + * .rules() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NestedFilterConfig]. */ + class Builder internal constructor() { + + private var operator: JsonField? = null + private var rules: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(nestedFilterConfig: NestedFilterConfig) = apply { + operator = nestedFilterConfig.operator + rules = nestedFilterConfig.rules.map { it.toMutableList() } + additionalProperties = nestedFilterConfig.additionalProperties.toMutableMap() + } + + /** The operator to use for filtering */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + fun rules(rules: List) = rules(JsonField.of(rules)) + + /** + * Sets [Builder.rules] to an arbitrary JSON value. + * + * You should usually call [Builder.rules] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rules(rules: JsonField>) = apply { + this.rules = rules.map { it.toMutableList() } + } + + /** + * Adds a single [FilterConfig] to [rules]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRule(rule: FilterConfig) = apply { + rules = + (rules ?: JsonField.of(mutableListOf())).also { checkKnown("rules", it).add(rule) } + } + + /** Alias for calling [addRule] with `FilterConfig.ofSingle(single)`. */ + fun addRule(single: SingleFilterConfig) = addRule(FilterConfig.ofSingle(single)) + + /** Alias for calling [addRule] with `FilterConfig.ofNested(nested)`. */ + fun addRule(nested: NestedFilterConfig) = addRule(FilterConfig.ofNested(nested)) + + 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 [NestedFilterConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .operator() + * .rules() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NestedFilterConfig = + NestedFilterConfig( + checkRequired("operator", operator), + checkRequired("rules", rules).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NestedFilterConfig = apply { + if (validated) { + return@apply + } + + operator().validate() + rules().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 = + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (rules.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** The operator to use for filtering */ + class Operator @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 ENDS_WITH = of("ENDS_WITH") + + @JvmField val EQ = of("EQ") + + @JvmField val EXISTS = of("EXISTS") + + @JvmField val GT = of("GT") + + @JvmField val GTE = of("GTE") + + @JvmField val INCLUDES = of("INCLUDES") + + @JvmField val IS_AFTER = of("IS_AFTER") + + @JvmField val IS_BEFORE = of("IS_BEFORE") + + @JvmField val LT = of("LT") + + @JvmField val LTE = of("LTE") + + @JvmField val NEQ = of("NEQ") + + @JvmField val OMIT = of("OMIT") + + @JvmField val STARTS_WITH = of("STARTS_WITH") + + @JvmField val AND = of("AND") + + @JvmField val OR = of("OR") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + ENDS_WITH, + EQ, + EXISTS, + GT, + GTE, + INCLUDES, + IS_AFTER, + IS_BEFORE, + LT, + LTE, + NEQ, + OMIT, + STARTS_WITH, + AND, + OR, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] 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 { + ENDS_WITH, + EQ, + EXISTS, + GT, + GTE, + INCLUDES, + IS_AFTER, + IS_BEFORE, + LT, + LTE, + NEQ, + OMIT, + STARTS_WITH, + AND, + OR, + /** An enum member indicating that [Operator] 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) { + ENDS_WITH -> Value.ENDS_WITH + EQ -> Value.EQ + EXISTS -> Value.EXISTS + GT -> Value.GT + GTE -> Value.GTE + INCLUDES -> Value.INCLUDES + IS_AFTER -> Value.IS_AFTER + IS_BEFORE -> Value.IS_BEFORE + LT -> Value.LT + LTE -> Value.LTE + NEQ -> Value.NEQ + OMIT -> Value.OMIT + STARTS_WITH -> Value.STARTS_WITH + AND -> Value.AND + OR -> Value.OR + 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) { + ENDS_WITH -> Known.ENDS_WITH + EQ -> Known.EQ + EXISTS -> Known.EXISTS + GT -> Known.GT + GTE -> Known.GTE + INCLUDES -> Known.INCLUDES + IS_AFTER -> Known.IS_AFTER + IS_BEFORE -> Known.IS_BEFORE + LT -> Known.LT + LTE -> Known.LTE + NEQ -> Known.NEQ + OMIT -> Known.OMIT + STARTS_WITH -> Known.STARTS_WITH + AND -> Known.AND + OR -> Known.OR + else -> throw CourierInvalidDataException("Unknown Operator: $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(): Operator = 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 Operator && 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 NestedFilterConfig && + operator == other.operator && + rules == other.rules && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(operator, rules, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NestedFilterConfig{operator=$operator, rules=$rules, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/audiences/SingleFilterConfig.kt b/courier-java-core/src/main/kotlin/com/courier/models/audiences/SingleFilterConfig.kt new file mode 100644 index 00000000..8b5c7a19 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/audiences/SingleFilterConfig.kt @@ -0,0 +1,454 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.audiences + +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 + +class SingleFilterConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val operator: JsonField, + private val path: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("operator") @ExcludeMissing operator: JsonField = JsonMissing.of(), + @JsonProperty("path") @ExcludeMissing path: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(operator, path, value, mutableMapOf()) + + /** + * The operator to use for filtering + * + * @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 operator(): Operator = operator.getRequired("operator") + + /** + * The attribe name from profile whose value will be operated against the filter 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 path(): String = path.getRequired("path") + + /** + * The value to use for filtering + * + * @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 value(): String = value.getRequired("value") + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [path]. + * + * Unlike [path], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path + + /** + * Returns the raw JSON value of [value]. + * + * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + + @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 [SingleFilterConfig]. + * + * The following fields are required: + * ```java + * .operator() + * .path() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SingleFilterConfig]. */ + class Builder internal constructor() { + + private var operator: JsonField? = null + private var path: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(singleFilterConfig: SingleFilterConfig) = apply { + operator = singleFilterConfig.operator + path = singleFilterConfig.path + value = singleFilterConfig.value + additionalProperties = singleFilterConfig.additionalProperties.toMutableMap() + } + + /** The operator to use for filtering */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The attribe name from profile whose value will be operated against the filter value */ + fun path(path: String) = path(JsonField.of(path)) + + /** + * Sets [Builder.path] to an arbitrary JSON value. + * + * You should usually call [Builder.path] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun path(path: JsonField) = apply { this.path = path } + + /** The value to use for filtering */ + fun value(value: String) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun value(value: JsonField) = apply { this.value = value } + + 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 [SingleFilterConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .operator() + * .path() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SingleFilterConfig = + SingleFilterConfig( + checkRequired("operator", operator), + checkRequired("path", path), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SingleFilterConfig = apply { + if (validated) { + return@apply + } + + operator().validate() + path() + value() + 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 = + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (if (path.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) + + /** The operator to use for filtering */ + class Operator @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 ENDS_WITH = of("ENDS_WITH") + + @JvmField val EQ = of("EQ") + + @JvmField val EXISTS = of("EXISTS") + + @JvmField val GT = of("GT") + + @JvmField val GTE = of("GTE") + + @JvmField val INCLUDES = of("INCLUDES") + + @JvmField val IS_AFTER = of("IS_AFTER") + + @JvmField val IS_BEFORE = of("IS_BEFORE") + + @JvmField val LT = of("LT") + + @JvmField val LTE = of("LTE") + + @JvmField val NEQ = of("NEQ") + + @JvmField val OMIT = of("OMIT") + + @JvmField val STARTS_WITH = of("STARTS_WITH") + + @JvmField val AND = of("AND") + + @JvmField val OR = of("OR") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + ENDS_WITH, + EQ, + EXISTS, + GT, + GTE, + INCLUDES, + IS_AFTER, + IS_BEFORE, + LT, + LTE, + NEQ, + OMIT, + STARTS_WITH, + AND, + OR, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] 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 { + ENDS_WITH, + EQ, + EXISTS, + GT, + GTE, + INCLUDES, + IS_AFTER, + IS_BEFORE, + LT, + LTE, + NEQ, + OMIT, + STARTS_WITH, + AND, + OR, + /** An enum member indicating that [Operator] 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) { + ENDS_WITH -> Value.ENDS_WITH + EQ -> Value.EQ + EXISTS -> Value.EXISTS + GT -> Value.GT + GTE -> Value.GTE + INCLUDES -> Value.INCLUDES + IS_AFTER -> Value.IS_AFTER + IS_BEFORE -> Value.IS_BEFORE + LT -> Value.LT + LTE -> Value.LTE + NEQ -> Value.NEQ + OMIT -> Value.OMIT + STARTS_WITH -> Value.STARTS_WITH + AND -> Value.AND + OR -> Value.OR + 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) { + ENDS_WITH -> Known.ENDS_WITH + EQ -> Known.EQ + EXISTS -> Known.EXISTS + GT -> Known.GT + GTE -> Known.GTE + INCLUDES -> Known.INCLUDES + IS_AFTER -> Known.IS_AFTER + IS_BEFORE -> Known.IS_BEFORE + LT -> Known.LT + LTE -> Known.LTE + NEQ -> Known.NEQ + OMIT -> Known.OMIT + STARTS_WITH -> Known.STARTS_WITH + AND -> Known.AND + OR -> Known.OR + else -> throw CourierInvalidDataException("Unknown Operator: $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(): Operator = 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 Operator && 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 SingleFilterConfig && + operator == other.operator && + path == other.path && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(operator, path, value, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SingleFilterConfig{operator=$operator, path=$path, value=$value, 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 da6cb045..23beed96 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 @@ -18,14 +18,20 @@ import com.courier.core.http.Headers import com.courier.core.http.QueryParams import com.courier.core.toImmutable import com.courier.errors.CourierInvalidDataException +import com.courier.models.AudienceRecipient import com.courier.models.ElementalContent import com.courier.models.ElementalContentSugar +import com.courier.models.ListPatternRecipient +import com.courier.models.ListRecipient import com.courier.models.MessageContext import com.courier.models.MessageRouting import com.courier.models.MessageRoutingChannel -import com.courier.models.Recipient +import com.courier.models.MsTeamsRecipient +import com.courier.models.PagerdutyRecipient +import com.courier.models.SlackRecipient import com.courier.models.UserRecipient import com.courier.models.Utm +import com.courier.models.WebhookRecipient import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator @@ -968,8 +974,29 @@ private constructor( /** Alias for calling [to] with `To.ofUserRecipient(userRecipient)`. */ fun to(userRecipient: UserRecipient) = to(To.ofUserRecipient(userRecipient)) - /** Alias for calling [to] with `To.ofRecipients(recipients)`. */ - fun toOfRecipients(recipients: List) = to(To.ofRecipients(recipients)) + /** Alias for calling [to] with `To.ofAudienceRecipient(audienceRecipient)`. */ + fun to(audienceRecipient: AudienceRecipient) = + to(To.ofAudienceRecipient(audienceRecipient)) + + /** Alias for calling [to] with `To.ofListRecipient(listRecipient)`. */ + fun to(listRecipient: ListRecipient) = to(To.ofListRecipient(listRecipient)) + + /** Alias for calling [to] with `To.ofListPatternRecipient(listPatternRecipient)`. */ + fun to(listPatternRecipient: ListPatternRecipient) = + to(To.ofListPatternRecipient(listPatternRecipient)) + + /** Alias for calling [to] with `To.ofSlackRecipient(slackRecipient)`. */ + fun to(slackRecipient: SlackRecipient) = to(To.ofSlackRecipient(slackRecipient)) + + /** Alias for calling [to] with `To.ofMsTeamsRecipient(msTeamsRecipient)`. */ + fun to(msTeamsRecipient: MsTeamsRecipient) = to(To.ofMsTeamsRecipient(msTeamsRecipient)) + + /** Alias for calling [to] with `To.ofPagerdutyRecipient(pagerdutyRecipient)`. */ + fun to(pagerdutyRecipient: PagerdutyRecipient) = + to(To.ofPagerdutyRecipient(pagerdutyRecipient)) + + /** Alias for calling [to] with `To.ofWebhookRecipient(webhookRecipient)`. */ + fun to(webhookRecipient: WebhookRecipient) = to(To.ofWebhookRecipient(webhookRecipient)) fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -3709,28 +3736,104 @@ private constructor( class To private constructor( private val userRecipient: UserRecipient? = null, - private val recipients: List? = null, + private val audienceRecipient: AudienceRecipient? = null, + private val listRecipient: ListRecipient? = null, + private val listPatternRecipient: ListPatternRecipient? = null, + private val slackRecipient: SlackRecipient? = null, + private val msTeamsRecipient: MsTeamsRecipient? = null, + private val pagerdutyRecipient: PagerdutyRecipient? = null, + private val webhookRecipient: WebhookRecipient? = null, private val _json: JsonValue? = null, ) { + /** Send to a specific user by user_id, email, phone_number, or list_id */ fun userRecipient(): Optional = Optional.ofNullable(userRecipient) - fun recipients(): Optional> = Optional.ofNullable(recipients) + /** Send to all users in an audience */ + fun audienceRecipient(): Optional = + Optional.ofNullable(audienceRecipient) + + /** Send to all users in a specific list */ + fun listRecipient(): Optional = Optional.ofNullable(listRecipient) + + /** Send to users in lists matching a pattern */ + fun listPatternRecipient(): Optional = + Optional.ofNullable(listPatternRecipient) + + /** Send via Slack (channel, email, or user_id) */ + fun slackRecipient(): Optional = Optional.ofNullable(slackRecipient) + + /** Send via Microsoft Teams */ + fun msTeamsRecipient(): Optional = + Optional.ofNullable(msTeamsRecipient) + + /** Send via PagerDuty */ + fun pagerdutyRecipient(): Optional = + Optional.ofNullable(pagerdutyRecipient) + + /** Send via webhook */ + fun webhookRecipient(): Optional = + Optional.ofNullable(webhookRecipient) fun isUserRecipient(): Boolean = userRecipient != null - fun isRecipients(): Boolean = recipients != null + fun isAudienceRecipient(): Boolean = audienceRecipient != null + + fun isListRecipient(): Boolean = listRecipient != null + + fun isListPatternRecipient(): Boolean = listPatternRecipient != null + + fun isSlackRecipient(): Boolean = slackRecipient != null + + fun isMsTeamsRecipient(): Boolean = msTeamsRecipient != null + + fun isPagerdutyRecipient(): Boolean = pagerdutyRecipient != null + + fun isWebhookRecipient(): Boolean = webhookRecipient != null + /** Send to a specific user by user_id, email, phone_number, or list_id */ fun asUserRecipient(): UserRecipient = userRecipient.getOrThrow("userRecipient") - fun asRecipients(): List = recipients.getOrThrow("recipients") + /** Send to all users in an audience */ + fun asAudienceRecipient(): AudienceRecipient = + audienceRecipient.getOrThrow("audienceRecipient") + + /** Send to all users in a specific list */ + fun asListRecipient(): ListRecipient = listRecipient.getOrThrow("listRecipient") + + /** Send to users in lists matching a pattern */ + fun asListPatternRecipient(): ListPatternRecipient = + listPatternRecipient.getOrThrow("listPatternRecipient") + + /** Send via Slack (channel, email, or user_id) */ + fun asSlackRecipient(): SlackRecipient = slackRecipient.getOrThrow("slackRecipient") + + /** Send via Microsoft Teams */ + fun asMsTeamsRecipient(): MsTeamsRecipient = + msTeamsRecipient.getOrThrow("msTeamsRecipient") + + /** Send via PagerDuty */ + fun asPagerdutyRecipient(): PagerdutyRecipient = + pagerdutyRecipient.getOrThrow("pagerdutyRecipient") + + /** Send via webhook */ + fun asWebhookRecipient(): WebhookRecipient = + webhookRecipient.getOrThrow("webhookRecipient") fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = when { userRecipient != null -> visitor.visitUserRecipient(userRecipient) - recipients != null -> visitor.visitRecipients(recipients) + audienceRecipient != null -> visitor.visitAudienceRecipient(audienceRecipient) + listRecipient != null -> visitor.visitListRecipient(listRecipient) + listPatternRecipient != null -> + visitor.visitListPatternRecipient(listPatternRecipient) + slackRecipient != null -> visitor.visitSlackRecipient(slackRecipient) + msTeamsRecipient != null -> visitor.visitMsTeamsRecipient(msTeamsRecipient) + pagerdutyRecipient != null -> + visitor.visitPagerdutyRecipient(pagerdutyRecipient) + webhookRecipient != null -> visitor.visitWebhookRecipient(webhookRecipient) else -> visitor.unknown(_json) } @@ -3747,8 +3850,36 @@ private constructor( userRecipient.validate() } - override fun visitRecipients(recipients: List) { - recipients.forEach { it.validate() } + override fun visitAudienceRecipient(audienceRecipient: AudienceRecipient) { + audienceRecipient.validate() + } + + override fun visitListRecipient(listRecipient: ListRecipient) { + listRecipient.validate() + } + + override fun visitListPatternRecipient( + listPatternRecipient: ListPatternRecipient + ) { + listPatternRecipient.validate() + } + + override fun visitSlackRecipient(slackRecipient: SlackRecipient) { + slackRecipient.validate() + } + + override fun visitMsTeamsRecipient(msTeamsRecipient: MsTeamsRecipient) { + msTeamsRecipient.validate() + } + + override fun visitPagerdutyRecipient( + pagerdutyRecipient: PagerdutyRecipient + ) { + pagerdutyRecipient.validate() + } + + override fun visitWebhookRecipient(webhookRecipient: WebhookRecipient) { + webhookRecipient.validate() } } ) @@ -3776,8 +3907,28 @@ private constructor( override fun visitUserRecipient(userRecipient: UserRecipient) = userRecipient.validity() - override fun visitRecipients(recipients: List) = - recipients.sumOf { it.validity().toInt() } + override fun visitAudienceRecipient(audienceRecipient: AudienceRecipient) = + audienceRecipient.validity() + + override fun visitListRecipient(listRecipient: ListRecipient) = + listRecipient.validity() + + override fun visitListPatternRecipient( + listPatternRecipient: ListPatternRecipient + ) = listPatternRecipient.validity() + + override fun visitSlackRecipient(slackRecipient: SlackRecipient) = + slackRecipient.validity() + + override fun visitMsTeamsRecipient(msTeamsRecipient: MsTeamsRecipient) = + msTeamsRecipient.validity() + + override fun visitPagerdutyRecipient( + pagerdutyRecipient: PagerdutyRecipient + ) = pagerdutyRecipient.validity() + + override fun visitWebhookRecipient(webhookRecipient: WebhookRecipient) = + webhookRecipient.validity() override fun unknown(json: JsonValue?) = 0 } @@ -3790,36 +3941,110 @@ private constructor( return other is To && userRecipient == other.userRecipient && - recipients == other.recipients + audienceRecipient == other.audienceRecipient && + listRecipient == other.listRecipient && + listPatternRecipient == other.listPatternRecipient && + slackRecipient == other.slackRecipient && + msTeamsRecipient == other.msTeamsRecipient && + pagerdutyRecipient == other.pagerdutyRecipient && + webhookRecipient == other.webhookRecipient } - override fun hashCode(): Int = Objects.hash(userRecipient, recipients) + override fun hashCode(): Int = + Objects.hash( + userRecipient, + audienceRecipient, + listRecipient, + listPatternRecipient, + slackRecipient, + msTeamsRecipient, + pagerdutyRecipient, + webhookRecipient, + ) override fun toString(): String = when { userRecipient != null -> "To{userRecipient=$userRecipient}" - recipients != null -> "To{recipients=$recipients}" + audienceRecipient != null -> "To{audienceRecipient=$audienceRecipient}" + listRecipient != null -> "To{listRecipient=$listRecipient}" + listPatternRecipient != null -> "To{listPatternRecipient=$listPatternRecipient}" + slackRecipient != null -> "To{slackRecipient=$slackRecipient}" + msTeamsRecipient != null -> "To{msTeamsRecipient=$msTeamsRecipient}" + pagerdutyRecipient != null -> "To{pagerdutyRecipient=$pagerdutyRecipient}" + webhookRecipient != null -> "To{webhookRecipient=$webhookRecipient}" _json != null -> "To{_unknown=$_json}" else -> throw IllegalStateException("Invalid To") } companion object { + /** Send to a specific user by user_id, email, phone_number, or list_id */ @JvmStatic fun ofUserRecipient(userRecipient: UserRecipient) = To(userRecipient = userRecipient) + /** Send to all users in an audience */ + @JvmStatic + fun ofAudienceRecipient(audienceRecipient: AudienceRecipient) = + To(audienceRecipient = audienceRecipient) + + /** Send to all users in a specific list */ + @JvmStatic + fun ofListRecipient(listRecipient: ListRecipient) = + To(listRecipient = listRecipient) + + /** Send to users in lists matching a pattern */ + @JvmStatic + fun ofListPatternRecipient(listPatternRecipient: ListPatternRecipient) = + To(listPatternRecipient = listPatternRecipient) + + /** Send via Slack (channel, email, or user_id) */ + @JvmStatic + fun ofSlackRecipient(slackRecipient: SlackRecipient) = + To(slackRecipient = slackRecipient) + + /** Send via Microsoft Teams */ + @JvmStatic + fun ofMsTeamsRecipient(msTeamsRecipient: MsTeamsRecipient) = + To(msTeamsRecipient = msTeamsRecipient) + + /** Send via PagerDuty */ + @JvmStatic + fun ofPagerdutyRecipient(pagerdutyRecipient: PagerdutyRecipient) = + To(pagerdutyRecipient = pagerdutyRecipient) + + /** Send via webhook */ @JvmStatic - fun ofRecipients(recipients: List) = - To(recipients = recipients.toImmutable()) + fun ofWebhookRecipient(webhookRecipient: WebhookRecipient) = + To(webhookRecipient = webhookRecipient) } /** An interface that defines how to map each variant of [To] to a value of type [T]. */ interface Visitor { + /** Send to a specific user by user_id, email, phone_number, or list_id */ fun visitUserRecipient(userRecipient: UserRecipient): T - fun visitRecipients(recipients: List): T + /** Send to all users in an audience */ + fun visitAudienceRecipient(audienceRecipient: AudienceRecipient): T + + /** Send to all users in a specific list */ + fun visitListRecipient(listRecipient: ListRecipient): T + + /** Send to users in lists matching a pattern */ + fun visitListPatternRecipient(listPatternRecipient: ListPatternRecipient): T + + /** Send via Slack (channel, email, or user_id) */ + fun visitSlackRecipient(slackRecipient: SlackRecipient): T + + /** Send via Microsoft Teams */ + fun visitMsTeamsRecipient(msTeamsRecipient: MsTeamsRecipient): T + + /** Send via PagerDuty */ + fun visitPagerdutyRecipient(pagerdutyRecipient: PagerdutyRecipient): T + + /** Send via webhook */ + fun visitWebhookRecipient(webhookRecipient: WebhookRecipient): T /** * Maps an unknown variant of [To] to a value of type [T]. @@ -3846,8 +4071,26 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { To(userRecipient = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef>())?.let { - To(recipients = it, _json = json) + tryDeserialize(node, jacksonTypeRef())?.let { + To(audienceRecipient = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + To(listRecipient = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + To(listPatternRecipient = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + To(slackRecipient = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + To(msTeamsRecipient = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + To(pagerdutyRecipient = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + To(webhookRecipient = it, _json = json) }, ) .filterNotNull() @@ -3875,7 +4118,18 @@ private constructor( ) { when { value.userRecipient != null -> generator.writeObject(value.userRecipient) - value.recipients != null -> generator.writeObject(value.recipients) + value.audienceRecipient != null -> + generator.writeObject(value.audienceRecipient) + value.listRecipient != null -> generator.writeObject(value.listRecipient) + value.listPatternRecipient != null -> + generator.writeObject(value.listPatternRecipient) + value.slackRecipient != null -> generator.writeObject(value.slackRecipient) + value.msTeamsRecipient != null -> + generator.writeObject(value.msTeamsRecipient) + value.pagerdutyRecipient != null -> + generator.writeObject(value.pagerdutyRecipient) + value.webhookRecipient != null -> + generator.writeObject(value.webhookRecipient) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid To") } diff --git a/courier-java-core/src/test/kotlin/com/courier/models/AirshipProfileAudienceTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/AirshipProfileAudienceTest.kt new file mode 100644 index 00000000..4c904393 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/AirshipProfileAudienceTest.kt @@ -0,0 +1,34 @@ +// 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 AirshipProfileAudienceTest { + + @Test + fun create() { + val airshipProfileAudience = + AirshipProfileAudience.builder().namedUser("named_user").build() + + assertThat(airshipProfileAudience.namedUser()).isEqualTo("named_user") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val airshipProfileAudience = + AirshipProfileAudience.builder().namedUser("named_user").build() + + val roundtrippedAirshipProfileAudience = + jsonMapper.readValue( + jsonMapper.writeValueAsString(airshipProfileAudience), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAirshipProfileAudience).isEqualTo(airshipProfileAudience) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/AirshipProfileTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/AirshipProfileTest.kt new file mode 100644 index 00000000..2e41db8e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/AirshipProfileTest.kt @@ -0,0 +1,42 @@ +// 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 AirshipProfileTest { + + @Test + fun create() { + val airshipProfile = + AirshipProfile.builder() + .audience(AirshipProfileAudience.builder().namedUser("named_user").build()) + .addDeviceType("string") + .build() + + assertThat(airshipProfile.audience()) + .isEqualTo(AirshipProfileAudience.builder().namedUser("named_user").build()) + assertThat(airshipProfile.deviceTypes()).containsExactly("string") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val airshipProfile = + AirshipProfile.builder() + .audience(AirshipProfileAudience.builder().namedUser("named_user").build()) + .addDeviceType("string") + .build() + + val roundtrippedAirshipProfile = + jsonMapper.readValue( + jsonMapper.writeValueAsString(airshipProfile), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAirshipProfile).isEqualTo(airshipProfile) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/AudienceFilterTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/AudienceFilterTest.kt new file mode 100644 index 00000000..0f1f6747 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/AudienceFilterTest.kt @@ -0,0 +1,44 @@ +// 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 AudienceFilterTest { + + @Test + fun create() { + val audienceFilter = + AudienceFilter.builder() + .operator(AudienceFilter.Operator.MEMBER_OF) + .path(AudienceFilter.Path.ACCOUNT_ID) + .value("value") + .build() + + assertThat(audienceFilter.operator()).isEqualTo(AudienceFilter.Operator.MEMBER_OF) + assertThat(audienceFilter.path()).isEqualTo(AudienceFilter.Path.ACCOUNT_ID) + assertThat(audienceFilter.value()).isEqualTo("value") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val audienceFilter = + AudienceFilter.builder() + .operator(AudienceFilter.Operator.MEMBER_OF) + .path(AudienceFilter.Path.ACCOUNT_ID) + .value("value") + .build() + + val roundtrippedAudienceFilter = + jsonMapper.readValue( + jsonMapper.writeValueAsString(audienceFilter), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAudienceFilter).isEqualTo(audienceFilter) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/AudienceRecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/AudienceRecipientTest.kt new file mode 100644 index 00000000..30d959bb --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/AudienceRecipientTest.kt @@ -0,0 +1,78 @@ +// 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 AudienceRecipientTest { + + @Test + fun create() { + val audienceRecipient = + AudienceRecipient.builder() + .audienceId("audience_id") + .data( + AudienceRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addFilter( + AudienceFilter.builder() + .operator(AudienceFilter.Operator.MEMBER_OF) + .path(AudienceFilter.Path.ACCOUNT_ID) + .value("value") + .build() + ) + .build() + + assertThat(audienceRecipient.audienceId()).isEqualTo("audience_id") + assertThat(audienceRecipient.data()) + .contains( + AudienceRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(audienceRecipient.filters().getOrNull()) + .containsExactly( + AudienceFilter.builder() + .operator(AudienceFilter.Operator.MEMBER_OF) + .path(AudienceFilter.Path.ACCOUNT_ID) + .value("value") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val audienceRecipient = + AudienceRecipient.builder() + .audienceId("audience_id") + .data( + AudienceRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addFilter( + AudienceFilter.builder() + .operator(AudienceFilter.Operator.MEMBER_OF) + .path(AudienceFilter.Path.ACCOUNT_ID) + .value("value") + .build() + ) + .build() + + val roundtrippedAudienceRecipient = + jsonMapper.readValue( + jsonMapper.writeValueAsString(audienceRecipient), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAudienceRecipient).isEqualTo(audienceRecipient) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/DiscordTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/DiscordTest.kt new file mode 100644 index 00000000..42d133d5 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/DiscordTest.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.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class DiscordTest { + + @Test + fun ofSendToChannel() { + val sendToChannel = SendToChannel.builder().channelId("channel_id").build() + + val discord = Discord.ofSendToChannel(sendToChannel) + + assertThat(discord.sendToChannel()).contains(sendToChannel) + assertThat(discord.sendDirectMessage()).isEmpty + } + + @Test + fun ofSendToChannelRoundtrip() { + val jsonMapper = jsonMapper() + val discord = + Discord.ofSendToChannel(SendToChannel.builder().channelId("channel_id").build()) + + val roundtrippedDiscord = + jsonMapper.readValue(jsonMapper.writeValueAsString(discord), jacksonTypeRef()) + + assertThat(roundtrippedDiscord).isEqualTo(discord) + } + + @Test + fun ofSendDirectMessage() { + val sendDirectMessage = SendDirectMessage.builder().userId("user_id").build() + + val discord = Discord.ofSendDirectMessage(sendDirectMessage) + + assertThat(discord.sendToChannel()).isEmpty + assertThat(discord.sendDirectMessage()).contains(sendDirectMessage) + } + + @Test + fun ofSendDirectMessageRoundtrip() { + val jsonMapper = jsonMapper() + val discord = + Discord.ofSendDirectMessage(SendDirectMessage.builder().userId("user_id").build()) + + val roundtrippedDiscord = + jsonMapper.readValue(jsonMapper.writeValueAsString(discord), jacksonTypeRef()) + + assertThat(roundtrippedDiscord).isEqualTo(discord) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val discord = jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { discord.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/ExpoTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/ExpoTest.kt new file mode 100644 index 00000000..aa590fcf --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/ExpoTest.kt @@ -0,0 +1,79 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class ExpoTest { + + @Test + fun ofToken() { + val token = Token.builder().token("token").build() + + val expo = Expo.ofToken(token) + + assertThat(expo.token()).contains(token) + assertThat(expo.multipleTokens()).isEmpty + } + + @Test + fun ofTokenRoundtrip() { + val jsonMapper = jsonMapper() + val expo = Expo.ofToken(Token.builder().token("token").build()) + + val roundtrippedExpo = + jsonMapper.readValue(jsonMapper.writeValueAsString(expo), jacksonTypeRef()) + + assertThat(roundtrippedExpo).isEqualTo(expo) + } + + @Test + fun ofMultipleTokens() { + val multipleTokens = + MultipleTokens.builder().addToken(Token.builder().token("token").build()).build() + + val expo = Expo.ofMultipleTokens(multipleTokens) + + assertThat(expo.token()).isEmpty + assertThat(expo.multipleTokens()).contains(multipleTokens) + } + + @Test + fun ofMultipleTokensRoundtrip() { + val jsonMapper = jsonMapper() + val expo = + Expo.ofMultipleTokens( + MultipleTokens.builder().addToken(Token.builder().token("token").build()).build() + ) + + val roundtrippedExpo = + jsonMapper.readValue(jsonMapper.writeValueAsString(expo), jacksonTypeRef()) + + assertThat(roundtrippedExpo).isEqualTo(expo) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val expo = jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { expo.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/IntercomRecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/IntercomRecipientTest.kt new file mode 100644 index 00000000..ae963d90 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/IntercomRecipientTest.kt @@ -0,0 +1,32 @@ +// 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 IntercomRecipientTest { + + @Test + fun create() { + val intercomRecipient = IntercomRecipient.builder().id("id").build() + + assertThat(intercomRecipient.id()).isEqualTo("id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val intercomRecipient = IntercomRecipient.builder().id("id").build() + + val roundtrippedIntercomRecipient = + jsonMapper.readValue( + jsonMapper.writeValueAsString(intercomRecipient), + jacksonTypeRef(), + ) + + assertThat(roundtrippedIntercomRecipient).isEqualTo(intercomRecipient) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/IntercomTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/IntercomTest.kt new file mode 100644 index 00000000..7974f3ae --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/IntercomTest.kt @@ -0,0 +1,35 @@ +// 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 IntercomTest { + + @Test + fun create() { + val intercom = + Intercom.builder().from("from").to(IntercomRecipient.builder().id("id").build()).build() + + assertThat(intercom.from()).isEqualTo("from") + assertThat(intercom.to()).isEqualTo(IntercomRecipient.builder().id("id").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val intercom = + Intercom.builder().from("from").to(IntercomRecipient.builder().id("id").build()).build() + + val roundtrippedIntercom = + jsonMapper.readValue( + jsonMapper.writeValueAsString(intercom), + jacksonTypeRef(), + ) + + assertThat(roundtrippedIntercom).isEqualTo(intercom) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/ListFilterTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/ListFilterTest.kt new file mode 100644 index 00000000..b344e8ff --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/ListFilterTest.kt @@ -0,0 +1,44 @@ +// 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 ListFilterTest { + + @Test + fun create() { + val listFilter = + ListFilter.builder() + .operator(ListFilter.Operator.MEMBER_OF) + .path(ListFilter.Path.ACCOUNT_ID) + .value("value") + .build() + + assertThat(listFilter.operator()).isEqualTo(ListFilter.Operator.MEMBER_OF) + assertThat(listFilter.path()).isEqualTo(ListFilter.Path.ACCOUNT_ID) + assertThat(listFilter.value()).isEqualTo("value") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val listFilter = + ListFilter.builder() + .operator(ListFilter.Operator.MEMBER_OF) + .path(ListFilter.Path.ACCOUNT_ID) + .value("value") + .build() + + val roundtrippedListFilter = + jsonMapper.readValue( + jsonMapper.writeValueAsString(listFilter), + jacksonTypeRef(), + ) + + assertThat(roundtrippedListFilter).isEqualTo(listFilter) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/ListPatternRecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/ListPatternRecipientTest.kt new file mode 100644 index 00000000..63ba8436 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/ListPatternRecipientTest.kt @@ -0,0 +1,55 @@ +// 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 ListPatternRecipientTest { + + @Test + fun create() { + val listPatternRecipient = + ListPatternRecipient.builder() + .data( + ListPatternRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .listPattern("list_pattern") + .build() + + assertThat(listPatternRecipient.data()) + .contains( + ListPatternRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(listPatternRecipient.listPattern()).contains("list_pattern") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val listPatternRecipient = + ListPatternRecipient.builder() + .data( + ListPatternRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .listPattern("list_pattern") + .build() + + val roundtrippedListPatternRecipient = + jsonMapper.readValue( + jsonMapper.writeValueAsString(listPatternRecipient), + jacksonTypeRef(), + ) + + assertThat(roundtrippedListPatternRecipient).isEqualTo(listPatternRecipient) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/ListRecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/ListRecipientTest.kt new file mode 100644 index 00000000..a2a2abeb --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/ListRecipientTest.kt @@ -0,0 +1,78 @@ +// 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 ListRecipientTest { + + @Test + fun create() { + val listRecipient = + ListRecipient.builder() + .data( + ListRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addFilter( + ListFilter.builder() + .operator(ListFilter.Operator.MEMBER_OF) + .path(ListFilter.Path.ACCOUNT_ID) + .value("value") + .build() + ) + .listId("list_id") + .build() + + assertThat(listRecipient.data()) + .contains( + ListRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(listRecipient.filters().getOrNull()) + .containsExactly( + ListFilter.builder() + .operator(ListFilter.Operator.MEMBER_OF) + .path(ListFilter.Path.ACCOUNT_ID) + .value("value") + .build() + ) + assertThat(listRecipient.listId()).contains("list_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val listRecipient = + ListRecipient.builder() + .data( + ListRecipient.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addFilter( + ListFilter.builder() + .operator(ListFilter.Operator.MEMBER_OF) + .path(ListFilter.Path.ACCOUNT_ID) + .value("value") + .build() + ) + .listId("list_id") + .build() + + val roundtrippedListRecipient = + jsonMapper.readValue( + jsonMapper.writeValueAsString(listRecipient), + jacksonTypeRef(), + ) + + assertThat(roundtrippedListRecipient).isEqualTo(listRecipient) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsBasePropertiesTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsBasePropertiesTest.kt new file mode 100644 index 00000000..6a0f3385 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsBasePropertiesTest.kt @@ -0,0 +1,35 @@ +// 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 MsTeamsBasePropertiesTest { + + @Test + fun create() { + val msTeamsBaseProperties = + MsTeamsBaseProperties.builder().serviceUrl("service_url").tenantId("tenant_id").build() + + assertThat(msTeamsBaseProperties.serviceUrl()).isEqualTo("service_url") + assertThat(msTeamsBaseProperties.tenantId()).isEqualTo("tenant_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val msTeamsBaseProperties = + MsTeamsBaseProperties.builder().serviceUrl("service_url").tenantId("tenant_id").build() + + val roundtrippedMsTeamsBaseProperties = + jsonMapper.readValue( + jsonMapper.writeValueAsString(msTeamsBaseProperties), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMsTeamsBaseProperties).isEqualTo(msTeamsBaseProperties) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsRecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsRecipientTest.kt new file mode 100644 index 00000000..322730d8 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsRecipientTest.kt @@ -0,0 +1,59 @@ +// 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 MsTeamsRecipientTest { + + @Test + fun create() { + val msTeamsRecipient = + MsTeamsRecipient.builder() + .msTeams( + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + ) + .build() + + assertThat(msTeamsRecipient.msTeams()) + .isEqualTo( + MsTeams.ofSendToMsTeamsUserId( + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + ) + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val msTeamsRecipient = + MsTeamsRecipient.builder() + .msTeams( + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + ) + .build() + + val roundtrippedMsTeamsRecipient = + jsonMapper.readValue( + jsonMapper.writeValueAsString(msTeamsRecipient), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMsTeamsRecipient).isEqualTo(msTeamsRecipient) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsTest.kt new file mode 100644 index 00000000..cadb73b2 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/MsTeamsTest.kt @@ -0,0 +1,215 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class MsTeamsTest { + + @Test + fun ofSendToMsTeamsUserId() { + val sendToMsTeamsUserId = + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + + val msTeams = MsTeams.ofSendToMsTeamsUserId(sendToMsTeamsUserId) + + assertThat(msTeams.sendToMsTeamsUserId()).contains(sendToMsTeamsUserId) + assertThat(msTeams.sendToMsTeamsEmail()).isEmpty + assertThat(msTeams.sendToMsTeamsChannelId()).isEmpty + assertThat(msTeams.sendToMsTeamsConversationId()).isEmpty + assertThat(msTeams.sendToMsTeamsChannelName()).isEmpty + } + + @Test + fun ofSendToMsTeamsUserIdRoundtrip() { + val jsonMapper = jsonMapper() + val msTeams = + MsTeams.ofSendToMsTeamsUserId( + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + ) + + val roundtrippedMsTeams = + jsonMapper.readValue(jsonMapper.writeValueAsString(msTeams), jacksonTypeRef()) + + assertThat(roundtrippedMsTeams).isEqualTo(msTeams) + } + + @Test + fun ofSendToMsTeamsEmail() { + val sendToMsTeamsEmail = + SendToMsTeamsEmail.builder() + .email("email") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + val msTeams = MsTeams.ofSendToMsTeamsEmail(sendToMsTeamsEmail) + + assertThat(msTeams.sendToMsTeamsUserId()).isEmpty + assertThat(msTeams.sendToMsTeamsEmail()).contains(sendToMsTeamsEmail) + assertThat(msTeams.sendToMsTeamsChannelId()).isEmpty + assertThat(msTeams.sendToMsTeamsConversationId()).isEmpty + assertThat(msTeams.sendToMsTeamsChannelName()).isEmpty + } + + @Test + fun ofSendToMsTeamsEmailRoundtrip() { + val jsonMapper = jsonMapper() + val msTeams = + MsTeams.ofSendToMsTeamsEmail( + SendToMsTeamsEmail.builder() + .email("email") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + ) + + val roundtrippedMsTeams = + jsonMapper.readValue(jsonMapper.writeValueAsString(msTeams), jacksonTypeRef()) + + assertThat(roundtrippedMsTeams).isEqualTo(msTeams) + } + + @Test + fun ofSendToMsTeamsChannelId() { + val sendToMsTeamsChannelId = + SendToMsTeamsChannelId.builder() + .channelId("channel_id") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + val msTeams = MsTeams.ofSendToMsTeamsChannelId(sendToMsTeamsChannelId) + + assertThat(msTeams.sendToMsTeamsUserId()).isEmpty + assertThat(msTeams.sendToMsTeamsEmail()).isEmpty + assertThat(msTeams.sendToMsTeamsChannelId()).contains(sendToMsTeamsChannelId) + assertThat(msTeams.sendToMsTeamsConversationId()).isEmpty + assertThat(msTeams.sendToMsTeamsChannelName()).isEmpty + } + + @Test + fun ofSendToMsTeamsChannelIdRoundtrip() { + val jsonMapper = jsonMapper() + val msTeams = + MsTeams.ofSendToMsTeamsChannelId( + SendToMsTeamsChannelId.builder() + .channelId("channel_id") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + ) + + val roundtrippedMsTeams = + jsonMapper.readValue(jsonMapper.writeValueAsString(msTeams), jacksonTypeRef()) + + assertThat(roundtrippedMsTeams).isEqualTo(msTeams) + } + + @Test + fun ofSendToMsTeamsConversationId() { + val sendToMsTeamsConversationId = + SendToMsTeamsConversationId.builder() + .conversationId("conversation_id") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + val msTeams = MsTeams.ofSendToMsTeamsConversationId(sendToMsTeamsConversationId) + + assertThat(msTeams.sendToMsTeamsUserId()).isEmpty + assertThat(msTeams.sendToMsTeamsEmail()).isEmpty + assertThat(msTeams.sendToMsTeamsChannelId()).isEmpty + assertThat(msTeams.sendToMsTeamsConversationId()).contains(sendToMsTeamsConversationId) + assertThat(msTeams.sendToMsTeamsChannelName()).isEmpty + } + + @Test + fun ofSendToMsTeamsConversationIdRoundtrip() { + val jsonMapper = jsonMapper() + val msTeams = + MsTeams.ofSendToMsTeamsConversationId( + SendToMsTeamsConversationId.builder() + .conversationId("conversation_id") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + ) + + val roundtrippedMsTeams = + jsonMapper.readValue(jsonMapper.writeValueAsString(msTeams), jacksonTypeRef()) + + assertThat(roundtrippedMsTeams).isEqualTo(msTeams) + } + + @Test + fun ofSendToMsTeamsChannelName() { + val sendToMsTeamsChannelName = + SendToMsTeamsChannelName.builder() + .channelName("channel_name") + .serviceUrl("service_url") + .teamId("team_id") + .tenantId("tenant_id") + .build() + + val msTeams = MsTeams.ofSendToMsTeamsChannelName(sendToMsTeamsChannelName) + + assertThat(msTeams.sendToMsTeamsUserId()).isEmpty + assertThat(msTeams.sendToMsTeamsEmail()).isEmpty + assertThat(msTeams.sendToMsTeamsChannelId()).isEmpty + assertThat(msTeams.sendToMsTeamsConversationId()).isEmpty + assertThat(msTeams.sendToMsTeamsChannelName()).contains(sendToMsTeamsChannelName) + } + + @Test + fun ofSendToMsTeamsChannelNameRoundtrip() { + val jsonMapper = jsonMapper() + val msTeams = + MsTeams.ofSendToMsTeamsChannelName( + SendToMsTeamsChannelName.builder() + .channelName("channel_name") + .serviceUrl("service_url") + .teamId("team_id") + .tenantId("tenant_id") + .build() + ) + + val roundtrippedMsTeams = + jsonMapper.readValue(jsonMapper.writeValueAsString(msTeams), jacksonTypeRef()) + + assertThat(roundtrippedMsTeams).isEqualTo(msTeams) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val msTeams = jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { msTeams.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/MultipleTokensTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/MultipleTokensTest.kt new file mode 100644 index 00000000..b415d98e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/MultipleTokensTest.kt @@ -0,0 +1,34 @@ +// 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 MultipleTokensTest { + + @Test + fun create() { + val multipleTokens = + MultipleTokens.builder().addToken(Token.builder().token("token").build()).build() + + assertThat(multipleTokens.tokens()).containsExactly(Token.builder().token("token").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val multipleTokens = + MultipleTokens.builder().addToken(Token.builder().token("token").build()).build() + + val roundtrippedMultipleTokens = + jsonMapper.readValue( + jsonMapper.writeValueAsString(multipleTokens), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMultipleTokens).isEqualTo(multipleTokens) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/PagerdutyRecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/PagerdutyRecipientTest.kt new file mode 100644 index 00000000..566a623c --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/PagerdutyRecipientTest.kt @@ -0,0 +1,60 @@ +// 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 PagerdutyRecipientTest { + + @Test + fun create() { + val pagerdutyRecipient = + PagerdutyRecipient.builder() + .pagerduty( + Pagerduty.builder() + .eventAction("event_action") + .routingKey("routing_key") + .severity("severity") + .source("source") + .build() + ) + .build() + + assertThat(pagerdutyRecipient.pagerduty()) + .isEqualTo( + Pagerduty.builder() + .eventAction("event_action") + .routingKey("routing_key") + .severity("severity") + .source("source") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val pagerdutyRecipient = + PagerdutyRecipient.builder() + .pagerduty( + Pagerduty.builder() + .eventAction("event_action") + .routingKey("routing_key") + .severity("severity") + .source("source") + .build() + ) + .build() + + val roundtrippedPagerdutyRecipient = + jsonMapper.readValue( + jsonMapper.writeValueAsString(pagerdutyRecipient), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPagerdutyRecipient).isEqualTo(pagerdutyRecipient) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/PagerdutyTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/PagerdutyTest.kt new file mode 100644 index 00000000..9618910b --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/PagerdutyTest.kt @@ -0,0 +1,47 @@ +// 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 PagerdutyTest { + + @Test + fun create() { + val pagerduty = + Pagerduty.builder() + .eventAction("event_action") + .routingKey("routing_key") + .severity("severity") + .source("source") + .build() + + assertThat(pagerduty.eventAction()).contains("event_action") + assertThat(pagerduty.routingKey()).contains("routing_key") + assertThat(pagerduty.severity()).contains("severity") + assertThat(pagerduty.source()).contains("source") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val pagerduty = + Pagerduty.builder() + .eventAction("event_action") + .routingKey("routing_key") + .severity("severity") + .source("source") + .build() + + val roundtrippedPagerduty = + jsonMapper.readValue( + jsonMapper.writeValueAsString(pagerduty), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPagerduty).isEqualTo(pagerduty) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/RecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/RecipientTest.kt deleted file mode 100644 index fa5b5c7b..00000000 --- a/courier-java-core/src/test/kotlin/com/courier/models/RecipientTest.kt +++ /dev/null @@ -1,201 +0,0 @@ -// 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 RecipientTest { - - @Test - fun create() { - val recipient = - Recipient.builder() - .accountId("account_id") - .context(MessageContext.builder().tenantId("tenant_id").build()) - .data( - Recipient.Data.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) - .email("email") - .listId("list_id") - .locale("locale") - .phoneNumber("phone_number") - .preferences( - Recipient.Preferences.builder() - .notifications( - Recipient.Preferences.Notifications.builder() - .putAdditionalProperty( - "foo", - JsonValue.from( - mapOf( - "status" to "OPTED_IN", - "channel_preferences" to - listOf(mapOf("channel" to "direct_message")), - "rules" to - listOf( - mapOf("until" to "until", "start" to "start") - ), - "source" to "subscription", - ) - ), - ) - .build() - ) - .categories( - Recipient.Preferences.Categories.builder() - .putAdditionalProperty( - "foo", - JsonValue.from( - mapOf( - "status" to "OPTED_IN", - "channel_preferences" to - listOf(mapOf("channel" to "direct_message")), - "rules" to - listOf( - mapOf("until" to "until", "start" to "start") - ), - "source" to "subscription", - ) - ), - ) - .build() - ) - .templateId("templateId") - .build() - ) - .tenantId("tenant_id") - .userId("user_id") - .build() - - assertThat(recipient.accountId()).contains("account_id") - assertThat(recipient.context()) - .contains(MessageContext.builder().tenantId("tenant_id").build()) - assertThat(recipient.data()) - .contains( - Recipient.Data.builder().putAdditionalProperty("foo", JsonValue.from("bar")).build() - ) - assertThat(recipient.email()).contains("email") - assertThat(recipient.listId()).contains("list_id") - assertThat(recipient.locale()).contains("locale") - assertThat(recipient.phoneNumber()).contains("phone_number") - assertThat(recipient.preferences()) - .contains( - Recipient.Preferences.builder() - .notifications( - Recipient.Preferences.Notifications.builder() - .putAdditionalProperty( - "foo", - JsonValue.from( - mapOf( - "status" to "OPTED_IN", - "channel_preferences" to - listOf(mapOf("channel" to "direct_message")), - "rules" to - listOf(mapOf("until" to "until", "start" to "start")), - "source" to "subscription", - ) - ), - ) - .build() - ) - .categories( - Recipient.Preferences.Categories.builder() - .putAdditionalProperty( - "foo", - JsonValue.from( - mapOf( - "status" to "OPTED_IN", - "channel_preferences" to - listOf(mapOf("channel" to "direct_message")), - "rules" to - listOf(mapOf("until" to "until", "start" to "start")), - "source" to "subscription", - ) - ), - ) - .build() - ) - .templateId("templateId") - .build() - ) - assertThat(recipient.tenantId()).contains("tenant_id") - assertThat(recipient.userId()).contains("user_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val recipient = - Recipient.builder() - .accountId("account_id") - .context(MessageContext.builder().tenantId("tenant_id").build()) - .data( - Recipient.Data.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) - .email("email") - .listId("list_id") - .locale("locale") - .phoneNumber("phone_number") - .preferences( - Recipient.Preferences.builder() - .notifications( - Recipient.Preferences.Notifications.builder() - .putAdditionalProperty( - "foo", - JsonValue.from( - mapOf( - "status" to "OPTED_IN", - "channel_preferences" to - listOf(mapOf("channel" to "direct_message")), - "rules" to - listOf( - mapOf("until" to "until", "start" to "start") - ), - "source" to "subscription", - ) - ), - ) - .build() - ) - .categories( - Recipient.Preferences.Categories.builder() - .putAdditionalProperty( - "foo", - JsonValue.from( - mapOf( - "status" to "OPTED_IN", - "channel_preferences" to - listOf(mapOf("channel" to "direct_message")), - "rules" to - listOf( - mapOf("until" to "until", "start" to "start") - ), - "source" to "subscription", - ) - ), - ) - .build() - ) - .templateId("templateId") - .build() - ) - .tenantId("tenant_id") - .userId("user_id") - .build() - - val roundtrippedRecipient = - jsonMapper.readValue( - jsonMapper.writeValueAsString(recipient), - jacksonTypeRef(), - ) - - assertThat(roundtrippedRecipient).isEqualTo(recipient) - } -} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendDirectMessageTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendDirectMessageTest.kt new file mode 100644 index 00000000..33486cbe --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendDirectMessageTest.kt @@ -0,0 +1,32 @@ +// 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 SendDirectMessageTest { + + @Test + fun create() { + val sendDirectMessage = SendDirectMessage.builder().userId("user_id").build() + + assertThat(sendDirectMessage.userId()).isEqualTo("user_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendDirectMessage = SendDirectMessage.builder().userId("user_id").build() + + val roundtrippedSendDirectMessage = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendDirectMessage), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendDirectMessage).isEqualTo(sendDirectMessage) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToChannelTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToChannelTest.kt new file mode 100644 index 00000000..6512662d --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToChannelTest.kt @@ -0,0 +1,32 @@ +// 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 SendToChannelTest { + + @Test + fun create() { + val sendToChannel = SendToChannel.builder().channelId("channel_id").build() + + assertThat(sendToChannel.channelId()).isEqualTo("channel_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToChannel = SendToChannel.builder().channelId("channel_id").build() + + val roundtrippedSendToChannel = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToChannel), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToChannel).isEqualTo(sendToChannel) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsChannelIdTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsChannelIdTest.kt new file mode 100644 index 00000000..8c9c3c35 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsChannelIdTest.kt @@ -0,0 +1,44 @@ +// 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 SendToMsTeamsChannelIdTest { + + @Test + fun create() { + val sendToMsTeamsChannelId = + SendToMsTeamsChannelId.builder() + .channelId("channel_id") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + assertThat(sendToMsTeamsChannelId.channelId()).isEqualTo("channel_id") + assertThat(sendToMsTeamsChannelId.serviceUrl()).isEqualTo("service_url") + assertThat(sendToMsTeamsChannelId.tenantId()).isEqualTo("tenant_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToMsTeamsChannelId = + SendToMsTeamsChannelId.builder() + .channelId("channel_id") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + val roundtrippedSendToMsTeamsChannelId = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToMsTeamsChannelId), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToMsTeamsChannelId).isEqualTo(sendToMsTeamsChannelId) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsChannelNameTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsChannelNameTest.kt new file mode 100644 index 00000000..18cab2f1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsChannelNameTest.kt @@ -0,0 +1,47 @@ +// 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 SendToMsTeamsChannelNameTest { + + @Test + fun create() { + val sendToMsTeamsChannelName = + SendToMsTeamsChannelName.builder() + .channelName("channel_name") + .serviceUrl("service_url") + .teamId("team_id") + .tenantId("tenant_id") + .build() + + assertThat(sendToMsTeamsChannelName.channelName()).isEqualTo("channel_name") + assertThat(sendToMsTeamsChannelName.serviceUrl()).isEqualTo("service_url") + assertThat(sendToMsTeamsChannelName.teamId()).isEqualTo("team_id") + assertThat(sendToMsTeamsChannelName.tenantId()).isEqualTo("tenant_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToMsTeamsChannelName = + SendToMsTeamsChannelName.builder() + .channelName("channel_name") + .serviceUrl("service_url") + .teamId("team_id") + .tenantId("tenant_id") + .build() + + val roundtrippedSendToMsTeamsChannelName = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToMsTeamsChannelName), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToMsTeamsChannelName).isEqualTo(sendToMsTeamsChannelName) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsConversationIdTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsConversationIdTest.kt new file mode 100644 index 00000000..4d1a5907 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsConversationIdTest.kt @@ -0,0 +1,44 @@ +// 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 SendToMsTeamsConversationIdTest { + + @Test + fun create() { + val sendToMsTeamsConversationId = + SendToMsTeamsConversationId.builder() + .conversationId("conversation_id") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + assertThat(sendToMsTeamsConversationId.conversationId()).isEqualTo("conversation_id") + assertThat(sendToMsTeamsConversationId.serviceUrl()).isEqualTo("service_url") + assertThat(sendToMsTeamsConversationId.tenantId()).isEqualTo("tenant_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToMsTeamsConversationId = + SendToMsTeamsConversationId.builder() + .conversationId("conversation_id") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + val roundtrippedSendToMsTeamsConversationId = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToMsTeamsConversationId), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToMsTeamsConversationId).isEqualTo(sendToMsTeamsConversationId) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsEmailTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsEmailTest.kt new file mode 100644 index 00000000..0b6c7892 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsEmailTest.kt @@ -0,0 +1,44 @@ +// 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 SendToMsTeamsEmailTest { + + @Test + fun create() { + val sendToMsTeamsEmail = + SendToMsTeamsEmail.builder() + .email("email") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + assertThat(sendToMsTeamsEmail.email()).isEqualTo("email") + assertThat(sendToMsTeamsEmail.serviceUrl()).isEqualTo("service_url") + assertThat(sendToMsTeamsEmail.tenantId()).isEqualTo("tenant_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToMsTeamsEmail = + SendToMsTeamsEmail.builder() + .email("email") + .serviceUrl("service_url") + .tenantId("tenant_id") + .build() + + val roundtrippedSendToMsTeamsEmail = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToMsTeamsEmail), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToMsTeamsEmail).isEqualTo(sendToMsTeamsEmail) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsUserIdTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsUserIdTest.kt new file mode 100644 index 00000000..a35da126 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToMsTeamsUserIdTest.kt @@ -0,0 +1,44 @@ +// 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 SendToMsTeamsUserIdTest { + + @Test + fun create() { + val sendToMsTeamsUserId = + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + + assertThat(sendToMsTeamsUserId.serviceUrl()).isEqualTo("service_url") + assertThat(sendToMsTeamsUserId.tenantId()).isEqualTo("tenant_id") + assertThat(sendToMsTeamsUserId.userId()).isEqualTo("user_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToMsTeamsUserId = + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + + val roundtrippedSendToMsTeamsUserId = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToMsTeamsUserId), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToMsTeamsUserId).isEqualTo(sendToMsTeamsUserId) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackChannelTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackChannelTest.kt new file mode 100644 index 00000000..2f8a2c98 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackChannelTest.kt @@ -0,0 +1,35 @@ +// 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 SendToSlackChannelTest { + + @Test + fun create() { + val sendToSlackChannel = + SendToSlackChannel.builder().accessToken("access_token").channel("channel").build() + + assertThat(sendToSlackChannel.accessToken()).isEqualTo("access_token") + assertThat(sendToSlackChannel.channel()).isEqualTo("channel") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToSlackChannel = + SendToSlackChannel.builder().accessToken("access_token").channel("channel").build() + + val roundtrippedSendToSlackChannel = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToSlackChannel), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToSlackChannel).isEqualTo(sendToSlackChannel) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackEmailTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackEmailTest.kt new file mode 100644 index 00000000..28b46b63 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackEmailTest.kt @@ -0,0 +1,35 @@ +// 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 SendToSlackEmailTest { + + @Test + fun create() { + val sendToSlackEmail = + SendToSlackEmail.builder().accessToken("access_token").email("email").build() + + assertThat(sendToSlackEmail.accessToken()).isEqualTo("access_token") + assertThat(sendToSlackEmail.email()).isEqualTo("email") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToSlackEmail = + SendToSlackEmail.builder().accessToken("access_token").email("email").build() + + val roundtrippedSendToSlackEmail = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToSlackEmail), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToSlackEmail).isEqualTo(sendToSlackEmail) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackUserIdTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackUserIdTest.kt new file mode 100644 index 00000000..85b6fc9c --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SendToSlackUserIdTest.kt @@ -0,0 +1,35 @@ +// 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 SendToSlackUserIdTest { + + @Test + fun create() { + val sendToSlackUserId = + SendToSlackUserId.builder().accessToken("access_token").userId("user_id").build() + + assertThat(sendToSlackUserId.accessToken()).isEqualTo("access_token") + assertThat(sendToSlackUserId.userId()).isEqualTo("user_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendToSlackUserId = + SendToSlackUserId.builder().accessToken("access_token").userId("user_id").build() + + val roundtrippedSendToSlackUserId = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendToSlackUserId), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendToSlackUserId).isEqualTo(sendToSlackUserId) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SlackBasePropertiesTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SlackBasePropertiesTest.kt new file mode 100644 index 00000000..c603caf8 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SlackBasePropertiesTest.kt @@ -0,0 +1,32 @@ +// 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 SlackBasePropertiesTest { + + @Test + fun create() { + val slackBaseProperties = SlackBaseProperties.builder().accessToken("access_token").build() + + assertThat(slackBaseProperties.accessToken()).isEqualTo("access_token") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val slackBaseProperties = SlackBaseProperties.builder().accessToken("access_token").build() + + val roundtrippedSlackBaseProperties = + jsonMapper.readValue( + jsonMapper.writeValueAsString(slackBaseProperties), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSlackBaseProperties).isEqualTo(slackBaseProperties) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SlackRecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SlackRecipientTest.kt new file mode 100644 index 00000000..6896ef12 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SlackRecipientTest.kt @@ -0,0 +1,56 @@ +// 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 SlackRecipientTest { + + @Test + fun create() { + val slackRecipient = + SlackRecipient.builder() + .slack( + SendToSlackChannel.builder() + .accessToken("access_token") + .channel("channel") + .build() + ) + .build() + + assertThat(slackRecipient.slack()) + .isEqualTo( + Slack.ofSendToSlackChannel( + SendToSlackChannel.builder() + .accessToken("access_token") + .channel("channel") + .build() + ) + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val slackRecipient = + SlackRecipient.builder() + .slack( + SendToSlackChannel.builder() + .accessToken("access_token") + .channel("channel") + .build() + ) + .build() + + val roundtrippedSlackRecipient = + jsonMapper.readValue( + jsonMapper.writeValueAsString(slackRecipient), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSlackRecipient).isEqualTo(slackRecipient) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/SlackTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/SlackTest.kt new file mode 100644 index 00000000..9e0e74e2 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/SlackTest.kt @@ -0,0 +1,111 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class SlackTest { + + @Test + fun ofSendToSlackChannel() { + val sendToSlackChannel = + SendToSlackChannel.builder().accessToken("access_token").channel("channel").build() + + val slack = Slack.ofSendToSlackChannel(sendToSlackChannel) + + assertThat(slack.sendToSlackChannel()).contains(sendToSlackChannel) + assertThat(slack.sendToSlackEmail()).isEmpty + assertThat(slack.sendToSlackUserId()).isEmpty + } + + @Test + fun ofSendToSlackChannelRoundtrip() { + val jsonMapper = jsonMapper() + val slack = + Slack.ofSendToSlackChannel( + SendToSlackChannel.builder().accessToken("access_token").channel("channel").build() + ) + + val roundtrippedSlack = + jsonMapper.readValue(jsonMapper.writeValueAsString(slack), jacksonTypeRef()) + + assertThat(roundtrippedSlack).isEqualTo(slack) + } + + @Test + fun ofSendToSlackEmail() { + val sendToSlackEmail = + SendToSlackEmail.builder().accessToken("access_token").email("email").build() + + val slack = Slack.ofSendToSlackEmail(sendToSlackEmail) + + assertThat(slack.sendToSlackChannel()).isEmpty + assertThat(slack.sendToSlackEmail()).contains(sendToSlackEmail) + assertThat(slack.sendToSlackUserId()).isEmpty + } + + @Test + fun ofSendToSlackEmailRoundtrip() { + val jsonMapper = jsonMapper() + val slack = + Slack.ofSendToSlackEmail( + SendToSlackEmail.builder().accessToken("access_token").email("email").build() + ) + + val roundtrippedSlack = + jsonMapper.readValue(jsonMapper.writeValueAsString(slack), jacksonTypeRef()) + + assertThat(roundtrippedSlack).isEqualTo(slack) + } + + @Test + fun ofSendToSlackUserId() { + val sendToSlackUserId = + SendToSlackUserId.builder().accessToken("access_token").userId("user_id").build() + + val slack = Slack.ofSendToSlackUserId(sendToSlackUserId) + + assertThat(slack.sendToSlackChannel()).isEmpty + assertThat(slack.sendToSlackEmail()).isEmpty + assertThat(slack.sendToSlackUserId()).contains(sendToSlackUserId) + } + + @Test + fun ofSendToSlackUserIdRoundtrip() { + val jsonMapper = jsonMapper() + val slack = + Slack.ofSendToSlackUserId( + SendToSlackUserId.builder().accessToken("access_token").userId("user_id").build() + ) + + val roundtrippedSlack = + jsonMapper.readValue(jsonMapper.writeValueAsString(slack), jacksonTypeRef()) + + assertThat(roundtrippedSlack).isEqualTo(slack) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val slack = jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { slack.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/TokenTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/TokenTest.kt new file mode 100644 index 00000000..202a3b2d --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/TokenTest.kt @@ -0,0 +1,29 @@ +// 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 TokenTest { + + @Test + fun create() { + val token = Token.builder().token("token").build() + + assertThat(token.token()).isEqualTo("token") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val token = Token.builder().token("token").build() + + val roundtrippedToken = + jsonMapper.readValue(jsonMapper.writeValueAsString(token), jacksonTypeRef()) + + assertThat(roundtrippedToken).isEqualTo(token) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/UserProfileFirebaseTokenTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/UserProfileFirebaseTokenTest.kt new file mode 100644 index 00000000..99660664 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/UserProfileFirebaseTokenTest.kt @@ -0,0 +1,72 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows + +internal class UserProfileFirebaseTokenTest { + + @Test + fun ofString() { + val string = "string" + + val userProfileFirebaseToken = UserProfileFirebaseToken.ofString(string) + + assertThat(userProfileFirebaseToken.string()).contains(string) + assertThat(userProfileFirebaseToken.strings()).isEmpty + } + + @Test + fun ofStringRoundtrip() { + val jsonMapper = jsonMapper() + val userProfileFirebaseToken = UserProfileFirebaseToken.ofString("string") + + val roundtrippedUserProfileFirebaseToken = + jsonMapper.readValue( + jsonMapper.writeValueAsString(userProfileFirebaseToken), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUserProfileFirebaseToken).isEqualTo(userProfileFirebaseToken) + } + + @Test + fun ofStrings() { + val strings = listOf("string") + + val userProfileFirebaseToken = UserProfileFirebaseToken.ofStrings(strings) + + assertThat(userProfileFirebaseToken.string()).isEmpty + assertThat(userProfileFirebaseToken.strings()).contains(strings) + } + + @Test + fun ofStringsRoundtrip() { + val jsonMapper = jsonMapper() + val userProfileFirebaseToken = UserProfileFirebaseToken.ofStrings(listOf("string")) + + val roundtrippedUserProfileFirebaseToken = + jsonMapper.readValue( + jsonMapper.writeValueAsString(userProfileFirebaseToken), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUserProfileFirebaseToken).isEqualTo(userProfileFirebaseToken) + } + + @Test + fun incompatibleJsonShapeDeserializesToUnknown() { + val value = JsonValue.from(mapOf("invalid" to "object")) + val userProfileFirebaseToken = + jsonMapper().convertValue(value, jacksonTypeRef()) + + val e = assertThrows { userProfileFirebaseToken.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/UserProfileTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/UserProfileTest.kt new file mode 100644 index 00000000..1089d154 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/UserProfileTest.kt @@ -0,0 +1,246 @@ +// 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 UserProfileTest { + + @Test + fun create() { + val userProfile = + UserProfile.builder() + .address( + UserProfile.Address.builder() + .country("country") + .formatted("formatted") + .locality("locality") + .postalCode("postal_code") + .region("region") + .streetAddress("street_address") + .build() + ) + .airship( + AirshipProfile.builder() + .audience(AirshipProfileAudience.builder().namedUser("named_user").build()) + .addDeviceType("string") + .build() + ) + .apn("apn") + .birthdate("birthdate") + .custom( + UserProfile.Custom.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .discord(SendToChannel.builder().channelId("channel_id").build()) + .email("email") + .emailVerified(true) + .expo(Token.builder().token("token").build()) + .facebookPsid("facebookPSID") + .familyName("family_name") + .firebaseToken("string") + .gender("gender") + .givenName("given_name") + .intercom( + Intercom.builder() + .from("from") + .to(IntercomRecipient.builder().id("id").build()) + .build() + ) + .locale("locale") + .middleName("middle_name") + .msTeams( + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + ) + .name("name") + .nickname("nickname") + .phoneNumber("phone_number") + .phoneNumberVerified(true) + .picture("picture") + .preferredName("preferred_name") + .profile("profile") + .slack( + SendToSlackChannel.builder() + .accessToken("access_token") + .channel("channel") + .build() + ) + .sub("sub") + .targetArn("target_arn") + .updatedAt("updated_at") + .website("website") + .zoneinfo("zoneinfo") + .build() + + assertThat(userProfile.address()) + .contains( + UserProfile.Address.builder() + .country("country") + .formatted("formatted") + .locality("locality") + .postalCode("postal_code") + .region("region") + .streetAddress("street_address") + .build() + ) + assertThat(userProfile.airship()) + .contains( + AirshipProfile.builder() + .audience(AirshipProfileAudience.builder().namedUser("named_user").build()) + .addDeviceType("string") + .build() + ) + assertThat(userProfile.apn()).contains("apn") + assertThat(userProfile.birthdate()).contains("birthdate") + assertThat(userProfile.custom()) + .contains( + UserProfile.Custom.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(userProfile.discord()) + .contains( + Discord.ofSendToChannel(SendToChannel.builder().channelId("channel_id").build()) + ) + assertThat(userProfile.email()).contains("email") + assertThat(userProfile.emailVerified()).contains(true) + assertThat(userProfile.expo()) + .contains(Expo.ofToken(Token.builder().token("token").build())) + assertThat(userProfile.facebookPsid()).contains("facebookPSID") + assertThat(userProfile.familyName()).contains("family_name") + assertThat(userProfile.firebaseToken()) + .contains(UserProfileFirebaseToken.ofString("string")) + assertThat(userProfile.gender()).contains("gender") + assertThat(userProfile.givenName()).contains("given_name") + assertThat(userProfile.intercom()) + .contains( + Intercom.builder() + .from("from") + .to(IntercomRecipient.builder().id("id").build()) + .build() + ) + assertThat(userProfile.locale()).contains("locale") + assertThat(userProfile.middleName()).contains("middle_name") + assertThat(userProfile.msTeams()) + .contains( + MsTeams.ofSendToMsTeamsUserId( + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + ) + ) + assertThat(userProfile.name()).contains("name") + assertThat(userProfile.nickname()).contains("nickname") + assertThat(userProfile.phoneNumber()).contains("phone_number") + assertThat(userProfile.phoneNumberVerified()).contains(true) + assertThat(userProfile.picture()).contains("picture") + assertThat(userProfile.preferredName()).contains("preferred_name") + assertThat(userProfile.profile()).contains("profile") + assertThat(userProfile.slack()) + .contains( + Slack.ofSendToSlackChannel( + SendToSlackChannel.builder() + .accessToken("access_token") + .channel("channel") + .build() + ) + ) + assertThat(userProfile.sub()).contains("sub") + assertThat(userProfile.targetArn()).contains("target_arn") + assertThat(userProfile.updatedAt()).contains("updated_at") + assertThat(userProfile.website()).contains("website") + assertThat(userProfile.zoneinfo()).contains("zoneinfo") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val userProfile = + UserProfile.builder() + .address( + UserProfile.Address.builder() + .country("country") + .formatted("formatted") + .locality("locality") + .postalCode("postal_code") + .region("region") + .streetAddress("street_address") + .build() + ) + .airship( + AirshipProfile.builder() + .audience(AirshipProfileAudience.builder().namedUser("named_user").build()) + .addDeviceType("string") + .build() + ) + .apn("apn") + .birthdate("birthdate") + .custom( + UserProfile.Custom.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .discord(SendToChannel.builder().channelId("channel_id").build()) + .email("email") + .emailVerified(true) + .expo(Token.builder().token("token").build()) + .facebookPsid("facebookPSID") + .familyName("family_name") + .firebaseToken("string") + .gender("gender") + .givenName("given_name") + .intercom( + Intercom.builder() + .from("from") + .to(IntercomRecipient.builder().id("id").build()) + .build() + ) + .locale("locale") + .middleName("middle_name") + .msTeams( + SendToMsTeamsUserId.builder() + .serviceUrl("service_url") + .tenantId("tenant_id") + .userId("user_id") + .build() + ) + .name("name") + .nickname("nickname") + .phoneNumber("phone_number") + .phoneNumberVerified(true) + .picture("picture") + .preferredName("preferred_name") + .profile("profile") + .slack( + SendToSlackChannel.builder() + .accessToken("access_token") + .channel("channel") + .build() + ) + .sub("sub") + .targetArn("target_arn") + .updatedAt("updated_at") + .website("website") + .zoneinfo("zoneinfo") + .build() + + val roundtrippedUserProfile = + jsonMapper.readValue( + jsonMapper.writeValueAsString(userProfile), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUserProfile).isEqualTo(userProfile) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/WebhookAuthenticationTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/WebhookAuthenticationTest.kt new file mode 100644 index 00000000..3b729d22 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/WebhookAuthenticationTest.kt @@ -0,0 +1,47 @@ +// 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 WebhookAuthenticationTest { + + @Test + fun create() { + val webhookAuthentication = + WebhookAuthentication.builder() + .mode(WebhookAuthMode.NONE) + .token("token") + .password("password") + .username("username") + .build() + + assertThat(webhookAuthentication.mode()).isEqualTo(WebhookAuthMode.NONE) + assertThat(webhookAuthentication.token()).contains("token") + assertThat(webhookAuthentication.password()).contains("password") + assertThat(webhookAuthentication.username()).contains("username") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val webhookAuthentication = + WebhookAuthentication.builder() + .mode(WebhookAuthMode.NONE) + .token("token") + .password("password") + .username("username") + .build() + + val roundtrippedWebhookAuthentication = + jsonMapper.readValue( + jsonMapper.writeValueAsString(webhookAuthentication), + jacksonTypeRef(), + ) + + assertThat(roundtrippedWebhookAuthentication).isEqualTo(webhookAuthentication) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/WebhookProfileTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/WebhookProfileTest.kt new file mode 100644 index 00000000..e22d3ab3 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/WebhookProfileTest.kt @@ -0,0 +1,86 @@ +// 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 WebhookProfileTest { + + @Test + fun create() { + val webhookProfile = + WebhookProfile.builder() + .url("url") + .authentication( + WebhookAuthentication.builder() + .mode(WebhookAuthMode.NONE) + .token("token") + .password("password") + .username("username") + .build() + ) + .headers( + WebhookProfile.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .method(WebhookMethod.POST) + .profile(WebhookProfileType.LIMITED) + .build() + + assertThat(webhookProfile.url()).isEqualTo("url") + assertThat(webhookProfile.authentication()) + .contains( + WebhookAuthentication.builder() + .mode(WebhookAuthMode.NONE) + .token("token") + .password("password") + .username("username") + .build() + ) + assertThat(webhookProfile.headers()) + .contains( + WebhookProfile.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + assertThat(webhookProfile.method()).contains(WebhookMethod.POST) + assertThat(webhookProfile.profile()).contains(WebhookProfileType.LIMITED) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val webhookProfile = + WebhookProfile.builder() + .url("url") + .authentication( + WebhookAuthentication.builder() + .mode(WebhookAuthMode.NONE) + .token("token") + .password("password") + .username("username") + .build() + ) + .headers( + WebhookProfile.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .method(WebhookMethod.POST) + .profile(WebhookProfileType.LIMITED) + .build() + + val roundtrippedWebhookProfile = + jsonMapper.readValue( + jsonMapper.writeValueAsString(webhookProfile), + jacksonTypeRef(), + ) + + assertThat(roundtrippedWebhookProfile).isEqualTo(webhookProfile) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/WebhookRecipientTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/WebhookRecipientTest.kt new file mode 100644 index 00000000..374bbd6a --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/WebhookRecipientTest.kt @@ -0,0 +1,97 @@ +// 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 WebhookRecipientTest { + + @Test + fun create() { + val webhookRecipient = + WebhookRecipient.builder() + .webhook( + WebhookProfile.builder() + .url("url") + .authentication( + WebhookAuthentication.builder() + .mode(WebhookAuthMode.NONE) + .token("token") + .password("password") + .username("username") + .build() + ) + .headers( + WebhookProfile.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .method(WebhookMethod.POST) + .profile(WebhookProfileType.LIMITED) + .build() + ) + .build() + + assertThat(webhookRecipient.webhook()) + .isEqualTo( + WebhookProfile.builder() + .url("url") + .authentication( + WebhookAuthentication.builder() + .mode(WebhookAuthMode.NONE) + .token("token") + .password("password") + .username("username") + .build() + ) + .headers( + WebhookProfile.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .method(WebhookMethod.POST) + .profile(WebhookProfileType.LIMITED) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val webhookRecipient = + WebhookRecipient.builder() + .webhook( + WebhookProfile.builder() + .url("url") + .authentication( + WebhookAuthentication.builder() + .mode(WebhookAuthMode.NONE) + .token("token") + .password("password") + .username("username") + .build() + ) + .headers( + WebhookProfile.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .method(WebhookMethod.POST) + .profile(WebhookProfileType.LIMITED) + .build() + ) + .build() + + val roundtrippedWebhookRecipient = + jsonMapper.readValue( + jsonMapper.writeValueAsString(webhookRecipient), + jacksonTypeRef(), + ) + + assertThat(roundtrippedWebhookRecipient).isEqualTo(webhookRecipient) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceListResponseTest.kt index 8d29594e..ac1c0c6d 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceListResponseTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceListResponseTest.kt @@ -20,8 +20,8 @@ internal class AudienceListResponseTest { .createdAt("created_at") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() @@ -40,8 +40,8 @@ internal class AudienceListResponseTest { .createdAt("created_at") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() @@ -65,8 +65,8 @@ internal class AudienceListResponseTest { .createdAt("created_at") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() diff --git a/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceTest.kt index b2e06ad6..d2ff5000 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceTest.kt @@ -17,8 +17,8 @@ internal class AudienceTest { .createdAt("created_at") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() @@ -32,11 +32,13 @@ internal class AudienceTest { assertThat(audience.description()).isEqualTo("description") assertThat(audience.filter()) .isEqualTo( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) - .path("path") - .value("value") - .build() + Filter.ofSingleFilterConfig( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) ) assertThat(audience.name()).isEqualTo("name") assertThat(audience.updatedAt()).isEqualTo("updated_at") @@ -51,8 +53,8 @@ internal class AudienceTest { .createdAt("created_at") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() diff --git a/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceUpdateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceUpdateParamsTest.kt index 508652a5..9f793c64 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceUpdateParamsTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceUpdateParamsTest.kt @@ -13,8 +13,8 @@ internal class AudienceUpdateParamsTest { .audienceId("audience_id") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() @@ -39,8 +39,8 @@ internal class AudienceUpdateParamsTest { .audienceId("audience_id") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() @@ -53,11 +53,13 @@ internal class AudienceUpdateParamsTest { assertThat(body.description()).contains("description") assertThat(body.filter()) .contains( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) - .path("path") - .value("value") - .build() + Filter.ofSingleFilterConfig( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) ) assertThat(body.name()).contains("name") } diff --git a/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceUpdateResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceUpdateResponseTest.kt index a4d2f71b..7917f856 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceUpdateResponseTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/audiences/AudienceUpdateResponseTest.kt @@ -19,8 +19,8 @@ internal class AudienceUpdateResponseTest { .createdAt("created_at") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() @@ -38,8 +38,8 @@ internal class AudienceUpdateResponseTest { .createdAt("created_at") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() @@ -61,8 +61,8 @@ internal class AudienceUpdateResponseTest { .createdAt("created_at") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() diff --git a/courier-java-core/src/test/kotlin/com/courier/models/audiences/FilterConfigTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/audiences/FilterConfigTest.kt index c9513bd4..ce0081c0 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/audiences/FilterConfigTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/audiences/FilterConfigTest.kt @@ -2,37 +2,91 @@ package com.courier.models.audiences +import com.courier.core.JsonValue import com.courier.core.jsonMapper +import com.courier.errors.CourierInvalidDataException import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource internal class FilterConfigTest { @Test - fun create() { - val filterConfig = - FilterConfig.builder() - .operator(FilterConfig.Operator.ENDS_WITH) + fun ofSingle() { + val single = + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() - assertThat(filterConfig.operator()).isEqualTo(FilterConfig.Operator.ENDS_WITH) - assertThat(filterConfig.path()).isEqualTo("path") - assertThat(filterConfig.value()).isEqualTo("value") + val filterConfig = FilterConfig.ofSingle(single) + + assertThat(filterConfig.single()).contains(single) + assertThat(filterConfig.nested()).isEmpty } @Test - fun roundtrip() { + fun ofSingleRoundtrip() { val jsonMapper = jsonMapper() val filterConfig = - FilterConfig.builder() - .operator(FilterConfig.Operator.ENDS_WITH) - .path("path") - .value("value") + FilterConfig.ofSingle( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) + + val roundtrippedFilterConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(filterConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFilterConfig).isEqualTo(filterConfig) + } + + @Test + fun ofNested() { + val nested = + NestedFilterConfig.builder() + .operator(NestedFilterConfig.Operator.ENDS_WITH) + .addRule( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) .build() + val filterConfig = FilterConfig.ofNested(nested) + + assertThat(filterConfig.single()).isEmpty + assertThat(filterConfig.nested()).contains(nested) + } + + @Test + fun ofNestedRoundtrip() { + val jsonMapper = jsonMapper() + val filterConfig = + FilterConfig.ofNested( + NestedFilterConfig.builder() + .operator(NestedFilterConfig.Operator.ENDS_WITH) + .addRule( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) + .build() + ) + val roundtrippedFilterConfig = jsonMapper.readValue( jsonMapper.writeValueAsString(filterConfig), @@ -41,4 +95,21 @@ internal class FilterConfigTest { assertThat(roundtrippedFilterConfig).isEqualTo(filterConfig) } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val filterConfig = jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { filterConfig.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } } diff --git a/courier-java-core/src/test/kotlin/com/courier/models/audiences/FilterTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/audiences/FilterTest.kt index a31de513..9ab1d655 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/audiences/FilterTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/audiences/FilterTest.kt @@ -2,32 +2,108 @@ package com.courier.models.audiences +import com.courier.core.JsonValue import com.courier.core.jsonMapper +import com.courier.errors.CourierInvalidDataException import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource internal class FilterTest { @Test - fun create() { + fun ofSingleFilterConfig() { + val singleFilterConfig = + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + + val filter = Filter.ofSingleFilterConfig(singleFilterConfig) + + assertThat(filter.singleFilterConfig()).contains(singleFilterConfig) + assertThat(filter.nestedFilterConfig()).isEmpty + } + + @Test + fun ofSingleFilterConfigRoundtrip() { + val jsonMapper = jsonMapper() val filter = - Filter.builder().operator(Filter.Operator.ENDS_WITH).path("path").value("value").build() + Filter.ofSingleFilterConfig( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) + + val roundtrippedFilter = + jsonMapper.readValue(jsonMapper.writeValueAsString(filter), jacksonTypeRef()) + + assertThat(roundtrippedFilter).isEqualTo(filter) + } + + @Test + fun ofNestedFilterConfig() { + val nestedFilterConfig = + NestedFilterConfig.builder() + .operator(NestedFilterConfig.Operator.ENDS_WITH) + .addRule( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) + .build() + + val filter = Filter.ofNestedFilterConfig(nestedFilterConfig) - assertThat(filter.operator()).isEqualTo(Filter.Operator.ENDS_WITH) - assertThat(filter.path()).isEqualTo("path") - assertThat(filter.value()).isEqualTo("value") + assertThat(filter.singleFilterConfig()).isEmpty + assertThat(filter.nestedFilterConfig()).contains(nestedFilterConfig) } @Test - fun roundtrip() { + fun ofNestedFilterConfigRoundtrip() { val jsonMapper = jsonMapper() val filter = - Filter.builder().operator(Filter.Operator.ENDS_WITH).path("path").value("value").build() + Filter.ofNestedFilterConfig( + NestedFilterConfig.builder() + .operator(NestedFilterConfig.Operator.ENDS_WITH) + .addRule( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) + .build() + ) val roundtrippedFilter = jsonMapper.readValue(jsonMapper.writeValueAsString(filter), jacksonTypeRef()) assertThat(roundtrippedFilter).isEqualTo(filter) } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val filter = jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { filter.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } } diff --git a/courier-java-core/src/test/kotlin/com/courier/models/audiences/NestedFilterConfigTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/audiences/NestedFilterConfigTest.kt new file mode 100644 index 00000000..11642222 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/audiences/NestedFilterConfigTest.kt @@ -0,0 +1,62 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.audiences + +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 NestedFilterConfigTest { + + @Test + fun create() { + val nestedFilterConfig = + NestedFilterConfig.builder() + .operator(NestedFilterConfig.Operator.ENDS_WITH) + .addRule( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) + .build() + + assertThat(nestedFilterConfig.operator()).isEqualTo(NestedFilterConfig.Operator.ENDS_WITH) + assertThat(nestedFilterConfig.rules()) + .containsExactly( + FilterConfig.ofSingle( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val nestedFilterConfig = + NestedFilterConfig.builder() + .operator(NestedFilterConfig.Operator.ENDS_WITH) + .addRule( + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + ) + .build() + + val roundtrippedNestedFilterConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(nestedFilterConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedNestedFilterConfig).isEqualTo(nestedFilterConfig) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/audiences/SingleFilterConfigTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/audiences/SingleFilterConfigTest.kt new file mode 100644 index 00000000..7a8bdfd5 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/audiences/SingleFilterConfigTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.audiences + +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 SingleFilterConfigTest { + + @Test + fun create() { + val singleFilterConfig = + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + + assertThat(singleFilterConfig.operator()).isEqualTo(SingleFilterConfig.Operator.ENDS_WITH) + assertThat(singleFilterConfig.path()).isEqualTo("path") + assertThat(singleFilterConfig.value()).isEqualTo("value") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val singleFilterConfig = + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) + .path("path") + .value("value") + .build() + + val roundtrippedSingleFilterConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(singleFilterConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSingleFilterConfig).isEqualTo(singleFilterConfig) + } +} 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 877599c9..ed44547f 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 @@ -203,7 +203,7 @@ internal class SendMessageParamsTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -411,7 +411,7 @@ internal class SendMessageParamsTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -609,7 +609,7 @@ internal class SendMessageParamsTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() 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 0088168b..1d44e8fa 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 @@ -281,7 +281,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -514,7 +514,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -747,7 +747,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -980,7 +980,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -1213,7 +1213,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -1446,7 +1446,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -1679,7 +1679,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -1912,7 +1912,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -2145,7 +2145,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -2378,7 +2378,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -2611,7 +2611,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -2844,7 +2844,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -3077,7 +3077,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -3310,7 +3310,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -3543,7 +3543,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -3776,7 +3776,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() @@ -4007,7 +4007,7 @@ internal class ErrorHandlingTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() 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 cbb5798a..1563de64 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 @@ -244,7 +244,7 @@ internal class ServiceParamsTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/AudienceServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/AudienceServiceAsyncTest.kt index 46e324db..cf2e9935 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/async/AudienceServiceAsyncTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/AudienceServiceAsyncTest.kt @@ -7,7 +7,7 @@ import com.courier.client.okhttp.CourierOkHttpClientAsync import com.courier.models.audiences.AudienceListMembersParams import com.courier.models.audiences.AudienceListParams import com.courier.models.audiences.AudienceUpdateParams -import com.courier.models.audiences.Filter +import com.courier.models.audiences.SingleFilterConfig import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -47,8 +47,8 @@ internal class AudienceServiceAsyncTest { .audienceId("audience_id") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() 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 b8d52beb..ed6f21d6 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 @@ -228,7 +228,7 @@ internal class SendServiceAsyncTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/AudienceServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/AudienceServiceTest.kt index 5ab40b46..07f1b335 100644 --- a/courier-java-core/src/test/kotlin/com/courier/services/blocking/AudienceServiceTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/AudienceServiceTest.kt @@ -7,7 +7,7 @@ import com.courier.client.okhttp.CourierOkHttpClient import com.courier.models.audiences.AudienceListMembersParams import com.courier.models.audiences.AudienceListParams import com.courier.models.audiences.AudienceUpdateParams -import com.courier.models.audiences.Filter +import com.courier.models.audiences.SingleFilterConfig import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -46,8 +46,8 @@ internal class AudienceServiceTest { .audienceId("audience_id") .description("description") .filter( - Filter.builder() - .operator(Filter.Operator.ENDS_WITH) + SingleFilterConfig.builder() + .operator(SingleFilterConfig.Operator.ENDS_WITH) .path("path") .value("value") .build() 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 bb0f32f5..dc2cc9d7 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 @@ -228,7 +228,7 @@ internal class SendServiceTest { .build() ) .tenantId("tenant_id") - .userId("example_user") + .userId("user_id") .build() ) .build() 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 0ec95c92..39234df5 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 @@ -5,8 +5,8 @@ package com.courier.proguard import com.courier.client.okhttp.CourierOkHttpClient import com.courier.core.jsonMapper import com.courier.models.Alignment -import com.courier.models.ElementalNode -import com.courier.models.ElementalTextNodeWithType +import com.courier.models.Discord +import com.courier.models.SendToChannel import com.courier.models.send.SendMessageResponse import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.reflect.full.memberFunctions @@ -84,26 +84,15 @@ internal class ProGuardCompatibilityTest { } @Test - fun elementalNodeRoundtrip() { + fun discordRoundtrip() { val jsonMapper = jsonMapper() - val elementalNode = - ElementalNode.ofTextNodeWithType( - ElementalTextNodeWithType.builder() - .addChannel("string") - .if_("if") - .loop("loop") - .ref("ref") - .type(ElementalTextNodeWithType.Type.TEXT) - .build() - ) + val discord = + Discord.ofSendToChannel(SendToChannel.builder().channelId("channel_id").build()) - val roundtrippedElementalNode = - jsonMapper.readValue( - jsonMapper.writeValueAsString(elementalNode), - jacksonTypeRef(), - ) + val roundtrippedDiscord = + jsonMapper.readValue(jsonMapper.writeValueAsString(discord), jacksonTypeRef()) - assertThat(roundtrippedElementalNode).isEqualTo(elementalNode) + assertThat(roundtrippedDiscord).isEqualTo(discord) } @Test From dde49686b275f99e28982bc8b210668a82de014d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 23:03:13 +0000 Subject: [PATCH 2/2] release: 4.5.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ README.md | 10 +++++----- build.gradle.kts | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 934f2cc0..3d5f4e35 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.4.0" + ".": "4.5.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 45abdcee..6bd51a46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 4.5.0 (2025-12-22) + +Full Changelog: [v4.4.0...v4.5.0](https://github.com/trycourier/courier-java/compare/v4.4.0...v4.5.0) + +### Features + +* **api:** add audience/list/slack/msTeams/pagerduty/webhook recipients, restructure to union ([46de0d2](https://github.com/trycourier/courier-java/commit/46de0d2d85f59c4d1d220dc3e3028c7e6760c769)) + ## 4.4.0 (2025-12-16) Full Changelog: [v4.3.0...v4.4.0](https://github.com/trycourier/courier-java/compare/v4.3.0...v4.4.0) diff --git a/README.md b/README.md index 8674e8ae..5ac7a1f8 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.courier/courier-java)](https://central.sonatype.com/artifact/com.courier/courier-java/4.4.0) -[![javadoc](https://javadoc.io/badge2/com.courier/courier-java/4.4.0/javadoc.svg)](https://javadoc.io/doc/com.courier/courier-java/4.4.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.courier/courier-java)](https://central.sonatype.com/artifact/com.courier/courier-java/4.5.0) +[![javadoc](https://javadoc.io/badge2/com.courier/courier-java/4.5.0/javadoc.svg)](https://javadoc.io/doc/com.courier/courier-java/4.5.0) @@ -13,7 +13,7 @@ It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [www.courier.com](https://www.courier.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.courier/courier-java/4.4.0). +The REST API documentation can be found on [www.courier.com](https://www.courier.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.courier/courier-java/4.5.0). @@ -24,7 +24,7 @@ The REST API documentation can be found on [www.courier.com](https://www.courier ### Gradle ```kotlin -implementation("com.courier:courier-java:4.4.0") +implementation("com.courier:courier-java:4.5.0") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.courier:courier-java:4.4.0") com.courier courier-java - 4.4.0 + 4.5.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 63460547..39beae8b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.courier" - version = "4.4.0" // x-release-please-version + version = "4.5.0" // x-release-please-version } subprojects {