diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 10f30916..6b7b74c5 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0" + ".": "0.3.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 7309c957..a0aad226 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 118 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/metronome/metronome-f7e0e0ddfc48af411be9cceb4ff2f2902fd49e10a0e37375e291c2a06a6ddf6d.yml -openapi_spec_hash: 51a0820e0399b218d44af30e9e0cb2da -config_hash: e73a5fed3fb2fc458b2cd21b1e3e7b91 +configured_endpoints: 115 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/metronome/metronome-f12f505faf40d5f25d74c0b5a417e2b36c7f3f9621a0e23acd3d6ec4c615443e.yml +openapi_spec_hash: 5c1f13896608a69feebd8855703b76df +config_hash: 6bd82f310398d5d47bcfeb8d7ed150b3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d15a619..db36ccd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## 0.3.0 (2026-05-29) + +Full Changelog: [v0.2.0...v0.3.0](https://github.com/Metronome-Industries/metronome-java/compare/v0.2.0...v0.3.0) + +### Features + +* [LAUNCH-2814] editContract returns full edit in the response ([8e77b8c](https://github.com/Metronome-Industries/metronome-java/commit/8e77b8c306f03efae58232e5f5c212ad42e2a0ae)) +* [orch-1860] remove all deprecated `/payments/*` endpoints from API ([d1ab06d](https://github.com/Metronome-Industries/metronome-java/commit/d1ab06d44d2a14a933564b1ea19953f66193ea50)) +* create contract returns contract data ([ed539ea](https://github.com/Metronome-Industries/metronome-java/commit/ed539ea6b6ae83b498b5669e86d67145e81b89fe)) +* nikku-orch-1723-update-create-contract ([c088c2a](https://github.com/Metronome-Industries/metronome-java/commit/c088c2afcc46740dc0b472722797006c135f8e80)) + + +### Chores + +* (internal) Add threshold balance specifier to contract create & edit, package create and both contract and package retrievals ([0f7d65f](https://github.com/Metronome-Industries/metronome-java/commit/0f7d65f597e64b05400557623bc7b90832639d3f)) + ## 0.2.0 (2026-05-18) Full Changelog: [v0.1.0...v0.2.0](https://github.com/Metronome-Industries/metronome-java/compare/v0.1.0...v0.2.0) diff --git a/README.md b/README.md index 6b4ff70b..c574abaa 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.metronome.api/metronome-java)](https://central.sonatype.com/artifact/com.metronome.api/metronome-java/0.2.0) -[![javadoc](https://javadoc.io/badge2/com.metronome.api/metronome-java/0.2.0/javadoc.svg)](https://javadoc.io/doc/com.metronome.api/metronome-java/0.2.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.metronome.api/metronome-java)](https://central.sonatype.com/artifact/com.metronome.api/metronome-java/0.3.0) +[![javadoc](https://javadoc.io/badge2/com.metronome.api/metronome-java/0.3.0/javadoc.svg)](https://javadoc.io/doc/com.metronome.api/metronome-java/0.3.0) @@ -20,7 +20,7 @@ Use the Metronome MCP Server to enable AI assistants to interact with this API, -The REST API documentation can be found on [docs.metronome.com](https://docs.metronome.com). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.metronome.api/metronome-java/0.2.0). +The REST API documentation can be found on [docs.metronome.com](https://docs.metronome.com). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.metronome.api/metronome-java/0.3.0). @@ -31,7 +31,7 @@ The REST API documentation can be found on [docs.metronome.com](https://docs.met ### Gradle ```kotlin -implementation("com.metronome.api:metronome-java:0.2.0") +implementation("com.metronome.api:metronome-java:0.3.0") ``` ### Maven @@ -40,7 +40,7 @@ implementation("com.metronome.api:metronome-java:0.2.0") com.metronome.api metronome-java - 0.2.0 + 0.3.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index b8b2f4f3..38cffb59 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.metronome.api" - version = "0.2.0" // x-release-please-version + version = "0.3.0" // x-release-please-version } subprojects { diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/Commit.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/Commit.kt index 8bd314fe..b636d72d 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/Commit.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/Commit.kt @@ -62,6 +62,7 @@ private constructor( private val rolloverFraction: JsonField, private val salesforceOpportunityId: JsonField, private val specifiers: JsonField>, + private val spendTrackerAttributes: JsonField, private val subscriptionConfig: JsonField, private val uniquenessKey: JsonField, private val additionalProperties: MutableMap, @@ -130,6 +131,9 @@ private constructor( @JsonProperty("specifiers") @ExcludeMissing specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + spendTrackerAttributes: JsonField = JsonMissing.of(), @JsonProperty("subscription_config") @ExcludeMissing subscriptionConfig: JsonField = JsonMissing.of(), @@ -164,6 +168,7 @@ private constructor( rolloverFraction, salesforceOpportunityId, specifiers, + spendTrackerAttributes, subscriptionConfig, uniquenessKey, mutableMapOf(), @@ -382,6 +387,15 @@ private constructor( */ fun specifiers(): Optional> = specifiers.getOptional("specifiers") + /** + * Optional attributes controlling how this commit interacts with spend trackers. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun spendTrackerAttributes(): Optional = + spendTrackerAttributes.getOptional("spend_tracker_attributes") + /** * The subscription configuration for this commit, if it was generated from a recurring commit * with a subscription attached. @@ -631,6 +645,16 @@ private constructor( @ExcludeMissing fun _specifiers(): JsonField> = specifiers + /** + * Returns the raw JSON value of [spendTrackerAttributes]. + * + * Unlike [spendTrackerAttributes], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + fun _spendTrackerAttributes(): JsonField = spendTrackerAttributes + /** * Returns the raw JSON value of [subscriptionConfig]. * @@ -709,6 +733,7 @@ private constructor( private var rolloverFraction: JsonField = JsonMissing.of() private var salesforceOpportunityId: JsonField = JsonMissing.of() private var specifiers: JsonField>? = null + private var spendTrackerAttributes: JsonField = JsonMissing.of() private var subscriptionConfig: JsonField = JsonMissing.of() private var uniquenessKey: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -742,6 +767,7 @@ private constructor( rolloverFraction = commit.rolloverFraction salesforceOpportunityId = commit.salesforceOpportunityId specifiers = commit.specifiers.map { it.toMutableList() } + spendTrackerAttributes = commit.spendTrackerAttributes subscriptionConfig = commit.subscriptionConfig uniquenessKey = commit.uniquenessKey additionalProperties = commit.additionalProperties.toMutableMap() @@ -1320,6 +1346,22 @@ private constructor( } } + /** Optional attributes controlling how this commit interacts with spend trackers. */ + fun spendTrackerAttributes(spendTrackerAttributes: SpendTrackerAttributes) = + spendTrackerAttributes(JsonField.of(spendTrackerAttributes)) + + /** + * Sets [Builder.spendTrackerAttributes] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAttributes] with a well-typed + * [SpendTrackerAttributes] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun spendTrackerAttributes(spendTrackerAttributes: JsonField) = + apply { + this.spendTrackerAttributes = spendTrackerAttributes + } + /** * The subscription configuration for this commit, if it was generated from a recurring * commit with a subscription attached. @@ -1419,6 +1461,7 @@ private constructor( rolloverFraction, salesforceOpportunityId, (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + spendTrackerAttributes, subscriptionConfig, uniquenessKey, additionalProperties.toMutableMap(), @@ -1467,6 +1510,7 @@ private constructor( rolloverFraction() salesforceOpportunityId() specifiers().ifPresent { it.forEach { it.validate() } } + spendTrackerAttributes().ifPresent { it.validate() } subscriptionConfig().ifPresent { it.validate() } uniquenessKey() validated = true @@ -1514,6 +1558,7 @@ private constructor( (if (rolloverFraction.asKnown().isPresent) 1 else 0) + (if (salesforceOpportunityId.asKnown().isPresent) 1 else 0) + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendTrackerAttributes.asKnown().getOrNull()?.validity() ?: 0) + (subscriptionConfig.asKnown().getOrNull()?.validity() ?: 0) + (if (uniquenessKey.asKnown().isPresent) 1 else 0) @@ -9937,6 +9982,187 @@ private constructor( "RolledOverFrom{commitId=$commitId, contractId=$contractId, additionalProperties=$additionalProperties}" } + /** Optional attributes controlling how this commit interacts with spend trackers. */ + class SpendTrackerAttributes + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val countsAsDiscounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("counts_as_discounted") + @ExcludeMissing + countsAsDiscounted: JsonField = JsonMissing.of() + ) : this(countsAsDiscounted, mutableMapOf()) + + /** + * If true, this commit is included in spend trackers with discounted set to DISCOUNTED_ONLY + * + * @throws MetronomeInvalidDataException 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 countsAsDiscounted(): Boolean = countsAsDiscounted.getRequired("counts_as_discounted") + + /** + * Returns the raw JSON value of [countsAsDiscounted]. + * + * Unlike [countsAsDiscounted], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("counts_as_discounted") + @ExcludeMissing + fun _countsAsDiscounted(): JsonField = countsAsDiscounted + + @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 [SpendTrackerAttributes]. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTrackerAttributes]. */ + class Builder internal constructor() { + + private var countsAsDiscounted: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTrackerAttributes: SpendTrackerAttributes) = apply { + countsAsDiscounted = spendTrackerAttributes.countsAsDiscounted + additionalProperties = spendTrackerAttributes.additionalProperties.toMutableMap() + } + + /** + * If true, this commit is included in spend trackers with discounted set to + * DISCOUNTED_ONLY + */ + fun countsAsDiscounted(countsAsDiscounted: Boolean) = + countsAsDiscounted(JsonField.of(countsAsDiscounted)) + + /** + * Sets [Builder.countsAsDiscounted] to an arbitrary JSON value. + * + * You should usually call [Builder.countsAsDiscounted] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun countsAsDiscounted(countsAsDiscounted: JsonField) = apply { + this.countsAsDiscounted = countsAsDiscounted + } + + 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 [SpendTrackerAttributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTrackerAttributes = + SpendTrackerAttributes( + checkRequired("countsAsDiscounted", countsAsDiscounted), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendTrackerAttributes = apply { + if (validated) { + return@apply + } + + countsAsDiscounted() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (countsAsDiscounted.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendTrackerAttributes && + countsAsDiscounted == other.countsAsDiscounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(countsAsDiscounted, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTrackerAttributes{countsAsDiscounted=$countsAsDiscounted, additionalProperties=$additionalProperties}" + } + /** * The subscription configuration for this commit, if it was generated from a recurring commit * with a subscription attached. @@ -10541,6 +10767,7 @@ private constructor( rolloverFraction == other.rolloverFraction && salesforceOpportunityId == other.salesforceOpportunityId && specifiers == other.specifiers && + spendTrackerAttributes == other.spendTrackerAttributes && subscriptionConfig == other.subscriptionConfig && uniquenessKey == other.uniquenessKey && additionalProperties == other.additionalProperties @@ -10575,6 +10802,7 @@ private constructor( rolloverFraction, salesforceOpportunityId, specifiers, + spendTrackerAttributes, subscriptionConfig, uniquenessKey, additionalProperties, @@ -10584,5 +10812,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Commit{id=$id, createdAt=$createdAt, product=$product, type=$type, accessSchedule=$accessSchedule, amount=$amount, applicableContractIds=$applicableContractIds, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, archivedAt=$archivedAt, balance=$balance, contract=$contract, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceContract=$invoiceContract, invoiceSchedule=$invoiceSchedule, ledger=$ledger, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, recurringCommitId=$recurringCommitId, rolledOverFrom=$rolledOverFrom, rolloverFraction=$rolloverFraction, salesforceOpportunityId=$salesforceOpportunityId, specifiers=$specifiers, subscriptionConfig=$subscriptionConfig, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" + "Commit{id=$id, createdAt=$createdAt, product=$product, type=$type, accessSchedule=$accessSchedule, amount=$amount, applicableContractIds=$applicableContractIds, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, archivedAt=$archivedAt, balance=$balance, contract=$contract, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceContract=$invoiceContract, invoiceSchedule=$invoiceSchedule, ledger=$ledger, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, recurringCommitId=$recurringCommitId, rolledOverFrom=$rolledOverFrom, rolloverFraction=$rolloverFraction, salesforceOpportunityId=$salesforceOpportunityId, specifiers=$specifiers, spendTrackerAttributes=$spendTrackerAttributes, subscriptionConfig=$subscriptionConfig, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" } diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/Contract.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/Contract.kt index 0f7c6e84..53a370f3 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/Contract.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/Contract.kt @@ -38,6 +38,7 @@ private constructor( JsonField, private val scheduledChargesOnUsageInvoices: JsonField, private val spendThresholdConfiguration: JsonField, + private val spendTrackers: JsonField>, private val subscriptions: JsonField>, private val uniquenessKey: JsonField, private val additionalProperties: MutableMap, @@ -80,6 +81,9 @@ private constructor( @JsonProperty("spend_threshold_configuration") @ExcludeMissing spendThresholdConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("spend_trackers") + @ExcludeMissing + spendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("subscriptions") @ExcludeMissing subscriptions: JsonField> = JsonMissing.of(), @@ -99,6 +103,7 @@ private constructor( prepaidBalanceThresholdConfiguration, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, uniquenessKey, mutableMapOf(), @@ -194,6 +199,14 @@ private constructor( fun spendThresholdConfiguration(): Optional = spendThresholdConfiguration.getOptional("spend_threshold_configuration") + /** + * Spend trackers attached to this contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = spendTrackers.getOptional("spend_trackers") + /** * List of subscriptions on the contract. * @@ -322,6 +335,15 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = spendThresholdConfiguration + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("spend_trackers") + @ExcludeMissing + fun _spendTrackers(): JsonField> = spendTrackers + /** * Returns the raw JSON value of [subscriptions]. * @@ -390,6 +412,7 @@ private constructor( JsonMissing.of() private var spendThresholdConfiguration: JsonField = JsonMissing.of() + private var spendTrackers: JsonField>? = null private var subscriptions: JsonField>? = null private var uniquenessKey: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -408,6 +431,7 @@ private constructor( prepaidBalanceThresholdConfiguration = contract.prepaidBalanceThresholdConfiguration scheduledChargesOnUsageInvoices = contract.scheduledChargesOnUsageInvoices spendThresholdConfiguration = contract.spendThresholdConfiguration + spendTrackers = contract.spendTrackers.map { it.toMutableList() } subscriptions = contract.subscriptions.map { it.toMutableList() } uniquenessKey = contract.uniquenessKey additionalProperties = contract.additionalProperties.toMutableMap() @@ -598,6 +622,33 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { this.spendThresholdConfiguration = spendThresholdConfiguration } + /** Spend trackers attached to this contract. */ + fun spendTrackers(spendTrackers: List) = + spendTrackers(JsonField.of(spendTrackers)) + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + this.spendTrackers = spendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + spendTrackers = + (spendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("spendTrackers", it).add(spendTracker) + } + } + /** List of subscriptions on the contract. */ fun subscriptions(subscriptions: List) = subscriptions(JsonField.of(subscriptions)) @@ -692,6 +743,7 @@ private constructor( prepaidBalanceThresholdConfiguration, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + (spendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, (subscriptions ?: JsonMissing.of()).map { it.toImmutable() }, uniquenessKey, additionalProperties.toMutableMap(), @@ -725,6 +777,7 @@ private constructor( prepaidBalanceThresholdConfiguration().ifPresent { it.validate() } scheduledChargesOnUsageInvoices().ifPresent { it.validate() } spendThresholdConfiguration().ifPresent { it.validate() } + spendTrackers().ifPresent { it.forEach { it.validate() } } subscriptions().ifPresent { it.forEach { it.validate() } } uniquenessKey() validated = true @@ -757,6 +810,7 @@ private constructor( (prepaidBalanceThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + (scheduledChargesOnUsageInvoices.asKnown().getOrNull()?.validity() ?: 0) + (spendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (spendTrackers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (subscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (uniquenessKey.asKnown().isPresent) 1 else 0) @@ -3359,6 +3413,1483 @@ private constructor( override fun toString() = value.toString() } + class SpendTracker + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val alias: JsonField, + private val applicableSpendSpecifiers: JsonField>, + private val creditTypeId: JsonField, + private val resetFrequency: JsonField, + private val accumulatedSpend: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("alias") @ExcludeMissing alias: JsonField = JsonMissing.of(), + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + applicableSpendSpecifiers: JsonField> = JsonMissing.of(), + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("reset_frequency") + @ExcludeMissing + resetFrequency: JsonField = JsonMissing.of(), + @JsonProperty("accumulated_spend") + @ExcludeMissing + accumulatedSpend: JsonField = JsonMissing.of(), + ) : this( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + accumulatedSpend, + mutableMapOf(), + ) + + /** + * Human-readable identifier, unique per contract. + * + * @throws MetronomeInvalidDataException 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 alias(): String = alias.getRequired("alias") + + /** + * @throws MetronomeInvalidDataException 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 applicableSpendSpecifiers(): List = + applicableSpendSpecifiers.getRequired("applicable_spend_specifiers") + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 resetFrequency(): ResetFrequency = resetFrequency.getRequired("reset_frequency") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun accumulatedSpend(): Optional = + accumulatedSpend.getOptional("accumulated_spend") + + /** + * Returns the raw JSON value of [alias]. + * + * Unlike [alias], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("alias") @ExcludeMissing fun _alias(): JsonField = alias + + /** + * Returns the raw JSON value of [applicableSpendSpecifiers]. + * + * Unlike [applicableSpendSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + fun _applicableSpendSpecifiers(): JsonField> = + applicableSpendSpecifiers + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [resetFrequency]. + * + * Unlike [resetFrequency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("reset_frequency") + @ExcludeMissing + fun _resetFrequency(): JsonField = resetFrequency + + /** + * Returns the raw JSON value of [accumulatedSpend]. + * + * Unlike [accumulatedSpend], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("accumulated_spend") + @ExcludeMissing + fun _accumulatedSpend(): JsonField = accumulatedSpend + + @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 [SpendTracker]. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTracker]. */ + class Builder internal constructor() { + + private var alias: JsonField? = null + private var applicableSpendSpecifiers: + JsonField>? = + null + private var creditTypeId: JsonField? = null + private var resetFrequency: JsonField? = null + private var accumulatedSpend: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTracker: SpendTracker) = apply { + alias = spendTracker.alias + applicableSpendSpecifiers = + spendTracker.applicableSpendSpecifiers.map { it.toMutableList() } + creditTypeId = spendTracker.creditTypeId + resetFrequency = spendTracker.resetFrequency + accumulatedSpend = spendTracker.accumulatedSpend + additionalProperties = spendTracker.additionalProperties.toMutableMap() + } + + /** Human-readable identifier, unique per contract. */ + fun alias(alias: String) = alias(JsonField.of(alias)) + + /** + * Sets [Builder.alias] to an arbitrary JSON value. + * + * You should usually call [Builder.alias] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun alias(alias: JsonField) = apply { this.alias = alias } + + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: List + ) = applicableSpendSpecifiers(JsonField.of(applicableSpendSpecifiers)) + + /** + * Sets [Builder.applicableSpendSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableSpendSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: JsonField> + ) = apply { + this.applicableSpendSpecifiers = + applicableSpendSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ApplicableSpendSpecifier] to [applicableSpendSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableSpendSpecifier(applicableSpendSpecifier: ApplicableSpendSpecifier) = + apply { + applicableSpendSpecifiers = + (applicableSpendSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableSpendSpecifiers", it) + .add(applicableSpendSpecifier) + } + } + + fun creditTypeId(creditTypeId: String) = creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun resetFrequency(resetFrequency: ResetFrequency) = + resetFrequency(JsonField.of(resetFrequency)) + + /** + * Sets [Builder.resetFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.resetFrequency] with a well-typed [ResetFrequency] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun resetFrequency(resetFrequency: JsonField) = apply { + this.resetFrequency = resetFrequency + } + + fun accumulatedSpend(accumulatedSpend: AccumulatedSpend) = + accumulatedSpend(JsonField.of(accumulatedSpend)) + + /** + * Sets [Builder.accumulatedSpend] to an arbitrary JSON value. + * + * You should usually call [Builder.accumulatedSpend] with a well-typed + * [AccumulatedSpend] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun accumulatedSpend(accumulatedSpend: JsonField) = apply { + this.accumulatedSpend = accumulatedSpend + } + + 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 [SpendTracker]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTracker = + SpendTracker( + checkRequired("alias", alias), + checkRequired("applicableSpendSpecifiers", applicableSpendSpecifiers).map { + it.toImmutable() + }, + checkRequired("creditTypeId", creditTypeId), + checkRequired("resetFrequency", resetFrequency), + accumulatedSpend, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendTracker = apply { + if (validated) { + return@apply + } + + alias() + applicableSpendSpecifiers().forEach { it.validate() } + creditTypeId() + resetFrequency().validate() + accumulatedSpend().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (alias.asKnown().isPresent) 1 else 0) + + (applicableSpendSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (creditTypeId.asKnown().isPresent) 1 else 0) + + (resetFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (accumulatedSpend.asKnown().getOrNull()?.validity() ?: 0) + + class ApplicableSpendSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sources: JsonField>, + private val spendType: JsonField, + private val discounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("sources") + @ExcludeMissing + sources: JsonField> = JsonMissing.of(), + @JsonProperty("spend_type") + @ExcludeMissing + spendType: JsonField = JsonMissing.of(), + @JsonProperty("discounted") + @ExcludeMissing + discounted: JsonField = JsonMissing.of(), + ) : this(sources, spendType, discounted, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 sources(): List = sources.getRequired("sources") + + /** + * @throws MetronomeInvalidDataException 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 spendType(): SpendType = spendType.getRequired("spend_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun discounted(): Optional = discounted.getOptional("discounted") + + /** + * Returns the raw JSON value of [sources]. + * + * Unlike [sources], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sources") + @ExcludeMissing + fun _sources(): JsonField> = sources + + /** + * Returns the raw JSON value of [spendType]. + * + * Unlike [spendType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_type") + @ExcludeMissing + fun _spendType(): JsonField = spendType + + /** + * Returns the raw JSON value of [discounted]. + * + * Unlike [discounted], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("discounted") + @ExcludeMissing + fun _discounted(): JsonField = discounted + + @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 + * [ApplicableSpendSpecifier]. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApplicableSpendSpecifier]. */ + class Builder internal constructor() { + + private var sources: JsonField>? = null + private var spendType: JsonField? = null + private var discounted: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { + sources = applicableSpendSpecifier.sources.map { it.toMutableList() } + spendType = applicableSpendSpecifier.spendType + discounted = applicableSpendSpecifier.discounted + additionalProperties = + applicableSpendSpecifier.additionalProperties.toMutableMap() + } + + fun sources(sources: List) = sources(JsonField.of(sources)) + + /** + * Sets [Builder.sources] to an arbitrary JSON value. + * + * You should usually call [Builder.sources] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun sources(sources: JsonField>) = apply { + this.sources = sources.map { it.toMutableList() } + } + + /** + * Adds a single [Source] to [sources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: Source) = apply { + sources = + (sources ?: JsonField.of(mutableListOf())).also { + checkKnown("sources", it).add(source) + } + } + + fun spendType(spendType: SpendType) = spendType(JsonField.of(spendType)) + + /** + * Sets [Builder.spendType] to an arbitrary JSON value. + * + * You should usually call [Builder.spendType] with a well-typed [SpendType] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendType(spendType: JsonField) = apply { + this.spendType = spendType + } + + fun discounted(discounted: Discounted) = discounted(JsonField.of(discounted)) + + /** + * Sets [Builder.discounted] to an arbitrary JSON value. + * + * You should usually call [Builder.discounted] with a well-typed [Discounted] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun discounted(discounted: JsonField) = apply { + this.discounted = discounted + } + + 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 [ApplicableSpendSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApplicableSpendSpecifier = + ApplicableSpendSpecifier( + checkRequired("sources", sources).map { it.toImmutable() }, + checkRequired("spendType", spendType), + discounted, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ApplicableSpendSpecifier = apply { + if (validated) { + return@apply + } + + sources().forEach { it.validate() } + spendType().validate() + discounted().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (sources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendType.asKnown().getOrNull()?.validity() ?: 0) + + (discounted.asKnown().getOrNull()?.validity() ?: 0) + + class Source @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 THRESHOLD_RECHARGE = of("THRESHOLD_RECHARGE") + + @JvmField val MANUAL = of("MANUAL") + + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) + } + + /** An enum containing [Source]'s known values. */ + enum class Known { + THRESHOLD_RECHARGE, + MANUAL, + } + + /** + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Source] 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 { + THRESHOLD_RECHARGE, + MANUAL, + /** + * An enum member indicating that [Source] 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) { + THRESHOLD_RECHARGE -> Value.THRESHOLD_RECHARGE + MANUAL -> Value.MANUAL + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + THRESHOLD_RECHARGE -> Known.THRESHOLD_RECHARGE + MANUAL -> Known.MANUAL + else -> throw MetronomeInvalidDataException("Unknown Source: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Source && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SpendType @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 COMMIT_PURCHASE = of("COMMIT_PURCHASE") + + @JvmStatic fun of(value: String) = SpendType(JsonField.of(value)) + } + + /** An enum containing [SpendType]'s known values. */ + enum class Known { + COMMIT_PURCHASE + } + + /** + * An enum containing [SpendType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SpendType] 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 { + COMMIT_PURCHASE, + /** + * An enum member indicating that [SpendType] 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) { + COMMIT_PURCHASE -> Value.COMMIT_PURCHASE + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + COMMIT_PURCHASE -> Known.COMMIT_PURCHASE + else -> throw MetronomeInvalidDataException("Unknown SpendType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): SpendType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 SpendType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Discounted + @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 ANY = of("ANY") + + @JvmField val DISCOUNTED_ONLY = of("DISCOUNTED_ONLY") + + @JvmField val UNDISCOUNTED_ONLY = of("UNDISCOUNTED_ONLY") + + @JvmStatic fun of(value: String) = Discounted(JsonField.of(value)) + } + + /** An enum containing [Discounted]'s known values. */ + enum class Known { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + } + + /** + * An enum containing [Discounted]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Discounted] 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 { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + /** + * An enum member indicating that [Discounted] 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) { + ANY -> Value.ANY + DISCOUNTED_ONLY -> Value.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Value.UNDISCOUNTED_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANY -> Known.ANY + DISCOUNTED_ONLY -> Known.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Known.UNDISCOUNTED_ONLY + else -> throw MetronomeInvalidDataException("Unknown Discounted: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Discounted = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Discounted && 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 ApplicableSpendSpecifier && + sources == other.sources && + spendType == other.spendType && + discounted == other.discounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(sources, spendType, discounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ApplicableSpendSpecifier{sources=$sources, spendType=$spendType, discounted=$discounted, additionalProperties=$additionalProperties}" + } + + class ResetFrequency + @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 BILLING_PERIOD = of("BILLING_PERIOD") + + @JvmStatic fun of(value: String) = ResetFrequency(JsonField.of(value)) + } + + /** An enum containing [ResetFrequency]'s known values. */ + enum class Known { + BILLING_PERIOD + } + + /** + * An enum containing [ResetFrequency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ResetFrequency] 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 { + BILLING_PERIOD, + /** + * An enum member indicating that [ResetFrequency] 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) { + BILLING_PERIOD -> Value.BILLING_PERIOD + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + BILLING_PERIOD -> Known.BILLING_PERIOD + else -> throw MetronomeInvalidDataException("Unknown ResetFrequency: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ResetFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ResetFrequency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class AccumulatedSpend + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val periodEndingBefore: JsonField, + private val periodStartingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("period_ending_before") + @ExcludeMissing + periodEndingBefore: JsonField = JsonMissing.of(), + @JsonProperty("period_starting_at") + @ExcludeMissing + periodStartingAt: JsonField = JsonMissing.of(), + ) : this(amount, periodEndingBefore, periodStartingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * @throws MetronomeInvalidDataException 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 periodEndingBefore(): OffsetDateTime = + periodEndingBefore.getRequired("period_ending_before") + + /** + * @throws MetronomeInvalidDataException 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 periodStartingAt(): OffsetDateTime = + periodStartingAt.getRequired("period_starting_at") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [periodEndingBefore]. + * + * Unlike [periodEndingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("period_ending_before") + @ExcludeMissing + fun _periodEndingBefore(): JsonField = periodEndingBefore + + /** + * Returns the raw JSON value of [periodStartingAt]. + * + * Unlike [periodStartingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("period_starting_at") + @ExcludeMissing + fun _periodStartingAt(): JsonField = periodStartingAt + + @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 [AccumulatedSpend]. + * + * The following fields are required: + * ```java + * .amount() + * .periodEndingBefore() + * .periodStartingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccumulatedSpend]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var periodEndingBefore: JsonField? = null + private var periodStartingAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(accumulatedSpend: AccumulatedSpend) = apply { + amount = accumulatedSpend.amount + periodEndingBefore = accumulatedSpend.periodEndingBefore + periodStartingAt = accumulatedSpend.periodStartingAt + additionalProperties = accumulatedSpend.additionalProperties.toMutableMap() + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun periodEndingBefore(periodEndingBefore: OffsetDateTime) = + periodEndingBefore(JsonField.of(periodEndingBefore)) + + /** + * Sets [Builder.periodEndingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.periodEndingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun periodEndingBefore(periodEndingBefore: JsonField) = apply { + this.periodEndingBefore = periodEndingBefore + } + + fun periodStartingAt(periodStartingAt: OffsetDateTime) = + periodStartingAt(JsonField.of(periodStartingAt)) + + /** + * Sets [Builder.periodStartingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.periodStartingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun periodStartingAt(periodStartingAt: JsonField) = apply { + this.periodStartingAt = periodStartingAt + } + + 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 [AccumulatedSpend]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .periodEndingBefore() + * .periodStartingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AccumulatedSpend = + AccumulatedSpend( + checkRequired("amount", amount), + checkRequired("periodEndingBefore", periodEndingBefore), + checkRequired("periodStartingAt", periodStartingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): AccumulatedSpend = apply { + if (validated) { + return@apply + } + + amount() + periodEndingBefore() + periodStartingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (periodEndingBefore.asKnown().isPresent) 1 else 0) + + (if (periodStartingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccumulatedSpend && + amount == other.amount && + periodEndingBefore == other.periodEndingBefore && + periodStartingAt == other.periodStartingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, periodEndingBefore, periodStartingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccumulatedSpend{amount=$amount, periodEndingBefore=$periodEndingBefore, periodStartingAt=$periodStartingAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendTracker && + alias == other.alias && + applicableSpendSpecifiers == other.applicableSpendSpecifiers && + creditTypeId == other.creditTypeId && + resetFrequency == other.resetFrequency && + accumulatedSpend == other.accumulatedSpend && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + accumulatedSpend, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTracker{alias=$alias, applicableSpendSpecifiers=$applicableSpendSpecifiers, creditTypeId=$creditTypeId, resetFrequency=$resetFrequency, accumulatedSpend=$accumulatedSpend, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3377,6 +4908,7 @@ private constructor( prepaidBalanceThresholdConfiguration == other.prepaidBalanceThresholdConfiguration && scheduledChargesOnUsageInvoices == other.scheduledChargesOnUsageInvoices && spendThresholdConfiguration == other.spendThresholdConfiguration && + spendTrackers == other.spendTrackers && subscriptions == other.subscriptions && uniquenessKey == other.uniquenessKey && additionalProperties == other.additionalProperties @@ -3396,6 +4928,7 @@ private constructor( prepaidBalanceThresholdConfiguration, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, uniquenessKey, additionalProperties, @@ -3405,5 +4938,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Contract{id=$id, amendments=$amendments, current=$current, customerId=$customerId, initial=$initial, archivedAt=$archivedAt, customFields=$customFields, customerBillingProviderConfiguration=$customerBillingProviderConfiguration, packageId=$packageId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" + "Contract{id=$id, amendments=$amendments, current=$current, customerId=$customerId, initial=$initial, archivedAt=$archivedAt, customFields=$customFields, customerBillingProviderConfiguration=$customerBillingProviderConfiguration, packageId=$packageId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, spendTrackers=$spendTrackers, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" } diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/ContractV2.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/ContractV2.kt index 5763bec6..1a0823e2 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/ContractV2.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/ContractV2.kt @@ -70,6 +70,7 @@ private constructor( private val salesforceOpportunityId: JsonField, private val scheduledChargesOnUsageInvoices: JsonField, private val spendThresholdConfiguration: JsonField, + private val spendTrackers: JsonField>, private val subscriptions: JsonField>, private val totalContractValue: JsonField, private val uniquenessKey: JsonField, @@ -171,6 +172,9 @@ private constructor( @JsonProperty("spend_threshold_configuration") @ExcludeMissing spendThresholdConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("spend_trackers") + @ExcludeMissing + spendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("subscriptions") @ExcludeMissing subscriptions: JsonField> = JsonMissing.of(), @@ -214,6 +218,7 @@ private constructor( salesforceOpportunityId, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, totalContractValue, uniquenessKey, @@ -464,6 +469,14 @@ private constructor( fun spendThresholdConfiguration(): Optional = spendThresholdConfiguration.getOptional("spend_threshold_configuration") + /** + * Spend trackers attached to this contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = spendTrackers.getOptional("spend_trackers") + /** * List of subscriptions on the contract. * @@ -786,6 +799,15 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = spendThresholdConfiguration + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("spend_trackers") + @ExcludeMissing + fun _spendTrackers(): JsonField> = spendTrackers + /** * Returns the raw JSON value of [subscriptions]. * @@ -892,6 +914,7 @@ private constructor( JsonMissing.of() private var spendThresholdConfiguration: JsonField = JsonMissing.of() + private var spendTrackers: JsonField>? = null private var subscriptions: JsonField>? = null private var totalContractValue: JsonField = JsonMissing.of() private var uniquenessKey: JsonField = JsonMissing.of() @@ -932,6 +955,7 @@ private constructor( salesforceOpportunityId = contractV2.salesforceOpportunityId scheduledChargesOnUsageInvoices = contractV2.scheduledChargesOnUsageInvoices spendThresholdConfiguration = contractV2.spendThresholdConfiguration + spendTrackers = contractV2.spendTrackers.map { it.toMutableList() } subscriptions = contractV2.subscriptions.map { it.toMutableList() } totalContractValue = contractV2.totalContractValue uniquenessKey = contractV2.uniquenessKey @@ -1552,6 +1576,33 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { this.spendThresholdConfiguration = spendThresholdConfiguration } + /** Spend trackers attached to this contract. */ + fun spendTrackers(spendTrackers: List) = + spendTrackers(JsonField.of(spendTrackers)) + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + this.spendTrackers = spendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + spendTrackers = + (spendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("spendTrackers", it).add(spendTracker) + } + } + /** List of subscriptions on the contract. */ fun subscriptions(subscriptions: List) = subscriptions(JsonField.of(subscriptions)) @@ -1683,6 +1734,7 @@ private constructor( salesforceOpportunityId, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + (spendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, (subscriptions ?: JsonMissing.of()).map { it.toImmutable() }, totalContractValue, uniquenessKey, @@ -1738,6 +1790,7 @@ private constructor( salesforceOpportunityId() scheduledChargesOnUsageInvoices().ifPresent { it.validate() } spendThresholdConfiguration().ifPresent { it.validate() } + spendTrackers().ifPresent { it.forEach { it.validate() } } subscriptions().ifPresent { it.forEach { it.validate() } } totalContractValue() uniquenessKey() @@ -1792,6 +1845,7 @@ private constructor( (if (salesforceOpportunityId.asKnown().isPresent) 1 else 0) + (scheduledChargesOnUsageInvoices.asKnown().getOrNull()?.validity() ?: 0) + (spendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (spendTrackers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (subscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (totalContractValue.asKnown().isPresent) 1 else 0) + (if (uniquenessKey.asKnown().isPresent) 1 else 0) @@ -1825,6 +1879,7 @@ private constructor( private val rolloverFraction: JsonField, private val salesforceOpportunityId: JsonField, private val specifiers: JsonField>, + private val spendTrackerAttributes: JsonField, private val subscriptionConfig: JsonField, private val additionalProperties: MutableMap, ) { @@ -1899,6 +1954,9 @@ private constructor( @JsonProperty("specifiers") @ExcludeMissing specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + spendTrackerAttributes: JsonField = JsonMissing.of(), @JsonProperty("subscription_config") @ExcludeMissing subscriptionConfig: JsonField = JsonMissing.of(), @@ -1929,6 +1987,7 @@ private constructor( rolloverFraction, salesforceOpportunityId, specifiers, + spendTrackerAttributes, subscriptionConfig, mutableMapOf(), ) @@ -2138,6 +2197,15 @@ private constructor( */ fun specifiers(): Optional> = specifiers.getOptional("specifiers") + /** + * Optional attributes controlling how this commit interacts with spend trackers. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun spendTrackerAttributes(): Optional = + spendTrackerAttributes.getOptional("spend_tracker_attributes") + /** * Attach a subscription to the recurring commit/credit. * @@ -2377,6 +2445,16 @@ private constructor( @ExcludeMissing fun _specifiers(): JsonField> = specifiers + /** + * Returns the raw JSON value of [spendTrackerAttributes]. + * + * Unlike [spendTrackerAttributes], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + fun _spendTrackerAttributes(): JsonField = spendTrackerAttributes + /** * Returns the raw JSON value of [subscriptionConfig]. * @@ -2445,6 +2523,7 @@ private constructor( private var rolloverFraction: JsonField = JsonMissing.of() private var salesforceOpportunityId: JsonField = JsonMissing.of() private var specifiers: JsonField>? = null + private var spendTrackerAttributes: JsonField = JsonMissing.of() private var subscriptionConfig: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -2477,6 +2556,7 @@ private constructor( rolloverFraction = commit.rolloverFraction salesforceOpportunityId = commit.salesforceOpportunityId specifiers = commit.specifiers.map { it.toMutableList() } + spendTrackerAttributes = commit.spendTrackerAttributes subscriptionConfig = commit.subscriptionConfig additionalProperties = commit.additionalProperties.toMutableMap() } @@ -3073,6 +3153,22 @@ private constructor( } } + /** Optional attributes controlling how this commit interacts with spend trackers. */ + fun spendTrackerAttributes(spendTrackerAttributes: SpendTrackerAttributes) = + spendTrackerAttributes(JsonField.of(spendTrackerAttributes)) + + /** + * Sets [Builder.spendTrackerAttributes] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAttributes] with a well-typed + * [SpendTrackerAttributes] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun spendTrackerAttributes(spendTrackerAttributes: JsonField) = + apply { + this.spendTrackerAttributes = spendTrackerAttributes + } + /** Attach a subscription to the recurring commit/credit. */ fun subscriptionConfig(subscriptionConfig: RecurringCommitSubscriptionConfig) = subscriptionConfig(JsonField.of(subscriptionConfig)) @@ -3150,6 +3246,7 @@ private constructor( rolloverFraction, salesforceOpportunityId, (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + spendTrackerAttributes, subscriptionConfig, additionalProperties.toMutableMap(), ) @@ -3197,6 +3294,7 @@ private constructor( rolloverFraction() salesforceOpportunityId() specifiers().ifPresent { it.forEach { it.validate() } } + spendTrackerAttributes().ifPresent { it.validate() } subscriptionConfig().ifPresent { it.validate() } validated = true } @@ -3243,6 +3341,7 @@ private constructor( (if (rolloverFraction.asKnown().isPresent) 1 else 0) + (if (salesforceOpportunityId.asKnown().isPresent) 1 else 0) + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendTrackerAttributes.asKnown().getOrNull()?.validity() ?: 0) + (subscriptionConfig.asKnown().getOrNull()?.validity() ?: 0) class Product @@ -11881,6 +11980,198 @@ private constructor( "RolledOverFrom{commitId=$commitId, contractId=$contractId, additionalProperties=$additionalProperties}" } + /** Optional attributes controlling how this commit interacts with spend trackers. */ + class SpendTrackerAttributes + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val countsAsDiscounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("counts_as_discounted") + @ExcludeMissing + countsAsDiscounted: JsonField = JsonMissing.of() + ) : this(countsAsDiscounted, mutableMapOf()) + + /** + * If true, this commit is included in spend trackers with discounted set to + * DISCOUNTED_ONLY + * + * @throws MetronomeInvalidDataException 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 countsAsDiscounted(): Boolean = + countsAsDiscounted.getRequired("counts_as_discounted") + + /** + * Returns the raw JSON value of [countsAsDiscounted]. + * + * Unlike [countsAsDiscounted], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("counts_as_discounted") + @ExcludeMissing + fun _countsAsDiscounted(): JsonField = countsAsDiscounted + + @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 + * [SpendTrackerAttributes]. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTrackerAttributes]. */ + class Builder internal constructor() { + + private var countsAsDiscounted: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTrackerAttributes: SpendTrackerAttributes) = apply { + countsAsDiscounted = spendTrackerAttributes.countsAsDiscounted + additionalProperties = + spendTrackerAttributes.additionalProperties.toMutableMap() + } + + /** + * If true, this commit is included in spend trackers with discounted set to + * DISCOUNTED_ONLY + */ + fun countsAsDiscounted(countsAsDiscounted: Boolean) = + countsAsDiscounted(JsonField.of(countsAsDiscounted)) + + /** + * Sets [Builder.countsAsDiscounted] to an arbitrary JSON value. + * + * You should usually call [Builder.countsAsDiscounted] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun countsAsDiscounted(countsAsDiscounted: JsonField) = apply { + this.countsAsDiscounted = countsAsDiscounted + } + + 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 [SpendTrackerAttributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTrackerAttributes = + SpendTrackerAttributes( + checkRequired("countsAsDiscounted", countsAsDiscounted), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SpendTrackerAttributes = apply { + if (validated) { + return@apply + } + + countsAsDiscounted() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (countsAsDiscounted.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendTrackerAttributes && + countsAsDiscounted == other.countsAsDiscounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(countsAsDiscounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTrackerAttributes{countsAsDiscounted=$countsAsDiscounted, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -11913,6 +12204,7 @@ private constructor( rolloverFraction == other.rolloverFraction && salesforceOpportunityId == other.salesforceOpportunityId && specifiers == other.specifiers && + spendTrackerAttributes == other.spendTrackerAttributes && subscriptionConfig == other.subscriptionConfig && additionalProperties == other.additionalProperties } @@ -11945,6 +12237,7 @@ private constructor( rolloverFraction, salesforceOpportunityId, specifiers, + spendTrackerAttributes, subscriptionConfig, additionalProperties, ) @@ -11953,7 +12246,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Commit{id=$id, createdAt=$createdAt, product=$product, type=$type, accessSchedule=$accessSchedule, applicableContractIds=$applicableContractIds, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, archivedAt=$archivedAt, balance=$balance, contract=$contract, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceContract=$invoiceContract, invoiceSchedule=$invoiceSchedule, ledger=$ledger, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, recurringCommitId=$recurringCommitId, rolledOverFrom=$rolledOverFrom, rolloverFraction=$rolloverFraction, salesforceOpportunityId=$salesforceOpportunityId, specifiers=$specifiers, subscriptionConfig=$subscriptionConfig, additionalProperties=$additionalProperties}" + "Commit{id=$id, createdAt=$createdAt, product=$product, type=$type, accessSchedule=$accessSchedule, applicableContractIds=$applicableContractIds, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, archivedAt=$archivedAt, balance=$balance, contract=$contract, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceContract=$invoiceContract, invoiceSchedule=$invoiceSchedule, ledger=$ledger, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, recurringCommitId=$recurringCommitId, rolledOverFrom=$rolledOverFrom, rolloverFraction=$rolloverFraction, salesforceOpportunityId=$salesforceOpportunityId, specifiers=$specifiers, spendTrackerAttributes=$spendTrackerAttributes, subscriptionConfig=$subscriptionConfig, additionalProperties=$additionalProperties}" } class Override @@ -32168,6 +32461,1483 @@ private constructor( override fun toString() = value.toString() } + class SpendTracker + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val alias: JsonField, + private val applicableSpendSpecifiers: JsonField>, + private val creditTypeId: JsonField, + private val resetFrequency: JsonField, + private val accumulatedSpend: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("alias") @ExcludeMissing alias: JsonField = JsonMissing.of(), + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + applicableSpendSpecifiers: JsonField> = JsonMissing.of(), + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("reset_frequency") + @ExcludeMissing + resetFrequency: JsonField = JsonMissing.of(), + @JsonProperty("accumulated_spend") + @ExcludeMissing + accumulatedSpend: JsonField = JsonMissing.of(), + ) : this( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + accumulatedSpend, + mutableMapOf(), + ) + + /** + * Human-readable identifier, unique per contract. + * + * @throws MetronomeInvalidDataException 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 alias(): String = alias.getRequired("alias") + + /** + * @throws MetronomeInvalidDataException 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 applicableSpendSpecifiers(): List = + applicableSpendSpecifiers.getRequired("applicable_spend_specifiers") + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 resetFrequency(): ResetFrequency = resetFrequency.getRequired("reset_frequency") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun accumulatedSpend(): Optional = + accumulatedSpend.getOptional("accumulated_spend") + + /** + * Returns the raw JSON value of [alias]. + * + * Unlike [alias], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("alias") @ExcludeMissing fun _alias(): JsonField = alias + + /** + * Returns the raw JSON value of [applicableSpendSpecifiers]. + * + * Unlike [applicableSpendSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + fun _applicableSpendSpecifiers(): JsonField> = + applicableSpendSpecifiers + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [resetFrequency]. + * + * Unlike [resetFrequency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("reset_frequency") + @ExcludeMissing + fun _resetFrequency(): JsonField = resetFrequency + + /** + * Returns the raw JSON value of [accumulatedSpend]. + * + * Unlike [accumulatedSpend], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("accumulated_spend") + @ExcludeMissing + fun _accumulatedSpend(): JsonField = accumulatedSpend + + @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 [SpendTracker]. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTracker]. */ + class Builder internal constructor() { + + private var alias: JsonField? = null + private var applicableSpendSpecifiers: + JsonField>? = + null + private var creditTypeId: JsonField? = null + private var resetFrequency: JsonField? = null + private var accumulatedSpend: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTracker: SpendTracker) = apply { + alias = spendTracker.alias + applicableSpendSpecifiers = + spendTracker.applicableSpendSpecifiers.map { it.toMutableList() } + creditTypeId = spendTracker.creditTypeId + resetFrequency = spendTracker.resetFrequency + accumulatedSpend = spendTracker.accumulatedSpend + additionalProperties = spendTracker.additionalProperties.toMutableMap() + } + + /** Human-readable identifier, unique per contract. */ + fun alias(alias: String) = alias(JsonField.of(alias)) + + /** + * Sets [Builder.alias] to an arbitrary JSON value. + * + * You should usually call [Builder.alias] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun alias(alias: JsonField) = apply { this.alias = alias } + + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: List + ) = applicableSpendSpecifiers(JsonField.of(applicableSpendSpecifiers)) + + /** + * Sets [Builder.applicableSpendSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableSpendSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: JsonField> + ) = apply { + this.applicableSpendSpecifiers = + applicableSpendSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ApplicableSpendSpecifier] to [applicableSpendSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableSpendSpecifier(applicableSpendSpecifier: ApplicableSpendSpecifier) = + apply { + applicableSpendSpecifiers = + (applicableSpendSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableSpendSpecifiers", it) + .add(applicableSpendSpecifier) + } + } + + fun creditTypeId(creditTypeId: String) = creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun resetFrequency(resetFrequency: ResetFrequency) = + resetFrequency(JsonField.of(resetFrequency)) + + /** + * Sets [Builder.resetFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.resetFrequency] with a well-typed [ResetFrequency] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun resetFrequency(resetFrequency: JsonField) = apply { + this.resetFrequency = resetFrequency + } + + fun accumulatedSpend(accumulatedSpend: AccumulatedSpend) = + accumulatedSpend(JsonField.of(accumulatedSpend)) + + /** + * Sets [Builder.accumulatedSpend] to an arbitrary JSON value. + * + * You should usually call [Builder.accumulatedSpend] with a well-typed + * [AccumulatedSpend] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun accumulatedSpend(accumulatedSpend: JsonField) = apply { + this.accumulatedSpend = accumulatedSpend + } + + 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 [SpendTracker]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTracker = + SpendTracker( + checkRequired("alias", alias), + checkRequired("applicableSpendSpecifiers", applicableSpendSpecifiers).map { + it.toImmutable() + }, + checkRequired("creditTypeId", creditTypeId), + checkRequired("resetFrequency", resetFrequency), + accumulatedSpend, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendTracker = apply { + if (validated) { + return@apply + } + + alias() + applicableSpendSpecifiers().forEach { it.validate() } + creditTypeId() + resetFrequency().validate() + accumulatedSpend().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (alias.asKnown().isPresent) 1 else 0) + + (applicableSpendSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (creditTypeId.asKnown().isPresent) 1 else 0) + + (resetFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (accumulatedSpend.asKnown().getOrNull()?.validity() ?: 0) + + class ApplicableSpendSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sources: JsonField>, + private val spendType: JsonField, + private val discounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("sources") + @ExcludeMissing + sources: JsonField> = JsonMissing.of(), + @JsonProperty("spend_type") + @ExcludeMissing + spendType: JsonField = JsonMissing.of(), + @JsonProperty("discounted") + @ExcludeMissing + discounted: JsonField = JsonMissing.of(), + ) : this(sources, spendType, discounted, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 sources(): List = sources.getRequired("sources") + + /** + * @throws MetronomeInvalidDataException 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 spendType(): SpendType = spendType.getRequired("spend_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun discounted(): Optional = discounted.getOptional("discounted") + + /** + * Returns the raw JSON value of [sources]. + * + * Unlike [sources], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sources") + @ExcludeMissing + fun _sources(): JsonField> = sources + + /** + * Returns the raw JSON value of [spendType]. + * + * Unlike [spendType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_type") + @ExcludeMissing + fun _spendType(): JsonField = spendType + + /** + * Returns the raw JSON value of [discounted]. + * + * Unlike [discounted], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("discounted") + @ExcludeMissing + fun _discounted(): JsonField = discounted + + @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 + * [ApplicableSpendSpecifier]. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApplicableSpendSpecifier]. */ + class Builder internal constructor() { + + private var sources: JsonField>? = null + private var spendType: JsonField? = null + private var discounted: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { + sources = applicableSpendSpecifier.sources.map { it.toMutableList() } + spendType = applicableSpendSpecifier.spendType + discounted = applicableSpendSpecifier.discounted + additionalProperties = + applicableSpendSpecifier.additionalProperties.toMutableMap() + } + + fun sources(sources: List) = sources(JsonField.of(sources)) + + /** + * Sets [Builder.sources] to an arbitrary JSON value. + * + * You should usually call [Builder.sources] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun sources(sources: JsonField>) = apply { + this.sources = sources.map { it.toMutableList() } + } + + /** + * Adds a single [Source] to [sources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: Source) = apply { + sources = + (sources ?: JsonField.of(mutableListOf())).also { + checkKnown("sources", it).add(source) + } + } + + fun spendType(spendType: SpendType) = spendType(JsonField.of(spendType)) + + /** + * Sets [Builder.spendType] to an arbitrary JSON value. + * + * You should usually call [Builder.spendType] with a well-typed [SpendType] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendType(spendType: JsonField) = apply { + this.spendType = spendType + } + + fun discounted(discounted: Discounted) = discounted(JsonField.of(discounted)) + + /** + * Sets [Builder.discounted] to an arbitrary JSON value. + * + * You should usually call [Builder.discounted] with a well-typed [Discounted] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun discounted(discounted: JsonField) = apply { + this.discounted = discounted + } + + 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 [ApplicableSpendSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApplicableSpendSpecifier = + ApplicableSpendSpecifier( + checkRequired("sources", sources).map { it.toImmutable() }, + checkRequired("spendType", spendType), + discounted, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ApplicableSpendSpecifier = apply { + if (validated) { + return@apply + } + + sources().forEach { it.validate() } + spendType().validate() + discounted().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (sources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendType.asKnown().getOrNull()?.validity() ?: 0) + + (discounted.asKnown().getOrNull()?.validity() ?: 0) + + class Source @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 THRESHOLD_RECHARGE = of("THRESHOLD_RECHARGE") + + @JvmField val MANUAL = of("MANUAL") + + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) + } + + /** An enum containing [Source]'s known values. */ + enum class Known { + THRESHOLD_RECHARGE, + MANUAL, + } + + /** + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Source] 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 { + THRESHOLD_RECHARGE, + MANUAL, + /** + * An enum member indicating that [Source] 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) { + THRESHOLD_RECHARGE -> Value.THRESHOLD_RECHARGE + MANUAL -> Value.MANUAL + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + THRESHOLD_RECHARGE -> Known.THRESHOLD_RECHARGE + MANUAL -> Known.MANUAL + else -> throw MetronomeInvalidDataException("Unknown Source: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Source && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SpendType @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 COMMIT_PURCHASE = of("COMMIT_PURCHASE") + + @JvmStatic fun of(value: String) = SpendType(JsonField.of(value)) + } + + /** An enum containing [SpendType]'s known values. */ + enum class Known { + COMMIT_PURCHASE + } + + /** + * An enum containing [SpendType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SpendType] 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 { + COMMIT_PURCHASE, + /** + * An enum member indicating that [SpendType] 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) { + COMMIT_PURCHASE -> Value.COMMIT_PURCHASE + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + COMMIT_PURCHASE -> Known.COMMIT_PURCHASE + else -> throw MetronomeInvalidDataException("Unknown SpendType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): SpendType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 SpendType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Discounted + @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 ANY = of("ANY") + + @JvmField val DISCOUNTED_ONLY = of("DISCOUNTED_ONLY") + + @JvmField val UNDISCOUNTED_ONLY = of("UNDISCOUNTED_ONLY") + + @JvmStatic fun of(value: String) = Discounted(JsonField.of(value)) + } + + /** An enum containing [Discounted]'s known values. */ + enum class Known { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + } + + /** + * An enum containing [Discounted]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Discounted] 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 { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + /** + * An enum member indicating that [Discounted] 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) { + ANY -> Value.ANY + DISCOUNTED_ONLY -> Value.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Value.UNDISCOUNTED_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANY -> Known.ANY + DISCOUNTED_ONLY -> Known.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Known.UNDISCOUNTED_ONLY + else -> throw MetronomeInvalidDataException("Unknown Discounted: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Discounted = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Discounted && 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 ApplicableSpendSpecifier && + sources == other.sources && + spendType == other.spendType && + discounted == other.discounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(sources, spendType, discounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ApplicableSpendSpecifier{sources=$sources, spendType=$spendType, discounted=$discounted, additionalProperties=$additionalProperties}" + } + + class ResetFrequency + @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 BILLING_PERIOD = of("BILLING_PERIOD") + + @JvmStatic fun of(value: String) = ResetFrequency(JsonField.of(value)) + } + + /** An enum containing [ResetFrequency]'s known values. */ + enum class Known { + BILLING_PERIOD + } + + /** + * An enum containing [ResetFrequency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ResetFrequency] 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 { + BILLING_PERIOD, + /** + * An enum member indicating that [ResetFrequency] 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) { + BILLING_PERIOD -> Value.BILLING_PERIOD + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + BILLING_PERIOD -> Known.BILLING_PERIOD + else -> throw MetronomeInvalidDataException("Unknown ResetFrequency: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ResetFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ResetFrequency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class AccumulatedSpend + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val periodEndingBefore: JsonField, + private val periodStartingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("period_ending_before") + @ExcludeMissing + periodEndingBefore: JsonField = JsonMissing.of(), + @JsonProperty("period_starting_at") + @ExcludeMissing + periodStartingAt: JsonField = JsonMissing.of(), + ) : this(amount, periodEndingBefore, periodStartingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * @throws MetronomeInvalidDataException 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 periodEndingBefore(): OffsetDateTime = + periodEndingBefore.getRequired("period_ending_before") + + /** + * @throws MetronomeInvalidDataException 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 periodStartingAt(): OffsetDateTime = + periodStartingAt.getRequired("period_starting_at") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [periodEndingBefore]. + * + * Unlike [periodEndingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("period_ending_before") + @ExcludeMissing + fun _periodEndingBefore(): JsonField = periodEndingBefore + + /** + * Returns the raw JSON value of [periodStartingAt]. + * + * Unlike [periodStartingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("period_starting_at") + @ExcludeMissing + fun _periodStartingAt(): JsonField = periodStartingAt + + @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 [AccumulatedSpend]. + * + * The following fields are required: + * ```java + * .amount() + * .periodEndingBefore() + * .periodStartingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccumulatedSpend]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var periodEndingBefore: JsonField? = null + private var periodStartingAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(accumulatedSpend: AccumulatedSpend) = apply { + amount = accumulatedSpend.amount + periodEndingBefore = accumulatedSpend.periodEndingBefore + periodStartingAt = accumulatedSpend.periodStartingAt + additionalProperties = accumulatedSpend.additionalProperties.toMutableMap() + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun periodEndingBefore(periodEndingBefore: OffsetDateTime) = + periodEndingBefore(JsonField.of(periodEndingBefore)) + + /** + * Sets [Builder.periodEndingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.periodEndingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun periodEndingBefore(periodEndingBefore: JsonField) = apply { + this.periodEndingBefore = periodEndingBefore + } + + fun periodStartingAt(periodStartingAt: OffsetDateTime) = + periodStartingAt(JsonField.of(periodStartingAt)) + + /** + * Sets [Builder.periodStartingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.periodStartingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun periodStartingAt(periodStartingAt: JsonField) = apply { + this.periodStartingAt = periodStartingAt + } + + 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 [AccumulatedSpend]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .periodEndingBefore() + * .periodStartingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AccumulatedSpend = + AccumulatedSpend( + checkRequired("amount", amount), + checkRequired("periodEndingBefore", periodEndingBefore), + checkRequired("periodStartingAt", periodStartingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): AccumulatedSpend = apply { + if (validated) { + return@apply + } + + amount() + periodEndingBefore() + periodStartingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (periodEndingBefore.asKnown().isPresent) 1 else 0) + + (if (periodStartingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccumulatedSpend && + amount == other.amount && + periodEndingBefore == other.periodEndingBefore && + periodStartingAt == other.periodStartingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, periodEndingBefore, periodStartingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccumulatedSpend{amount=$amount, periodEndingBefore=$periodEndingBefore, periodStartingAt=$periodStartingAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendTracker && + alias == other.alias && + applicableSpendSpecifiers == other.applicableSpendSpecifiers && + creditTypeId == other.creditTypeId && + resetFrequency == other.resetFrequency && + accumulatedSpend == other.accumulatedSpend && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + accumulatedSpend, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTracker{alias=$alias, applicableSpendSpecifiers=$applicableSpendSpecifiers, creditTypeId=$creditTypeId, resetFrequency=$resetFrequency, accumulatedSpend=$accumulatedSpend, additionalProperties=$additionalProperties}" + } + class Subscription @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -35690,6 +37460,7 @@ private constructor( salesforceOpportunityId == other.salesforceOpportunityId && scheduledChargesOnUsageInvoices == other.scheduledChargesOnUsageInvoices && spendThresholdConfiguration == other.spendThresholdConfiguration && + spendTrackers == other.spendTrackers && subscriptions == other.subscriptions && totalContractValue == other.totalContractValue && uniquenessKey == other.uniquenessKey && @@ -35731,6 +37502,7 @@ private constructor( salesforceOpportunityId, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, totalContractValue, uniquenessKey, @@ -35741,5 +37513,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "ContractV2{id=$id, commits=$commits, createdAt=$createdAt, createdBy=$createdBy, customerId=$customerId, overrides=$overrides, scheduledCharges=$scheduledCharges, startingAt=$startingAt, transitions=$transitions, usageFilter=$usageFilter, usageStatementSchedule=$usageStatementSchedule, archivedAt=$archivedAt, credits=$credits, customFields=$customFields, customerBillingProviderConfiguration=$customerBillingProviderConfiguration, discounts=$discounts, endingBefore=$endingBefore, hasMore=$hasMore, hierarchyConfiguration=$hierarchyConfiguration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, netsuiteSalesOrderId=$netsuiteSalesOrderId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, priority=$priority, professionalServices=$professionalServices, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, resellerRoyalties=$resellerRoyalties, salesforceOpportunityId=$salesforceOpportunityId, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, subscriptions=$subscriptions, totalContractValue=$totalContractValue, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" + "ContractV2{id=$id, commits=$commits, createdAt=$createdAt, createdBy=$createdBy, customerId=$customerId, overrides=$overrides, scheduledCharges=$scheduledCharges, startingAt=$startingAt, transitions=$transitions, usageFilter=$usageFilter, usageStatementSchedule=$usageStatementSchedule, archivedAt=$archivedAt, credits=$credits, customFields=$customFields, customerBillingProviderConfiguration=$customerBillingProviderConfiguration, discounts=$discounts, endingBefore=$endingBefore, hasMore=$hasMore, hierarchyConfiguration=$hierarchyConfiguration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, netsuiteSalesOrderId=$netsuiteSalesOrderId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, priority=$priority, professionalServices=$professionalServices, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, resellerRoyalties=$resellerRoyalties, salesforceOpportunityId=$salesforceOpportunityId, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, spendTrackers=$spendTrackers, subscriptions=$subscriptions, totalContractValue=$totalContractValue, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" } diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/ContractWithoutAmendments.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/ContractWithoutAmendments.kt index ca84fc38..0459d9bb 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/ContractWithoutAmendments.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/ContractWithoutAmendments.kt @@ -49,6 +49,7 @@ private constructor( private val salesforceOpportunityId: JsonField, private val scheduledChargesOnUsageInvoices: JsonField, private val spendThresholdConfiguration: JsonField, + private val spendTrackers: JsonField>, private val totalContractValue: JsonField, private val usageFilter: JsonField, private val additionalProperties: MutableMap, @@ -126,6 +127,9 @@ private constructor( @JsonProperty("spend_threshold_configuration") @ExcludeMissing spendThresholdConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("spend_trackers") + @ExcludeMissing + spendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("total_contract_value") @ExcludeMissing totalContractValue: JsonField = JsonMissing.of(), @@ -157,6 +161,7 @@ private constructor( salesforceOpportunityId, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, totalContractValue, usageFilter, mutableMapOf(), @@ -337,6 +342,14 @@ private constructor( fun spendThresholdConfiguration(): Optional = spendThresholdConfiguration.getOptional("spend_threshold_configuration") + /** + * Spend trackers attached to this contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = spendTrackers.getOptional("spend_trackers") + /** * This field's availability is dependent on your client's configuration. * @@ -574,6 +587,15 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = spendThresholdConfiguration + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("spend_trackers") + @ExcludeMissing + fun _spendTrackers(): JsonField> = spendTrackers + /** * Returns the raw JSON value of [totalContractValue]. * @@ -656,6 +678,7 @@ private constructor( JsonMissing.of() private var spendThresholdConfiguration: JsonField = JsonMissing.of() + private var spendTrackers: JsonField>? = null private var totalContractValue: JsonField = JsonMissing.of() private var usageFilter: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -690,6 +713,7 @@ private constructor( scheduledChargesOnUsageInvoices = contractWithoutAmendments.scheduledChargesOnUsageInvoices spendThresholdConfiguration = contractWithoutAmendments.spendThresholdConfiguration + spendTrackers = contractWithoutAmendments.spendTrackers.map { it.toMutableList() } totalContractValue = contractWithoutAmendments.totalContractValue usageFilter = contractWithoutAmendments.usageFilter additionalProperties = contractWithoutAmendments.additionalProperties.toMutableMap() @@ -1165,6 +1189,33 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { this.spendThresholdConfiguration = spendThresholdConfiguration } + /** Spend trackers attached to this contract. */ + fun spendTrackers(spendTrackers: List) = + spendTrackers(JsonField.of(spendTrackers)) + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + this.spendTrackers = spendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + spendTrackers = + (spendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("spendTrackers", it).add(spendTracker) + } + } + /** This field's availability is dependent on your client's configuration. */ fun totalContractValue(totalContractValue: Double) = totalContractValue(JsonField.of(totalContractValue)) @@ -1257,6 +1308,7 @@ private constructor( salesforceOpportunityId, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + (spendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, totalContractValue, usageFilter, additionalProperties.toMutableMap(), @@ -1302,6 +1354,7 @@ private constructor( salesforceOpportunityId() scheduledChargesOnUsageInvoices().ifPresent { it.validate() } spendThresholdConfiguration().ifPresent { it.validate() } + spendTrackers().ifPresent { it.forEach { it.validate() } } totalContractValue() usageFilter().ifPresent { it.validate() } validated = true @@ -1346,6 +1399,7 @@ private constructor( (if (salesforceOpportunityId.asKnown().isPresent) 1 else 0) + (scheduledChargesOnUsageInvoices.asKnown().getOrNull()?.validity() ?: 0) + (spendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (spendTrackers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (totalContractValue.asKnown().isPresent) 1 else 0) + (usageFilter.asKnown().getOrNull()?.validity() ?: 0) @@ -8400,6 +8454,1483 @@ private constructor( override fun toString() = value.toString() } + class SpendTracker + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val alias: JsonField, + private val applicableSpendSpecifiers: JsonField>, + private val creditTypeId: JsonField, + private val resetFrequency: JsonField, + private val accumulatedSpend: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("alias") @ExcludeMissing alias: JsonField = JsonMissing.of(), + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + applicableSpendSpecifiers: JsonField> = JsonMissing.of(), + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("reset_frequency") + @ExcludeMissing + resetFrequency: JsonField = JsonMissing.of(), + @JsonProperty("accumulated_spend") + @ExcludeMissing + accumulatedSpend: JsonField = JsonMissing.of(), + ) : this( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + accumulatedSpend, + mutableMapOf(), + ) + + /** + * Human-readable identifier, unique per contract. + * + * @throws MetronomeInvalidDataException 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 alias(): String = alias.getRequired("alias") + + /** + * @throws MetronomeInvalidDataException 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 applicableSpendSpecifiers(): List = + applicableSpendSpecifiers.getRequired("applicable_spend_specifiers") + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 resetFrequency(): ResetFrequency = resetFrequency.getRequired("reset_frequency") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun accumulatedSpend(): Optional = + accumulatedSpend.getOptional("accumulated_spend") + + /** + * Returns the raw JSON value of [alias]. + * + * Unlike [alias], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("alias") @ExcludeMissing fun _alias(): JsonField = alias + + /** + * Returns the raw JSON value of [applicableSpendSpecifiers]. + * + * Unlike [applicableSpendSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + fun _applicableSpendSpecifiers(): JsonField> = + applicableSpendSpecifiers + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [resetFrequency]. + * + * Unlike [resetFrequency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("reset_frequency") + @ExcludeMissing + fun _resetFrequency(): JsonField = resetFrequency + + /** + * Returns the raw JSON value of [accumulatedSpend]. + * + * Unlike [accumulatedSpend], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("accumulated_spend") + @ExcludeMissing + fun _accumulatedSpend(): JsonField = accumulatedSpend + + @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 [SpendTracker]. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTracker]. */ + class Builder internal constructor() { + + private var alias: JsonField? = null + private var applicableSpendSpecifiers: + JsonField>? = + null + private var creditTypeId: JsonField? = null + private var resetFrequency: JsonField? = null + private var accumulatedSpend: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTracker: SpendTracker) = apply { + alias = spendTracker.alias + applicableSpendSpecifiers = + spendTracker.applicableSpendSpecifiers.map { it.toMutableList() } + creditTypeId = spendTracker.creditTypeId + resetFrequency = spendTracker.resetFrequency + accumulatedSpend = spendTracker.accumulatedSpend + additionalProperties = spendTracker.additionalProperties.toMutableMap() + } + + /** Human-readable identifier, unique per contract. */ + fun alias(alias: String) = alias(JsonField.of(alias)) + + /** + * Sets [Builder.alias] to an arbitrary JSON value. + * + * You should usually call [Builder.alias] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun alias(alias: JsonField) = apply { this.alias = alias } + + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: List + ) = applicableSpendSpecifiers(JsonField.of(applicableSpendSpecifiers)) + + /** + * Sets [Builder.applicableSpendSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableSpendSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: JsonField> + ) = apply { + this.applicableSpendSpecifiers = + applicableSpendSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ApplicableSpendSpecifier] to [applicableSpendSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableSpendSpecifier(applicableSpendSpecifier: ApplicableSpendSpecifier) = + apply { + applicableSpendSpecifiers = + (applicableSpendSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableSpendSpecifiers", it) + .add(applicableSpendSpecifier) + } + } + + fun creditTypeId(creditTypeId: String) = creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun resetFrequency(resetFrequency: ResetFrequency) = + resetFrequency(JsonField.of(resetFrequency)) + + /** + * Sets [Builder.resetFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.resetFrequency] with a well-typed [ResetFrequency] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun resetFrequency(resetFrequency: JsonField) = apply { + this.resetFrequency = resetFrequency + } + + fun accumulatedSpend(accumulatedSpend: AccumulatedSpend) = + accumulatedSpend(JsonField.of(accumulatedSpend)) + + /** + * Sets [Builder.accumulatedSpend] to an arbitrary JSON value. + * + * You should usually call [Builder.accumulatedSpend] with a well-typed + * [AccumulatedSpend] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun accumulatedSpend(accumulatedSpend: JsonField) = apply { + this.accumulatedSpend = accumulatedSpend + } + + 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 [SpendTracker]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTracker = + SpendTracker( + checkRequired("alias", alias), + checkRequired("applicableSpendSpecifiers", applicableSpendSpecifiers).map { + it.toImmutable() + }, + checkRequired("creditTypeId", creditTypeId), + checkRequired("resetFrequency", resetFrequency), + accumulatedSpend, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendTracker = apply { + if (validated) { + return@apply + } + + alias() + applicableSpendSpecifiers().forEach { it.validate() } + creditTypeId() + resetFrequency().validate() + accumulatedSpend().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (alias.asKnown().isPresent) 1 else 0) + + (applicableSpendSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (creditTypeId.asKnown().isPresent) 1 else 0) + + (resetFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (accumulatedSpend.asKnown().getOrNull()?.validity() ?: 0) + + class ApplicableSpendSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sources: JsonField>, + private val spendType: JsonField, + private val discounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("sources") + @ExcludeMissing + sources: JsonField> = JsonMissing.of(), + @JsonProperty("spend_type") + @ExcludeMissing + spendType: JsonField = JsonMissing.of(), + @JsonProperty("discounted") + @ExcludeMissing + discounted: JsonField = JsonMissing.of(), + ) : this(sources, spendType, discounted, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 sources(): List = sources.getRequired("sources") + + /** + * @throws MetronomeInvalidDataException 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 spendType(): SpendType = spendType.getRequired("spend_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun discounted(): Optional = discounted.getOptional("discounted") + + /** + * Returns the raw JSON value of [sources]. + * + * Unlike [sources], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sources") + @ExcludeMissing + fun _sources(): JsonField> = sources + + /** + * Returns the raw JSON value of [spendType]. + * + * Unlike [spendType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_type") + @ExcludeMissing + fun _spendType(): JsonField = spendType + + /** + * Returns the raw JSON value of [discounted]. + * + * Unlike [discounted], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("discounted") + @ExcludeMissing + fun _discounted(): JsonField = discounted + + @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 + * [ApplicableSpendSpecifier]. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApplicableSpendSpecifier]. */ + class Builder internal constructor() { + + private var sources: JsonField>? = null + private var spendType: JsonField? = null + private var discounted: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { + sources = applicableSpendSpecifier.sources.map { it.toMutableList() } + spendType = applicableSpendSpecifier.spendType + discounted = applicableSpendSpecifier.discounted + additionalProperties = + applicableSpendSpecifier.additionalProperties.toMutableMap() + } + + fun sources(sources: List) = sources(JsonField.of(sources)) + + /** + * Sets [Builder.sources] to an arbitrary JSON value. + * + * You should usually call [Builder.sources] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun sources(sources: JsonField>) = apply { + this.sources = sources.map { it.toMutableList() } + } + + /** + * Adds a single [Source] to [sources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: Source) = apply { + sources = + (sources ?: JsonField.of(mutableListOf())).also { + checkKnown("sources", it).add(source) + } + } + + fun spendType(spendType: SpendType) = spendType(JsonField.of(spendType)) + + /** + * Sets [Builder.spendType] to an arbitrary JSON value. + * + * You should usually call [Builder.spendType] with a well-typed [SpendType] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendType(spendType: JsonField) = apply { + this.spendType = spendType + } + + fun discounted(discounted: Discounted) = discounted(JsonField.of(discounted)) + + /** + * Sets [Builder.discounted] to an arbitrary JSON value. + * + * You should usually call [Builder.discounted] with a well-typed [Discounted] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun discounted(discounted: JsonField) = apply { + this.discounted = discounted + } + + 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 [ApplicableSpendSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApplicableSpendSpecifier = + ApplicableSpendSpecifier( + checkRequired("sources", sources).map { it.toImmutable() }, + checkRequired("spendType", spendType), + discounted, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ApplicableSpendSpecifier = apply { + if (validated) { + return@apply + } + + sources().forEach { it.validate() } + spendType().validate() + discounted().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (sources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendType.asKnown().getOrNull()?.validity() ?: 0) + + (discounted.asKnown().getOrNull()?.validity() ?: 0) + + class Source @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 THRESHOLD_RECHARGE = of("THRESHOLD_RECHARGE") + + @JvmField val MANUAL = of("MANUAL") + + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) + } + + /** An enum containing [Source]'s known values. */ + enum class Known { + THRESHOLD_RECHARGE, + MANUAL, + } + + /** + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Source] 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 { + THRESHOLD_RECHARGE, + MANUAL, + /** + * An enum member indicating that [Source] 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) { + THRESHOLD_RECHARGE -> Value.THRESHOLD_RECHARGE + MANUAL -> Value.MANUAL + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + THRESHOLD_RECHARGE -> Known.THRESHOLD_RECHARGE + MANUAL -> Known.MANUAL + else -> throw MetronomeInvalidDataException("Unknown Source: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Source && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SpendType @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 COMMIT_PURCHASE = of("COMMIT_PURCHASE") + + @JvmStatic fun of(value: String) = SpendType(JsonField.of(value)) + } + + /** An enum containing [SpendType]'s known values. */ + enum class Known { + COMMIT_PURCHASE + } + + /** + * An enum containing [SpendType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SpendType] 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 { + COMMIT_PURCHASE, + /** + * An enum member indicating that [SpendType] 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) { + COMMIT_PURCHASE -> Value.COMMIT_PURCHASE + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + COMMIT_PURCHASE -> Known.COMMIT_PURCHASE + else -> throw MetronomeInvalidDataException("Unknown SpendType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): SpendType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 SpendType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Discounted + @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 ANY = of("ANY") + + @JvmField val DISCOUNTED_ONLY = of("DISCOUNTED_ONLY") + + @JvmField val UNDISCOUNTED_ONLY = of("UNDISCOUNTED_ONLY") + + @JvmStatic fun of(value: String) = Discounted(JsonField.of(value)) + } + + /** An enum containing [Discounted]'s known values. */ + enum class Known { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + } + + /** + * An enum containing [Discounted]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Discounted] 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 { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + /** + * An enum member indicating that [Discounted] 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) { + ANY -> Value.ANY + DISCOUNTED_ONLY -> Value.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Value.UNDISCOUNTED_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANY -> Known.ANY + DISCOUNTED_ONLY -> Known.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Known.UNDISCOUNTED_ONLY + else -> throw MetronomeInvalidDataException("Unknown Discounted: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Discounted = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Discounted && 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 ApplicableSpendSpecifier && + sources == other.sources && + spendType == other.spendType && + discounted == other.discounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(sources, spendType, discounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ApplicableSpendSpecifier{sources=$sources, spendType=$spendType, discounted=$discounted, additionalProperties=$additionalProperties}" + } + + class ResetFrequency + @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 BILLING_PERIOD = of("BILLING_PERIOD") + + @JvmStatic fun of(value: String) = ResetFrequency(JsonField.of(value)) + } + + /** An enum containing [ResetFrequency]'s known values. */ + enum class Known { + BILLING_PERIOD + } + + /** + * An enum containing [ResetFrequency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ResetFrequency] 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 { + BILLING_PERIOD, + /** + * An enum member indicating that [ResetFrequency] 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) { + BILLING_PERIOD -> Value.BILLING_PERIOD + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + BILLING_PERIOD -> Known.BILLING_PERIOD + else -> throw MetronomeInvalidDataException("Unknown ResetFrequency: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ResetFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ResetFrequency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class AccumulatedSpend + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val periodEndingBefore: JsonField, + private val periodStartingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("period_ending_before") + @ExcludeMissing + periodEndingBefore: JsonField = JsonMissing.of(), + @JsonProperty("period_starting_at") + @ExcludeMissing + periodStartingAt: JsonField = JsonMissing.of(), + ) : this(amount, periodEndingBefore, periodStartingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * @throws MetronomeInvalidDataException 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 periodEndingBefore(): OffsetDateTime = + periodEndingBefore.getRequired("period_ending_before") + + /** + * @throws MetronomeInvalidDataException 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 periodStartingAt(): OffsetDateTime = + periodStartingAt.getRequired("period_starting_at") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [periodEndingBefore]. + * + * Unlike [periodEndingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("period_ending_before") + @ExcludeMissing + fun _periodEndingBefore(): JsonField = periodEndingBefore + + /** + * Returns the raw JSON value of [periodStartingAt]. + * + * Unlike [periodStartingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("period_starting_at") + @ExcludeMissing + fun _periodStartingAt(): JsonField = periodStartingAt + + @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 [AccumulatedSpend]. + * + * The following fields are required: + * ```java + * .amount() + * .periodEndingBefore() + * .periodStartingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccumulatedSpend]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var periodEndingBefore: JsonField? = null + private var periodStartingAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(accumulatedSpend: AccumulatedSpend) = apply { + amount = accumulatedSpend.amount + periodEndingBefore = accumulatedSpend.periodEndingBefore + periodStartingAt = accumulatedSpend.periodStartingAt + additionalProperties = accumulatedSpend.additionalProperties.toMutableMap() + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun periodEndingBefore(periodEndingBefore: OffsetDateTime) = + periodEndingBefore(JsonField.of(periodEndingBefore)) + + /** + * Sets [Builder.periodEndingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.periodEndingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun periodEndingBefore(periodEndingBefore: JsonField) = apply { + this.periodEndingBefore = periodEndingBefore + } + + fun periodStartingAt(periodStartingAt: OffsetDateTime) = + periodStartingAt(JsonField.of(periodStartingAt)) + + /** + * Sets [Builder.periodStartingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.periodStartingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun periodStartingAt(periodStartingAt: JsonField) = apply { + this.periodStartingAt = periodStartingAt + } + + 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 [AccumulatedSpend]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .periodEndingBefore() + * .periodStartingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AccumulatedSpend = + AccumulatedSpend( + checkRequired("amount", amount), + checkRequired("periodEndingBefore", periodEndingBefore), + checkRequired("periodStartingAt", periodStartingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): AccumulatedSpend = apply { + if (validated) { + return@apply + } + + amount() + periodEndingBefore() + periodStartingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (periodEndingBefore.asKnown().isPresent) 1 else 0) + + (if (periodStartingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccumulatedSpend && + amount == other.amount && + periodEndingBefore == other.periodEndingBefore && + periodStartingAt == other.periodStartingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, periodEndingBefore, periodStartingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccumulatedSpend{amount=$amount, periodEndingBefore=$periodEndingBefore, periodStartingAt=$periodStartingAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendTracker && + alias == other.alias && + applicableSpendSpecifiers == other.applicableSpendSpecifiers && + creditTypeId == other.creditTypeId && + resetFrequency == other.resetFrequency && + accumulatedSpend == other.accumulatedSpend && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + accumulatedSpend, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTracker{alias=$alias, applicableSpendSpecifiers=$applicableSpendSpecifiers, creditTypeId=$creditTypeId, resetFrequency=$resetFrequency, accumulatedSpend=$accumulatedSpend, additionalProperties=$additionalProperties}" + } + class UsageFilter @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -8967,6 +10498,7 @@ private constructor( salesforceOpportunityId == other.salesforceOpportunityId && scheduledChargesOnUsageInvoices == other.scheduledChargesOnUsageInvoices && spendThresholdConfiguration == other.spendThresholdConfiguration && + spendTrackers == other.spendTrackers && totalContractValue == other.totalContractValue && usageFilter == other.usageFilter && additionalProperties == other.additionalProperties @@ -8998,6 +10530,7 @@ private constructor( salesforceOpportunityId, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, totalContractValue, usageFilter, additionalProperties, @@ -9007,5 +10540,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "ContractWithoutAmendments{commits=$commits, createdAt=$createdAt, createdBy=$createdBy, overrides=$overrides, scheduledCharges=$scheduledCharges, startingAt=$startingAt, transitions=$transitions, usageStatementSchedule=$usageStatementSchedule, credits=$credits, discounts=$discounts, endingBefore=$endingBefore, hierarchyConfiguration=$hierarchyConfiguration, name=$name, netPaymentTermsDays=$netPaymentTermsDays, netsuiteSalesOrderId=$netsuiteSalesOrderId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, professionalServices=$professionalServices, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, resellerRoyalties=$resellerRoyalties, salesforceOpportunityId=$salesforceOpportunityId, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, totalContractValue=$totalContractValue, usageFilter=$usageFilter, additionalProperties=$additionalProperties}" + "ContractWithoutAmendments{commits=$commits, createdAt=$createdAt, createdBy=$createdBy, overrides=$overrides, scheduledCharges=$scheduledCharges, startingAt=$startingAt, transitions=$transitions, usageStatementSchedule=$usageStatementSchedule, credits=$credits, discounts=$discounts, endingBefore=$endingBefore, hierarchyConfiguration=$hierarchyConfiguration, name=$name, netPaymentTermsDays=$netPaymentTermsDays, netsuiteSalesOrderId=$netsuiteSalesOrderId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, professionalServices=$professionalServices, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, resellerRoyalties=$resellerRoyalties, salesforceOpportunityId=$salesforceOpportunityId, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, spendTrackers=$spendTrackers, totalContractValue=$totalContractValue, usageFilter=$usageFilter, additionalProperties=$additionalProperties}" } diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfiguration.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfiguration.kt index 8e247df5..63180241 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfiguration.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfiguration.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.metronome.api.core.Enum import com.metronome.api.core.ExcludeMissing import com.metronome.api.core.JsonField import com.metronome.api.core.JsonMissing @@ -29,6 +30,7 @@ private constructor( private val thresholdAmount: JsonField, private val customCreditTypeId: JsonField, private val discountConfiguration: JsonField, + private val thresholdBalanceSpecifiers: JsonField>, private val additionalProperties: MutableMap, ) { @@ -53,6 +55,9 @@ private constructor( @JsonProperty("discount_configuration") @ExcludeMissing discountConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + thresholdBalanceSpecifiers: JsonField> = JsonMissing.of(), ) : this( commit, isEnabled, @@ -61,6 +66,7 @@ private constructor( thresholdAmount, customCreditTypeId, discountConfiguration, + thresholdBalanceSpecifiers, mutableMapOf(), ) @@ -120,6 +126,13 @@ private constructor( fun discountConfiguration(): Optional = discountConfiguration.getOptional("discount_configuration") + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun thresholdBalanceSpecifiers(): Optional> = + thresholdBalanceSpecifiers.getOptional("threshold_balance_specifiers") + /** * Returns the raw JSON value of [commit]. * @@ -183,6 +196,17 @@ private constructor( @ExcludeMissing fun _discountConfiguration(): JsonField = discountConfiguration + /** + * Returns the raw JSON value of [thresholdBalanceSpecifiers]. + * + * Unlike [thresholdBalanceSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + fun _thresholdBalanceSpecifiers(): JsonField> = + thresholdBalanceSpecifiers + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -223,6 +247,8 @@ private constructor( private var thresholdAmount: JsonField? = null private var customCreditTypeId: JsonField = JsonMissing.of() private var discountConfiguration: JsonField = JsonMissing.of() + private var thresholdBalanceSpecifiers: JsonField>? = + null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -236,6 +262,10 @@ private constructor( thresholdAmount = prepaidBalanceThresholdConfiguration.thresholdAmount customCreditTypeId = prepaidBalanceThresholdConfiguration.customCreditTypeId discountConfiguration = prepaidBalanceThresholdConfiguration.discountConfiguration + thresholdBalanceSpecifiers = + prepaidBalanceThresholdConfiguration.thresholdBalanceSpecifiers.map { + it.toMutableList() + } additionalProperties = prepaidBalanceThresholdConfiguration.additionalProperties.toMutableMap() } @@ -344,6 +374,36 @@ private constructor( this.discountConfiguration = discountConfiguration } + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: List + ) = thresholdBalanceSpecifiers(JsonField.of(thresholdBalanceSpecifiers)) + + /** + * Sets [Builder.thresholdBalanceSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdBalanceSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: JsonField> + ) = apply { + this.thresholdBalanceSpecifiers = thresholdBalanceSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ThresholdBalanceSpecifier] to [thresholdBalanceSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addThresholdBalanceSpecifier(thresholdBalanceSpecifier: ThresholdBalanceSpecifier) = + apply { + thresholdBalanceSpecifiers = + (thresholdBalanceSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("thresholdBalanceSpecifiers", it).add(thresholdBalanceSpecifier) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -388,6 +448,7 @@ private constructor( checkRequired("thresholdAmount", thresholdAmount), customCreditTypeId, discountConfiguration, + (thresholdBalanceSpecifiers ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -414,6 +475,7 @@ private constructor( thresholdAmount() customCreditTypeId() discountConfiguration().ifPresent { it.validate() } + thresholdBalanceSpecifiers().ifPresent { it.forEach { it.validate() } } validated = true } @@ -438,7 +500,8 @@ private constructor( (if (rechargeToAmount.asKnown().isPresent) 1 else 0) + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + (if (customCreditTypeId.asKnown().isPresent) 1 else 0) + - (discountConfiguration.asKnown().getOrNull()?.validity() ?: 0) + (discountConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (thresholdBalanceSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) class Commit @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -951,6 +1014,7 @@ private constructor( @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val paymentFraction: JsonField, + private val cap: JsonField, private val additionalProperties: MutableMap, ) { @@ -958,8 +1022,9 @@ private constructor( private constructor( @JsonProperty("payment_fraction") @ExcludeMissing - paymentFraction: JsonField = JsonMissing.of() - ) : this(paymentFraction, mutableMapOf()) + paymentFraction: JsonField = JsonMissing.of(), + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), + ) : this(paymentFraction, cap, mutableMapOf()) /** * The fraction of the original amount that the customer pays after applying the discount. @@ -970,6 +1035,15 @@ private constructor( */ fun paymentFraction(): Double = paymentFraction.getRequired("payment_fraction") + /** + * If provided, the discount stops applying once the spend tracker has accumulated this much + * spend in the billing period. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") + /** * Returns the raw JSON value of [paymentFraction]. * @@ -980,6 +1054,13 @@ private constructor( @ExcludeMissing fun _paymentFraction(): JsonField = paymentFraction + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -1009,11 +1090,13 @@ private constructor( class Builder internal constructor() { private var paymentFraction: JsonField? = null + private var cap: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(discountConfiguration: DiscountConfiguration) = apply { paymentFraction = discountConfiguration.paymentFraction + cap = discountConfiguration.cap additionalProperties = discountConfiguration.additionalProperties.toMutableMap() } @@ -1036,6 +1119,21 @@ private constructor( this.paymentFraction = paymentFraction } + /** + * If provided, the discount stops applying once the spend tracker has accumulated this + * much spend in the billing period. + */ + fun cap(cap: Cap) = cap(JsonField.of(cap)) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1070,6 +1168,7 @@ private constructor( fun build(): DiscountConfiguration = DiscountConfiguration( checkRequired("paymentFraction", paymentFraction), + cap, additionalProperties.toMutableMap(), ) } @@ -1091,6 +1190,7 @@ private constructor( } paymentFraction() + cap().ifPresent { it.validate() } validated = true } @@ -1109,7 +1209,238 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = (if (paymentFraction.asKnown().isPresent) 1 else 0) + internal fun validity(): Int = + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + (cap.asKnown().getOrNull()?.validity() ?: 0) + + /** + * If provided, the discount stops applying once the spend tracker has accumulated this much + * spend in the billing period. + */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** Accumulated spend ceiling above which the discount stops applying. */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -1118,15 +1449,808 @@ private constructor( return other is DiscountConfiguration && paymentFraction == other.paymentFraction && + cap == other.cap && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(paymentFraction, cap, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DiscountConfiguration{paymentFraction=$paymentFraction, cap=$cap, additionalProperties=$additionalProperties}" + } + + class ThresholdBalanceSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val exclude: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("exclude") + @ExcludeMissing + exclude: JsonField> = JsonMissing.of() + ) : this(exclude, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 exclude(): List = exclude.getRequired("exclude") + + /** + * Returns the raw JSON value of [exclude]. + * + * Unlike [exclude], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("exclude") @ExcludeMissing fun _exclude(): JsonField> = exclude + + @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 + * [ThresholdBalanceSpecifier]. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThresholdBalanceSpecifier]. */ + class Builder internal constructor() { + + private var exclude: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(thresholdBalanceSpecifier: ThresholdBalanceSpecifier) = apply { + exclude = thresholdBalanceSpecifier.exclude.map { it.toMutableList() } + additionalProperties = thresholdBalanceSpecifier.additionalProperties.toMutableMap() + } + + fun exclude(exclude: List) = exclude(JsonField.of(exclude)) + + /** + * Sets [Builder.exclude] to an arbitrary JSON value. + * + * You should usually call [Builder.exclude] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun exclude(exclude: JsonField>) = apply { + this.exclude = exclude.map { it.toMutableList() } + } + + /** + * Adds a single [Exclude] to [Builder.exclude]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExclude(exclude: Exclude) = apply { + this.exclude = + (this.exclude ?: JsonField.of(mutableListOf())).also { + checkKnown("exclude", it).add(exclude) + } + } + + 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 [ThresholdBalanceSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThresholdBalanceSpecifier = + ThresholdBalanceSpecifier( + checkRequired("exclude", exclude).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ThresholdBalanceSpecifier = apply { + if (validated) { + return@apply + } + + exclude().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (exclude.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Exclude + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val customFieldFilters: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("custom_field_filters") + @ExcludeMissing + customFieldFilters: JsonField> = JsonMissing.of() + ) : this(customFieldFilters, mutableMapOf()) + + /** + * If provided, balances with all the custom fields will not be considered when + * evaluating threshold billing + * + * @throws MetronomeInvalidDataException 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 customFieldFilters(): List = + customFieldFilters.getRequired("custom_field_filters") + + /** + * Returns the raw JSON value of [customFieldFilters]. + * + * Unlike [customFieldFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("custom_field_filters") + @ExcludeMissing + fun _customFieldFilters(): JsonField> = customFieldFilters + + @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 [Exclude]. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Exclude]. */ + class Builder internal constructor() { + + private var customFieldFilters: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(exclude: Exclude) = apply { + customFieldFilters = exclude.customFieldFilters.map { it.toMutableList() } + additionalProperties = exclude.additionalProperties.toMutableMap() + } + + /** + * If provided, balances with all the custom fields will not be considered when + * evaluating threshold billing + */ + fun customFieldFilters(customFieldFilters: List) = + customFieldFilters(JsonField.of(customFieldFilters)) + + /** + * Sets [Builder.customFieldFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.customFieldFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun customFieldFilters(customFieldFilters: JsonField>) = + apply { + this.customFieldFilters = customFieldFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CustomFieldFilter] to [customFieldFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCustomFieldFilter(customFieldFilter: CustomFieldFilter) = apply { + customFieldFilters = + (customFieldFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("customFieldFilters", it).add(customFieldFilter) + } + } + + 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 [Exclude]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Exclude = + Exclude( + checkRequired("customFieldFilters", customFieldFilters).map { + it.toImmutable() + }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Exclude = apply { + if (validated) { + return@apply + } + + customFieldFilters().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (customFieldFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class CustomFieldFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val entity: JsonField, + private val key: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("entity") + @ExcludeMissing + entity: JsonField = JsonMissing.of(), + @JsonProperty("key") @ExcludeMissing key: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(entity, key, value, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 entity(): Entity = entity.getRequired("entity") + + /** + * @throws MetronomeInvalidDataException 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 key(): String = key.getRequired("key") + + /** + * @throws MetronomeInvalidDataException 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 [entity]. + * + * Unlike [entity], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("entity") @ExcludeMissing fun _entity(): JsonField = entity + + /** + * Returns the raw JSON value of [key]. + * + * Unlike [key], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("key") @ExcludeMissing fun _key(): JsonField = key + + /** + * 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 + * [CustomFieldFilter]. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFieldFilter]. */ + class Builder internal constructor() { + + private var entity: JsonField? = null + private var key: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(customFieldFilter: CustomFieldFilter) = apply { + entity = customFieldFilter.entity + key = customFieldFilter.key + value = customFieldFilter.value + additionalProperties = customFieldFilter.additionalProperties.toMutableMap() + } + + fun entity(entity: Entity) = entity(JsonField.of(entity)) + + /** + * Sets [Builder.entity] to an arbitrary JSON value. + * + * You should usually call [Builder.entity] with a well-typed [Entity] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun entity(entity: JsonField) = apply { this.entity = entity } + + fun key(key: String) = key(JsonField.of(key)) + + /** + * Sets [Builder.key] to an arbitrary JSON value. + * + * You should usually call [Builder.key] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun key(key: JsonField) = apply { this.key = key } + + 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 [CustomFieldFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomFieldFilter = + CustomFieldFilter( + checkRequired("entity", entity), + checkRequired("key", key), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): CustomFieldFilter = apply { + if (validated) { + return@apply + } + + entity().validate() + key() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (entity.asKnown().getOrNull()?.validity() ?: 0) + + (if (key.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) + + class Entity + @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 COMMIT = of("Commit") + + @JvmField val CONTRACT_CREDIT = of("ContractCredit") + + @JvmField val CONTRACT_CREDIT_OR_COMMIT = of("ContractCreditOrCommit") + + @JvmStatic fun of(value: String) = Entity(JsonField.of(value)) + } + + /** An enum containing [Entity]'s known values. */ + enum class Known { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + } + + /** + * An enum containing [Entity]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Entity] 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 { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + /** + * An enum member indicating that [Entity] 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) { + COMMIT -> Value.COMMIT + CONTRACT_CREDIT -> Value.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Value.CONTRACT_CREDIT_OR_COMMIT + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT -> Known.COMMIT + CONTRACT_CREDIT -> Known.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Known.CONTRACT_CREDIT_OR_COMMIT + else -> throw MetronomeInvalidDataException("Unknown Entity: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Entity = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Entity && 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 CustomFieldFilter && + entity == other.entity && + key == other.key && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(entity, key, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomFieldFilter{entity=$entity, key=$key, value=$value, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Exclude && + customFieldFilters == other.customFieldFilters && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(customFieldFilters, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Exclude{customFieldFilters=$customFieldFilters, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThresholdBalanceSpecifier && + exclude == other.exclude && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(paymentFraction, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(exclude, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "DiscountConfiguration{paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + "ThresholdBalanceSpecifier{exclude=$exclude, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1142,6 +2266,7 @@ private constructor( thresholdAmount == other.thresholdAmount && customCreditTypeId == other.customCreditTypeId && discountConfiguration == other.discountConfiguration && + thresholdBalanceSpecifiers == other.thresholdBalanceSpecifiers && additionalProperties == other.additionalProperties } @@ -1154,6 +2279,7 @@ private constructor( thresholdAmount, customCreditTypeId, discountConfiguration, + thresholdBalanceSpecifiers, additionalProperties, ) } @@ -1161,5 +2287,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "PrepaidBalanceThresholdConfiguration{commit=$commit, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, additionalProperties=$additionalProperties}" + "PrepaidBalanceThresholdConfiguration{commit=$commit, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, thresholdBalanceSpecifiers=$thresholdBalanceSpecifiers, additionalProperties=$additionalProperties}" } diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationV2.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationV2.kt index a3384c12..4c097953 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationV2.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationV2.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.metronome.api.core.Enum import com.metronome.api.core.ExcludeMissing import com.metronome.api.core.JsonField import com.metronome.api.core.JsonMissing @@ -29,6 +30,7 @@ private constructor( private val thresholdAmount: JsonField, private val customCreditTypeId: JsonField, private val discountConfiguration: JsonField, + private val thresholdBalanceSpecifiers: JsonField>, private val additionalProperties: MutableMap, ) { @@ -53,6 +55,9 @@ private constructor( @JsonProperty("discount_configuration") @ExcludeMissing discountConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + thresholdBalanceSpecifiers: JsonField> = JsonMissing.of(), ) : this( commit, isEnabled, @@ -61,6 +66,7 @@ private constructor( thresholdAmount, customCreditTypeId, discountConfiguration, + thresholdBalanceSpecifiers, mutableMapOf(), ) @@ -120,6 +126,13 @@ private constructor( fun discountConfiguration(): Optional = discountConfiguration.getOptional("discount_configuration") + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun thresholdBalanceSpecifiers(): Optional> = + thresholdBalanceSpecifiers.getOptional("threshold_balance_specifiers") + /** * Returns the raw JSON value of [commit]. * @@ -183,6 +196,17 @@ private constructor( @ExcludeMissing fun _discountConfiguration(): JsonField = discountConfiguration + /** + * Returns the raw JSON value of [thresholdBalanceSpecifiers]. + * + * Unlike [thresholdBalanceSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + fun _thresholdBalanceSpecifiers(): JsonField> = + thresholdBalanceSpecifiers + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -223,6 +247,8 @@ private constructor( private var thresholdAmount: JsonField? = null private var customCreditTypeId: JsonField = JsonMissing.of() private var discountConfiguration: JsonField = JsonMissing.of() + private var thresholdBalanceSpecifiers: JsonField>? = + null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -236,6 +262,10 @@ private constructor( thresholdAmount = prepaidBalanceThresholdConfigurationV2.thresholdAmount customCreditTypeId = prepaidBalanceThresholdConfigurationV2.customCreditTypeId discountConfiguration = prepaidBalanceThresholdConfigurationV2.discountConfiguration + thresholdBalanceSpecifiers = + prepaidBalanceThresholdConfigurationV2.thresholdBalanceSpecifiers.map { + it.toMutableList() + } additionalProperties = prepaidBalanceThresholdConfigurationV2.additionalProperties.toMutableMap() } @@ -344,6 +374,36 @@ private constructor( this.discountConfiguration = discountConfiguration } + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: List + ) = thresholdBalanceSpecifiers(JsonField.of(thresholdBalanceSpecifiers)) + + /** + * Sets [Builder.thresholdBalanceSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdBalanceSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: JsonField> + ) = apply { + this.thresholdBalanceSpecifiers = thresholdBalanceSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ThresholdBalanceSpecifier] to [thresholdBalanceSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addThresholdBalanceSpecifier(thresholdBalanceSpecifier: ThresholdBalanceSpecifier) = + apply { + thresholdBalanceSpecifiers = + (thresholdBalanceSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("thresholdBalanceSpecifiers", it).add(thresholdBalanceSpecifier) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -388,6 +448,7 @@ private constructor( checkRequired("thresholdAmount", thresholdAmount), customCreditTypeId, discountConfiguration, + (thresholdBalanceSpecifiers ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -414,6 +475,7 @@ private constructor( thresholdAmount() customCreditTypeId() discountConfiguration().ifPresent { it.validate() } + thresholdBalanceSpecifiers().ifPresent { it.forEach { it.validate() } } validated = true } @@ -438,7 +500,8 @@ private constructor( (if (rechargeToAmount.asKnown().isPresent) 1 else 0) + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + (if (customCreditTypeId.asKnown().isPresent) 1 else 0) + - (discountConfiguration.asKnown().getOrNull()?.validity() ?: 0) + (discountConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (thresholdBalanceSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) class Commit @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -954,6 +1017,7 @@ private constructor( @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val paymentFraction: JsonField, + private val cap: JsonField, private val additionalProperties: MutableMap, ) { @@ -961,8 +1025,9 @@ private constructor( private constructor( @JsonProperty("payment_fraction") @ExcludeMissing - paymentFraction: JsonField = JsonMissing.of() - ) : this(paymentFraction, mutableMapOf()) + paymentFraction: JsonField = JsonMissing.of(), + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), + ) : this(paymentFraction, cap, mutableMapOf()) /** * The fraction of the original amount that the customer pays after applying the discount. @@ -973,6 +1038,15 @@ private constructor( */ fun paymentFraction(): Double = paymentFraction.getRequired("payment_fraction") + /** + * If provided, the discount stops applying once the spend tracker has accumulated this much + * spend in the billing period. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") + /** * Returns the raw JSON value of [paymentFraction]. * @@ -983,6 +1057,13 @@ private constructor( @ExcludeMissing fun _paymentFraction(): JsonField = paymentFraction + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -1012,11 +1093,13 @@ private constructor( class Builder internal constructor() { private var paymentFraction: JsonField? = null + private var cap: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(discountConfiguration: DiscountConfiguration) = apply { paymentFraction = discountConfiguration.paymentFraction + cap = discountConfiguration.cap additionalProperties = discountConfiguration.additionalProperties.toMutableMap() } @@ -1039,6 +1122,21 @@ private constructor( this.paymentFraction = paymentFraction } + /** + * If provided, the discount stops applying once the spend tracker has accumulated this + * much spend in the billing period. + */ + fun cap(cap: Cap) = cap(JsonField.of(cap)) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1073,6 +1171,7 @@ private constructor( fun build(): DiscountConfiguration = DiscountConfiguration( checkRequired("paymentFraction", paymentFraction), + cap, additionalProperties.toMutableMap(), ) } @@ -1094,6 +1193,7 @@ private constructor( } paymentFraction() + cap().ifPresent { it.validate() } validated = true } @@ -1112,7 +1212,238 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = (if (paymentFraction.asKnown().isPresent) 1 else 0) + internal fun validity(): Int = + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + (cap.asKnown().getOrNull()?.validity() ?: 0) + + /** + * If provided, the discount stops applying once the spend tracker has accumulated this much + * spend in the billing period. + */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** Accumulated spend ceiling above which the discount stops applying. */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -1121,15 +1452,801 @@ private constructor( return other is DiscountConfiguration && paymentFraction == other.paymentFraction && + cap == other.cap && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(paymentFraction, cap, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DiscountConfiguration{paymentFraction=$paymentFraction, cap=$cap, additionalProperties=$additionalProperties}" + } + + class ThresholdBalanceSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val exclude: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("exclude") + @ExcludeMissing + exclude: JsonField> = JsonMissing.of() + ) : this(exclude, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 exclude(): List = exclude.getRequired("exclude") + + /** + * Returns the raw JSON value of [exclude]. + * + * Unlike [exclude], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("exclude") @ExcludeMissing fun _exclude(): JsonField> = exclude + + @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 + * [ThresholdBalanceSpecifier]. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThresholdBalanceSpecifier]. */ + class Builder internal constructor() { + + private var exclude: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(thresholdBalanceSpecifier: ThresholdBalanceSpecifier) = apply { + exclude = thresholdBalanceSpecifier.exclude.map { it.toMutableList() } + additionalProperties = thresholdBalanceSpecifier.additionalProperties.toMutableMap() + } + + fun exclude(exclude: List) = exclude(JsonField.of(exclude)) + + /** + * Sets [Builder.exclude] to an arbitrary JSON value. + * + * You should usually call [Builder.exclude] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun exclude(exclude: JsonField>) = apply { + this.exclude = exclude.map { it.toMutableList() } + } + + /** + * Adds a single [Exclude] to [Builder.exclude]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExclude(exclude: Exclude) = apply { + this.exclude = + (this.exclude ?: JsonField.of(mutableListOf())).also { + checkKnown("exclude", it).add(exclude) + } + } + + 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 [ThresholdBalanceSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThresholdBalanceSpecifier = + ThresholdBalanceSpecifier( + checkRequired("exclude", exclude).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ThresholdBalanceSpecifier = apply { + if (validated) { + return@apply + } + + exclude().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (exclude.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Exclude + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val customFieldFilters: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("custom_field_filters") + @ExcludeMissing + customFieldFilters: JsonField> = JsonMissing.of() + ) : this(customFieldFilters, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 customFieldFilters(): List = + customFieldFilters.getRequired("custom_field_filters") + + /** + * Returns the raw JSON value of [customFieldFilters]. + * + * Unlike [customFieldFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("custom_field_filters") + @ExcludeMissing + fun _customFieldFilters(): JsonField> = customFieldFilters + + @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 [Exclude]. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Exclude]. */ + class Builder internal constructor() { + + private var customFieldFilters: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(exclude: Exclude) = apply { + customFieldFilters = exclude.customFieldFilters.map { it.toMutableList() } + additionalProperties = exclude.additionalProperties.toMutableMap() + } + + fun customFieldFilters(customFieldFilters: List) = + customFieldFilters(JsonField.of(customFieldFilters)) + + /** + * Sets [Builder.customFieldFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.customFieldFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun customFieldFilters(customFieldFilters: JsonField>) = + apply { + this.customFieldFilters = customFieldFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CustomFieldFilter] to [customFieldFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCustomFieldFilter(customFieldFilter: CustomFieldFilter) = apply { + customFieldFilters = + (customFieldFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("customFieldFilters", it).add(customFieldFilter) + } + } + + 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 [Exclude]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Exclude = + Exclude( + checkRequired("customFieldFilters", customFieldFilters).map { + it.toImmutable() + }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Exclude = apply { + if (validated) { + return@apply + } + + customFieldFilters().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (customFieldFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class CustomFieldFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val entity: JsonField, + private val key: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("entity") + @ExcludeMissing + entity: JsonField = JsonMissing.of(), + @JsonProperty("key") @ExcludeMissing key: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(entity, key, value, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 entity(): Entity = entity.getRequired("entity") + + /** + * @throws MetronomeInvalidDataException 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 key(): String = key.getRequired("key") + + /** + * @throws MetronomeInvalidDataException 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 [entity]. + * + * Unlike [entity], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("entity") @ExcludeMissing fun _entity(): JsonField = entity + + /** + * Returns the raw JSON value of [key]. + * + * Unlike [key], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("key") @ExcludeMissing fun _key(): JsonField = key + + /** + * 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 + * [CustomFieldFilter]. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFieldFilter]. */ + class Builder internal constructor() { + + private var entity: JsonField? = null + private var key: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(customFieldFilter: CustomFieldFilter) = apply { + entity = customFieldFilter.entity + key = customFieldFilter.key + value = customFieldFilter.value + additionalProperties = customFieldFilter.additionalProperties.toMutableMap() + } + + fun entity(entity: Entity) = entity(JsonField.of(entity)) + + /** + * Sets [Builder.entity] to an arbitrary JSON value. + * + * You should usually call [Builder.entity] with a well-typed [Entity] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun entity(entity: JsonField) = apply { this.entity = entity } + + fun key(key: String) = key(JsonField.of(key)) + + /** + * Sets [Builder.key] to an arbitrary JSON value. + * + * You should usually call [Builder.key] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun key(key: JsonField) = apply { this.key = key } + + 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 [CustomFieldFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomFieldFilter = + CustomFieldFilter( + checkRequired("entity", entity), + checkRequired("key", key), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): CustomFieldFilter = apply { + if (validated) { + return@apply + } + + entity().validate() + key() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (entity.asKnown().getOrNull()?.validity() ?: 0) + + (if (key.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) + + class Entity + @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 COMMIT = of("Commit") + + @JvmField val CONTRACT_CREDIT = of("ContractCredit") + + @JvmField val CONTRACT_CREDIT_OR_COMMIT = of("ContractCreditOrCommit") + + @JvmStatic fun of(value: String) = Entity(JsonField.of(value)) + } + + /** An enum containing [Entity]'s known values. */ + enum class Known { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + } + + /** + * An enum containing [Entity]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Entity] 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 { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + /** + * An enum member indicating that [Entity] 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) { + COMMIT -> Value.COMMIT + CONTRACT_CREDIT -> Value.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Value.CONTRACT_CREDIT_OR_COMMIT + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT -> Known.COMMIT + CONTRACT_CREDIT -> Known.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Known.CONTRACT_CREDIT_OR_COMMIT + else -> throw MetronomeInvalidDataException("Unknown Entity: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Entity = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Entity && 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 CustomFieldFilter && + entity == other.entity && + key == other.key && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(entity, key, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomFieldFilter{entity=$entity, key=$key, value=$value, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Exclude && + customFieldFilters == other.customFieldFilters && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(customFieldFilters, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Exclude{customFieldFilters=$customFieldFilters, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThresholdBalanceSpecifier && + exclude == other.exclude && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(paymentFraction, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(exclude, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "DiscountConfiguration{paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + "ThresholdBalanceSpecifier{exclude=$exclude, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1145,6 +2262,7 @@ private constructor( thresholdAmount == other.thresholdAmount && customCreditTypeId == other.customCreditTypeId && discountConfiguration == other.discountConfiguration && + thresholdBalanceSpecifiers == other.thresholdBalanceSpecifiers && additionalProperties == other.additionalProperties } @@ -1157,6 +2275,7 @@ private constructor( thresholdAmount, customCreditTypeId, discountConfiguration, + thresholdBalanceSpecifiers, additionalProperties, ) } @@ -1164,5 +2283,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "PrepaidBalanceThresholdConfigurationV2{commit=$commit, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, additionalProperties=$additionalProperties}" + "PrepaidBalanceThresholdConfigurationV2{commit=$commit, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, thresholdBalanceSpecifiers=$thresholdBalanceSpecifiers, additionalProperties=$additionalProperties}" } diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/SpendThresholdConfiguration.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/SpendThresholdConfiguration.kt index f837f4cb..6967b7c7 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/SpendThresholdConfiguration.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/SpendThresholdConfiguration.kt @@ -348,6 +348,7 @@ private constructor( @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val paymentFraction: JsonField, + private val cap: JsonField, private val additionalProperties: MutableMap, ) { @@ -355,8 +356,9 @@ private constructor( private constructor( @JsonProperty("payment_fraction") @ExcludeMissing - paymentFraction: JsonField = JsonMissing.of() - ) : this(paymentFraction, mutableMapOf()) + paymentFraction: JsonField = JsonMissing.of(), + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), + ) : this(paymentFraction, cap, mutableMapOf()) /** * The fraction of the original amount that the customer pays after applying the discount. @@ -367,6 +369,15 @@ private constructor( */ fun paymentFraction(): Double = paymentFraction.getRequired("payment_fraction") + /** + * If provided, the discount stops applying once the spend tracker has accumulated this much + * spend in the billing period. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") + /** * Returns the raw JSON value of [paymentFraction]. * @@ -377,6 +388,13 @@ private constructor( @ExcludeMissing fun _paymentFraction(): JsonField = paymentFraction + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -406,11 +424,13 @@ private constructor( class Builder internal constructor() { private var paymentFraction: JsonField? = null + private var cap: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(discountConfiguration: DiscountConfiguration) = apply { paymentFraction = discountConfiguration.paymentFraction + cap = discountConfiguration.cap additionalProperties = discountConfiguration.additionalProperties.toMutableMap() } @@ -433,6 +453,21 @@ private constructor( this.paymentFraction = paymentFraction } + /** + * If provided, the discount stops applying once the spend tracker has accumulated this + * much spend in the billing period. + */ + fun cap(cap: Cap) = cap(JsonField.of(cap)) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -467,6 +502,7 @@ private constructor( fun build(): DiscountConfiguration = DiscountConfiguration( checkRequired("paymentFraction", paymentFraction), + cap, additionalProperties.toMutableMap(), ) } @@ -488,6 +524,7 @@ private constructor( } paymentFraction() + cap().ifPresent { it.validate() } validated = true } @@ -506,7 +543,238 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = (if (paymentFraction.asKnown().isPresent) 1 else 0) + internal fun validity(): Int = + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + (cap.asKnown().getOrNull()?.validity() ?: 0) + + /** + * If provided, the discount stops applying once the spend tracker has accumulated this much + * spend in the billing period. + */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** Accumulated spend ceiling above which the discount stops applying. */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -515,15 +783,18 @@ private constructor( return other is DiscountConfiguration && paymentFraction == other.paymentFraction && + cap == other.cap && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(paymentFraction, additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(paymentFraction, cap, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "DiscountConfiguration{paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + "DiscountConfiguration{paymentFraction=$paymentFraction, cap=$cap, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/SpendThresholdConfigurationV2.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/SpendThresholdConfigurationV2.kt index 8efb01d9..3f735a77 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/SpendThresholdConfigurationV2.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/SpendThresholdConfigurationV2.kt @@ -349,6 +349,7 @@ private constructor( @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val paymentFraction: JsonField, + private val cap: JsonField, private val additionalProperties: MutableMap, ) { @@ -356,8 +357,9 @@ private constructor( private constructor( @JsonProperty("payment_fraction") @ExcludeMissing - paymentFraction: JsonField = JsonMissing.of() - ) : this(paymentFraction, mutableMapOf()) + paymentFraction: JsonField = JsonMissing.of(), + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), + ) : this(paymentFraction, cap, mutableMapOf()) /** * The fraction of the original amount that the customer pays after applying the discount. @@ -368,6 +370,15 @@ private constructor( */ fun paymentFraction(): Double = paymentFraction.getRequired("payment_fraction") + /** + * If provided, the discount stops applying once the spend tracker has accumulated this much + * spend in the billing period. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") + /** * Returns the raw JSON value of [paymentFraction]. * @@ -378,6 +389,13 @@ private constructor( @ExcludeMissing fun _paymentFraction(): JsonField = paymentFraction + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -407,11 +425,13 @@ private constructor( class Builder internal constructor() { private var paymentFraction: JsonField? = null + private var cap: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(discountConfiguration: DiscountConfiguration) = apply { paymentFraction = discountConfiguration.paymentFraction + cap = discountConfiguration.cap additionalProperties = discountConfiguration.additionalProperties.toMutableMap() } @@ -434,6 +454,21 @@ private constructor( this.paymentFraction = paymentFraction } + /** + * If provided, the discount stops applying once the spend tracker has accumulated this + * much spend in the billing period. + */ + fun cap(cap: Cap) = cap(JsonField.of(cap)) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -468,6 +503,7 @@ private constructor( fun build(): DiscountConfiguration = DiscountConfiguration( checkRequired("paymentFraction", paymentFraction), + cap, additionalProperties.toMutableMap(), ) } @@ -489,6 +525,7 @@ private constructor( } paymentFraction() + cap().ifPresent { it.validate() } validated = true } @@ -507,7 +544,238 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = (if (paymentFraction.asKnown().isPresent) 1 else 0) + internal fun validity(): Int = + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + (cap.asKnown().getOrNull()?.validity() ?: 0) + + /** + * If provided, the discount stops applying once the spend tracker has accumulated this much + * spend in the billing period. + */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** Accumulated spend ceiling above which the discount stops applying. */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -516,15 +784,18 @@ private constructor( return other is DiscountConfiguration && paymentFraction == other.paymentFraction && + cap == other.cap && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(paymentFraction, additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(paymentFraction, cap, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "DiscountConfiguration{paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + "DiscountConfiguration{paymentFraction=$paymentFraction, cap=$cap, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractAmendParams.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractAmendParams.kt index a85f20d9..d9ce7069 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractAmendParams.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractAmendParams.kt @@ -1544,6 +1544,7 @@ private constructor( private val rateType: JsonField, private val rolloverFraction: JsonField, private val specifiers: JsonField>, + private val spendTrackerAttributes: JsonField, private val temporaryId: JsonField, private val additionalProperties: MutableMap, ) { @@ -1592,6 +1593,9 @@ private constructor( @JsonProperty("specifiers") @ExcludeMissing specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + spendTrackerAttributes: JsonField = JsonMissing.of(), @JsonProperty("temporary_id") @ExcludeMissing temporaryId: JsonField = JsonMissing.of(), @@ -1612,6 +1616,7 @@ private constructor( rateType, rolloverFraction, specifiers, + spendTrackerAttributes, temporaryId, mutableMapOf(), ) @@ -1754,6 +1759,15 @@ private constructor( fun specifiers(): Optional> = specifiers.getOptional("specifiers") + /** + * Optional attributes for spend tracker integration. Immutable after creation. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun spendTrackerAttributes(): Optional = + spendTrackerAttributes.getOptional("spend_tracker_attributes") + /** * A temporary ID for the commit that can be used to reference the commit for commit * specific overrides. @@ -1904,6 +1918,16 @@ private constructor( @ExcludeMissing fun _specifiers(): JsonField> = specifiers + /** + * Returns the raw JSON value of [spendTrackerAttributes]. + * + * Unlike [spendTrackerAttributes], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + fun _spendTrackerAttributes(): JsonField = spendTrackerAttributes + /** * Returns the raw JSON value of [temporaryId]. * @@ -1959,6 +1983,7 @@ private constructor( private var rateType: JsonField = JsonMissing.of() private var rolloverFraction: JsonField = JsonMissing.of() private var specifiers: JsonField>? = null + private var spendTrackerAttributes: JsonField = JsonMissing.of() private var temporaryId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -1980,6 +2005,7 @@ private constructor( rateType = commit.rateType rolloverFraction = commit.rolloverFraction specifiers = commit.specifiers.map { it.toMutableList() } + spendTrackerAttributes = commit.spendTrackerAttributes temporaryId = commit.temporaryId additionalProperties = commit.additionalProperties.toMutableMap() } @@ -2260,6 +2286,22 @@ private constructor( } } + /** Optional attributes for spend tracker integration. Immutable after creation. */ + fun spendTrackerAttributes(spendTrackerAttributes: SpendTrackerAttributes) = + spendTrackerAttributes(JsonField.of(spendTrackerAttributes)) + + /** + * Sets [Builder.spendTrackerAttributes] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAttributes] with a well-typed + * [SpendTrackerAttributes] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun spendTrackerAttributes(spendTrackerAttributes: JsonField) = + apply { + this.spendTrackerAttributes = spendTrackerAttributes + } + /** * A temporary ID for the commit that can be used to reference the commit for commit * specific overrides. @@ -2327,6 +2369,7 @@ private constructor( rateType, rolloverFraction, (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + spendTrackerAttributes, temporaryId, additionalProperties.toMutableMap(), ) @@ -2364,6 +2407,7 @@ private constructor( rateType().ifPresent { it.validate() } rolloverFraction() specifiers().ifPresent { it.forEach { it.validate() } } + spendTrackerAttributes().ifPresent { it.validate() } temporaryId() validated = true } @@ -2400,6 +2444,7 @@ private constructor( (rateType.asKnown().getOrNull()?.validity() ?: 0) + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendTrackerAttributes.asKnown().getOrNull()?.validity() ?: 0) + (if (temporaryId.asKnown().isPresent) 1 else 0) class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4744,6 +4789,198 @@ private constructor( override fun toString() = value.toString() } + /** Optional attributes for spend tracker integration. Immutable after creation. */ + class SpendTrackerAttributes + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val countsAsDiscounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("counts_as_discounted") + @ExcludeMissing + countsAsDiscounted: JsonField = JsonMissing.of() + ) : this(countsAsDiscounted, mutableMapOf()) + + /** + * If true, this commit will be included in spend trackers with discounted set to + * DISCOUNTED_ONLY + * + * @throws MetronomeInvalidDataException 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 countsAsDiscounted(): Boolean = + countsAsDiscounted.getRequired("counts_as_discounted") + + /** + * Returns the raw JSON value of [countsAsDiscounted]. + * + * Unlike [countsAsDiscounted], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("counts_as_discounted") + @ExcludeMissing + fun _countsAsDiscounted(): JsonField = countsAsDiscounted + + @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 + * [SpendTrackerAttributes]. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTrackerAttributes]. */ + class Builder internal constructor() { + + private var countsAsDiscounted: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTrackerAttributes: SpendTrackerAttributes) = apply { + countsAsDiscounted = spendTrackerAttributes.countsAsDiscounted + additionalProperties = + spendTrackerAttributes.additionalProperties.toMutableMap() + } + + /** + * If true, this commit will be included in spend trackers with discounted set to + * DISCOUNTED_ONLY + */ + fun countsAsDiscounted(countsAsDiscounted: Boolean) = + countsAsDiscounted(JsonField.of(countsAsDiscounted)) + + /** + * Sets [Builder.countsAsDiscounted] to an arbitrary JSON value. + * + * You should usually call [Builder.countsAsDiscounted] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun countsAsDiscounted(countsAsDiscounted: JsonField) = apply { + this.countsAsDiscounted = countsAsDiscounted + } + + 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 [SpendTrackerAttributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTrackerAttributes = + SpendTrackerAttributes( + checkRequired("countsAsDiscounted", countsAsDiscounted), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SpendTrackerAttributes = apply { + if (validated) { + return@apply + } + + countsAsDiscounted() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (countsAsDiscounted.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendTrackerAttributes && + countsAsDiscounted == other.countsAsDiscounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(countsAsDiscounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTrackerAttributes{countsAsDiscounted=$countsAsDiscounted, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4766,6 +5003,7 @@ private constructor( rateType == other.rateType && rolloverFraction == other.rolloverFraction && specifiers == other.specifiers && + spendTrackerAttributes == other.spendTrackerAttributes && temporaryId == other.temporaryId && additionalProperties == other.additionalProperties } @@ -4788,6 +5026,7 @@ private constructor( rateType, rolloverFraction, specifiers, + spendTrackerAttributes, temporaryId, additionalProperties, ) @@ -4796,7 +5035,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Commit{productId=$productId, type=$type, accessSchedule=$accessSchedule, amount=$amount, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, rolloverFraction=$rolloverFraction, specifiers=$specifiers, temporaryId=$temporaryId, additionalProperties=$additionalProperties}" + "Commit{productId=$productId, type=$type, accessSchedule=$accessSchedule, amount=$amount, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, rolloverFraction=$rolloverFraction, specifiers=$specifiers, spendTrackerAttributes=$spendTrackerAttributes, temporaryId=$temporaryId, additionalProperties=$additionalProperties}" } class Credit diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractCreateParams.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractCreateParams.kt index fd83b326..7d81aa3d 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractCreateParams.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractCreateParams.kt @@ -349,6 +349,14 @@ private constructor( fun spendThresholdConfiguration(): Optional = body.spendThresholdConfiguration() + /** + * Spend trackers to attach to this contract. Aliases must be unique within a contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = body.spendTrackers() + /** * Optional list of * [subscriptions](https://docs.metronome.com/manage-product-access/create-subscription/) to add @@ -613,6 +621,13 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = body._spendThresholdConfiguration() + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _spendTrackers(): JsonField> = body._spendTrackers() + /** * Returns the raw JSON value of [subscriptions]. * @@ -1206,6 +1221,31 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { body.spendThresholdConfiguration(spendThresholdConfiguration) } + /** Spend trackers to attach to this contract. Aliases must be unique within a contract. */ + fun spendTrackers(spendTrackers: List) = apply { + body.spendTrackers(spendTrackers) + } + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + body.spendTrackers(spendTrackers) + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + body.addSpendTracker(spendTracker) + } + /** * Optional list of * [subscriptions](https://docs.metronome.com/manage-product-access/create-subscription/) to @@ -1485,6 +1525,7 @@ private constructor( private val scheduledCharges: JsonField>, private val scheduledChargesOnUsageInvoices: JsonField, private val spendThresholdConfiguration: JsonField, + private val spendTrackers: JsonField>, private val subscriptions: JsonField>, private val totalContractValue: JsonField, private val transition: JsonField, @@ -1582,6 +1623,9 @@ private constructor( @JsonProperty("spend_threshold_configuration") @ExcludeMissing spendThresholdConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("spend_trackers") + @ExcludeMissing + spendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("subscriptions") @ExcludeMissing subscriptions: JsonField> = JsonMissing.of(), @@ -1629,6 +1673,7 @@ private constructor( scheduledCharges, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, totalContractValue, transition, @@ -1864,6 +1909,15 @@ private constructor( fun spendThresholdConfiguration(): Optional = spendThresholdConfiguration.getOptional("spend_threshold_configuration") + /** + * Spend trackers to attach to this contract. Aliases must be unique within a contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = + spendTrackers.getOptional("spend_trackers") + /** * Optional list of * [subscriptions](https://docs.metronome.com/manage-product-access/create-subscription/) to @@ -2182,6 +2236,16 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = spendThresholdConfiguration + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_trackers") + @ExcludeMissing + fun _spendTrackers(): JsonField> = spendTrackers + /** * Returns the raw JSON value of [subscriptions]. * @@ -2306,6 +2370,7 @@ private constructor( JsonMissing.of() private var spendThresholdConfiguration: JsonField = JsonMissing.of() + private var spendTrackers: JsonField>? = null private var subscriptions: JsonField>? = null private var totalContractValue: JsonField = JsonMissing.of() private var transition: JsonField = JsonMissing.of() @@ -2344,6 +2409,7 @@ private constructor( scheduledCharges = body.scheduledCharges.map { it.toMutableList() } scheduledChargesOnUsageInvoices = body.scheduledChargesOnUsageInvoices spendThresholdConfiguration = body.spendThresholdConfiguration + spendTrackers = body.spendTrackers.map { it.toMutableList() } subscriptions = body.subscriptions.map { it.toMutableList() } totalContractValue = body.totalContractValue transition = body.transition @@ -2887,6 +2953,35 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { this.spendThresholdConfiguration = spendThresholdConfiguration } + /** + * Spend trackers to attach to this contract. Aliases must be unique within a contract. + */ + fun spendTrackers(spendTrackers: List) = + spendTrackers(JsonField.of(spendTrackers)) + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + this.spendTrackers = spendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + spendTrackers = + (spendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("spendTrackers", it).add(spendTracker) + } + } + /** * Optional list of * [subscriptions](https://docs.metronome.com/manage-product-access/create-subscription/) @@ -3054,6 +3149,7 @@ private constructor( (scheduledCharges ?: JsonMissing.of()).map { it.toImmutable() }, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + (spendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, (subscriptions ?: JsonMissing.of()).map { it.toImmutable() }, totalContractValue, transition, @@ -3108,6 +3204,7 @@ private constructor( scheduledCharges().ifPresent { it.forEach { it.validate() } } scheduledChargesOnUsageInvoices().ifPresent { it.validate() } spendThresholdConfiguration().ifPresent { it.validate() } + spendTrackers().ifPresent { it.forEach { it.validate() } } subscriptions().ifPresent { it.forEach { it.validate() } } totalContractValue() transition().ifPresent { it.validate() } @@ -3161,6 +3258,7 @@ private constructor( (scheduledCharges.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (scheduledChargesOnUsageInvoices.asKnown().getOrNull()?.validity() ?: 0) + (spendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (spendTrackers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (subscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (totalContractValue.asKnown().isPresent) 1 else 0) + (transition.asKnown().getOrNull()?.validity() ?: 0) + @@ -3203,6 +3301,7 @@ private constructor( scheduledCharges == other.scheduledCharges && scheduledChargesOnUsageInvoices == other.scheduledChargesOnUsageInvoices && spendThresholdConfiguration == other.spendThresholdConfiguration && + spendTrackers == other.spendTrackers && subscriptions == other.subscriptions && totalContractValue == other.totalContractValue && transition == other.transition && @@ -3242,6 +3341,7 @@ private constructor( scheduledCharges, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, totalContractValue, transition, @@ -3255,7 +3355,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{customerId=$customerId, startingAt=$startingAt, billingProviderConfiguration=$billingProviderConfiguration, commits=$commits, credits=$credits, customFields=$customFields, discounts=$discounts, endingBefore=$endingBefore, hierarchyConfiguration=$hierarchyConfiguration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, netsuiteSalesOrderId=$netsuiteSalesOrderId, overrides=$overrides, packageAlias=$packageAlias, packageId=$packageId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, professionalServices=$professionalServices, rateCardAlias=$rateCardAlias, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, resellerRoyalties=$resellerRoyalties, revenueSystemConfiguration=$revenueSystemConfiguration, salesforceOpportunityId=$salesforceOpportunityId, scheduledCharges=$scheduledCharges, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, subscriptions=$subscriptions, totalContractValue=$totalContractValue, transition=$transition, uniquenessKey=$uniquenessKey, usageFilter=$usageFilter, usageStatementSchedule=$usageStatementSchedule, additionalProperties=$additionalProperties}" + "Body{customerId=$customerId, startingAt=$startingAt, billingProviderConfiguration=$billingProviderConfiguration, commits=$commits, credits=$credits, customFields=$customFields, discounts=$discounts, endingBefore=$endingBefore, hierarchyConfiguration=$hierarchyConfiguration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, netsuiteSalesOrderId=$netsuiteSalesOrderId, overrides=$overrides, packageAlias=$packageAlias, packageId=$packageId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, professionalServices=$professionalServices, rateCardAlias=$rateCardAlias, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, resellerRoyalties=$resellerRoyalties, revenueSystemConfiguration=$revenueSystemConfiguration, salesforceOpportunityId=$salesforceOpportunityId, scheduledCharges=$scheduledCharges, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, spendTrackers=$spendTrackers, subscriptions=$subscriptions, totalContractValue=$totalContractValue, transition=$transition, uniquenessKey=$uniquenessKey, usageFilter=$usageFilter, usageStatementSchedule=$usageStatementSchedule, additionalProperties=$additionalProperties}" } /** @@ -3869,6 +3969,7 @@ private constructor( private val rateType: JsonField, private val rolloverFraction: JsonField, private val specifiers: JsonField>, + private val spendTrackerAttributes: JsonField, private val temporaryId: JsonField, private val additionalProperties: MutableMap, ) { @@ -3917,6 +4018,9 @@ private constructor( @JsonProperty("specifiers") @ExcludeMissing specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + spendTrackerAttributes: JsonField = JsonMissing.of(), @JsonProperty("temporary_id") @ExcludeMissing temporaryId: JsonField = JsonMissing.of(), @@ -3937,6 +4041,7 @@ private constructor( rateType, rolloverFraction, specifiers, + spendTrackerAttributes, temporaryId, mutableMapOf(), ) @@ -4079,6 +4184,15 @@ private constructor( fun specifiers(): Optional> = specifiers.getOptional("specifiers") + /** + * Optional attributes for spend tracker integration. Immutable after creation. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun spendTrackerAttributes(): Optional = + spendTrackerAttributes.getOptional("spend_tracker_attributes") + /** * A temporary ID for the commit that can be used to reference the commit for commit * specific overrides. @@ -4229,6 +4343,16 @@ private constructor( @ExcludeMissing fun _specifiers(): JsonField> = specifiers + /** + * Returns the raw JSON value of [spendTrackerAttributes]. + * + * Unlike [spendTrackerAttributes], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + fun _spendTrackerAttributes(): JsonField = spendTrackerAttributes + /** * Returns the raw JSON value of [temporaryId]. * @@ -4284,6 +4408,7 @@ private constructor( private var rateType: JsonField = JsonMissing.of() private var rolloverFraction: JsonField = JsonMissing.of() private var specifiers: JsonField>? = null + private var spendTrackerAttributes: JsonField = JsonMissing.of() private var temporaryId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -4305,6 +4430,7 @@ private constructor( rateType = commit.rateType rolloverFraction = commit.rolloverFraction specifiers = commit.specifiers.map { it.toMutableList() } + spendTrackerAttributes = commit.spendTrackerAttributes temporaryId = commit.temporaryId additionalProperties = commit.additionalProperties.toMutableMap() } @@ -4585,6 +4711,22 @@ private constructor( } } + /** Optional attributes for spend tracker integration. Immutable after creation. */ + fun spendTrackerAttributes(spendTrackerAttributes: SpendTrackerAttributes) = + spendTrackerAttributes(JsonField.of(spendTrackerAttributes)) + + /** + * Sets [Builder.spendTrackerAttributes] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAttributes] with a well-typed + * [SpendTrackerAttributes] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun spendTrackerAttributes(spendTrackerAttributes: JsonField) = + apply { + this.spendTrackerAttributes = spendTrackerAttributes + } + /** * A temporary ID for the commit that can be used to reference the commit for commit * specific overrides. @@ -4652,6 +4794,7 @@ private constructor( rateType, rolloverFraction, (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + spendTrackerAttributes, temporaryId, additionalProperties.toMutableMap(), ) @@ -4689,6 +4832,7 @@ private constructor( rateType().ifPresent { it.validate() } rolloverFraction() specifiers().ifPresent { it.forEach { it.validate() } } + spendTrackerAttributes().ifPresent { it.validate() } temporaryId() validated = true } @@ -4725,6 +4869,7 @@ private constructor( (rateType.asKnown().getOrNull()?.validity() ?: 0) + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendTrackerAttributes.asKnown().getOrNull()?.validity() ?: 0) + (if (temporaryId.asKnown().isPresent) 1 else 0) class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -7069,6 +7214,198 @@ private constructor( override fun toString() = value.toString() } + /** Optional attributes for spend tracker integration. Immutable after creation. */ + class SpendTrackerAttributes + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val countsAsDiscounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("counts_as_discounted") + @ExcludeMissing + countsAsDiscounted: JsonField = JsonMissing.of() + ) : this(countsAsDiscounted, mutableMapOf()) + + /** + * If true, this commit will be included in spend trackers with discounted set to + * DISCOUNTED_ONLY + * + * @throws MetronomeInvalidDataException 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 countsAsDiscounted(): Boolean = + countsAsDiscounted.getRequired("counts_as_discounted") + + /** + * Returns the raw JSON value of [countsAsDiscounted]. + * + * Unlike [countsAsDiscounted], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("counts_as_discounted") + @ExcludeMissing + fun _countsAsDiscounted(): JsonField = countsAsDiscounted + + @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 + * [SpendTrackerAttributes]. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTrackerAttributes]. */ + class Builder internal constructor() { + + private var countsAsDiscounted: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTrackerAttributes: SpendTrackerAttributes) = apply { + countsAsDiscounted = spendTrackerAttributes.countsAsDiscounted + additionalProperties = + spendTrackerAttributes.additionalProperties.toMutableMap() + } + + /** + * If true, this commit will be included in spend trackers with discounted set to + * DISCOUNTED_ONLY + */ + fun countsAsDiscounted(countsAsDiscounted: Boolean) = + countsAsDiscounted(JsonField.of(countsAsDiscounted)) + + /** + * Sets [Builder.countsAsDiscounted] to an arbitrary JSON value. + * + * You should usually call [Builder.countsAsDiscounted] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun countsAsDiscounted(countsAsDiscounted: JsonField) = apply { + this.countsAsDiscounted = countsAsDiscounted + } + + 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 [SpendTrackerAttributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTrackerAttributes = + SpendTrackerAttributes( + checkRequired("countsAsDiscounted", countsAsDiscounted), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SpendTrackerAttributes = apply { + if (validated) { + return@apply + } + + countsAsDiscounted() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (countsAsDiscounted.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendTrackerAttributes && + countsAsDiscounted == other.countsAsDiscounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(countsAsDiscounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTrackerAttributes{countsAsDiscounted=$countsAsDiscounted, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -7091,6 +7428,7 @@ private constructor( rateType == other.rateType && rolloverFraction == other.rolloverFraction && specifiers == other.specifiers && + spendTrackerAttributes == other.spendTrackerAttributes && temporaryId == other.temporaryId && additionalProperties == other.additionalProperties } @@ -7113,6 +7451,7 @@ private constructor( rateType, rolloverFraction, specifiers, + spendTrackerAttributes, temporaryId, additionalProperties, ) @@ -7121,7 +7460,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Commit{productId=$productId, type=$type, accessSchedule=$accessSchedule, amount=$amount, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, rolloverFraction=$rolloverFraction, specifiers=$specifiers, temporaryId=$temporaryId, additionalProperties=$additionalProperties}" + "Commit{productId=$productId, type=$type, accessSchedule=$accessSchedule, amount=$amount, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, rolloverFraction=$rolloverFraction, specifiers=$specifiers, spendTrackerAttributes=$spendTrackerAttributes, temporaryId=$temporaryId, additionalProperties=$additionalProperties}" } class Credit @@ -25160,6 +25499,1174 @@ private constructor( override fun toString() = value.toString() } + class SpendTracker + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val alias: JsonField, + private val applicableSpendSpecifiers: JsonField>, + private val creditTypeId: JsonField, + private val resetFrequency: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("alias") @ExcludeMissing alias: JsonField = JsonMissing.of(), + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + applicableSpendSpecifiers: JsonField> = JsonMissing.of(), + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("reset_frequency") + @ExcludeMissing + resetFrequency: JsonField = JsonMissing.of(), + ) : this(alias, applicableSpendSpecifiers, creditTypeId, resetFrequency, mutableMapOf()) + + /** + * Human-readable identifier, unique per contract. + * + * @throws MetronomeInvalidDataException 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 alias(): String = alias.getRequired("alias") + + /** + * @throws MetronomeInvalidDataException 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 applicableSpendSpecifiers(): List = + applicableSpendSpecifiers.getRequired("applicable_spend_specifiers") + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 resetFrequency(): ResetFrequency = resetFrequency.getRequired("reset_frequency") + + /** + * Returns the raw JSON value of [alias]. + * + * Unlike [alias], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("alias") @ExcludeMissing fun _alias(): JsonField = alias + + /** + * Returns the raw JSON value of [applicableSpendSpecifiers]. + * + * Unlike [applicableSpendSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + fun _applicableSpendSpecifiers(): JsonField> = + applicableSpendSpecifiers + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [resetFrequency]. + * + * Unlike [resetFrequency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("reset_frequency") + @ExcludeMissing + fun _resetFrequency(): JsonField = resetFrequency + + @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 [SpendTracker]. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTracker]. */ + class Builder internal constructor() { + + private var alias: JsonField? = null + private var applicableSpendSpecifiers: + JsonField>? = + null + private var creditTypeId: JsonField? = null + private var resetFrequency: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTracker: SpendTracker) = apply { + alias = spendTracker.alias + applicableSpendSpecifiers = + spendTracker.applicableSpendSpecifiers.map { it.toMutableList() } + creditTypeId = spendTracker.creditTypeId + resetFrequency = spendTracker.resetFrequency + additionalProperties = spendTracker.additionalProperties.toMutableMap() + } + + /** Human-readable identifier, unique per contract. */ + fun alias(alias: String) = alias(JsonField.of(alias)) + + /** + * Sets [Builder.alias] to an arbitrary JSON value. + * + * You should usually call [Builder.alias] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun alias(alias: JsonField) = apply { this.alias = alias } + + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: List + ) = applicableSpendSpecifiers(JsonField.of(applicableSpendSpecifiers)) + + /** + * Sets [Builder.applicableSpendSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableSpendSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: JsonField> + ) = apply { + this.applicableSpendSpecifiers = + applicableSpendSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ApplicableSpendSpecifier] to [applicableSpendSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableSpendSpecifier(applicableSpendSpecifier: ApplicableSpendSpecifier) = + apply { + applicableSpendSpecifiers = + (applicableSpendSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableSpendSpecifiers", it) + .add(applicableSpendSpecifier) + } + } + + fun creditTypeId(creditTypeId: String) = creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun resetFrequency(resetFrequency: ResetFrequency) = + resetFrequency(JsonField.of(resetFrequency)) + + /** + * Sets [Builder.resetFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.resetFrequency] with a well-typed [ResetFrequency] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun resetFrequency(resetFrequency: JsonField) = apply { + this.resetFrequency = resetFrequency + } + + 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 [SpendTracker]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTracker = + SpendTracker( + checkRequired("alias", alias), + checkRequired("applicableSpendSpecifiers", applicableSpendSpecifiers).map { + it.toImmutable() + }, + checkRequired("creditTypeId", creditTypeId), + checkRequired("resetFrequency", resetFrequency), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendTracker = apply { + if (validated) { + return@apply + } + + alias() + applicableSpendSpecifiers().forEach { it.validate() } + creditTypeId() + resetFrequency().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (alias.asKnown().isPresent) 1 else 0) + + (applicableSpendSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (creditTypeId.asKnown().isPresent) 1 else 0) + + (resetFrequency.asKnown().getOrNull()?.validity() ?: 0) + + class ApplicableSpendSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sources: JsonField>, + private val spendType: JsonField, + private val discounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("sources") + @ExcludeMissing + sources: JsonField> = JsonMissing.of(), + @JsonProperty("spend_type") + @ExcludeMissing + spendType: JsonField = JsonMissing.of(), + @JsonProperty("discounted") + @ExcludeMissing + discounted: JsonField = JsonMissing.of(), + ) : this(sources, spendType, discounted, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 sources(): List = sources.getRequired("sources") + + /** + * @throws MetronomeInvalidDataException 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 spendType(): SpendType = spendType.getRequired("spend_type") + + /** + * Filter by whether the spend was discounted. Defaults to ANY if omitted. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun discounted(): Optional = discounted.getOptional("discounted") + + /** + * Returns the raw JSON value of [sources]. + * + * Unlike [sources], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sources") + @ExcludeMissing + fun _sources(): JsonField> = sources + + /** + * Returns the raw JSON value of [spendType]. + * + * Unlike [spendType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_type") + @ExcludeMissing + fun _spendType(): JsonField = spendType + + /** + * Returns the raw JSON value of [discounted]. + * + * Unlike [discounted], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("discounted") + @ExcludeMissing + fun _discounted(): JsonField = discounted + + @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 + * [ApplicableSpendSpecifier]. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApplicableSpendSpecifier]. */ + class Builder internal constructor() { + + private var sources: JsonField>? = null + private var spendType: JsonField? = null + private var discounted: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { + sources = applicableSpendSpecifier.sources.map { it.toMutableList() } + spendType = applicableSpendSpecifier.spendType + discounted = applicableSpendSpecifier.discounted + additionalProperties = + applicableSpendSpecifier.additionalProperties.toMutableMap() + } + + fun sources(sources: List) = sources(JsonField.of(sources)) + + /** + * Sets [Builder.sources] to an arbitrary JSON value. + * + * You should usually call [Builder.sources] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun sources(sources: JsonField>) = apply { + this.sources = sources.map { it.toMutableList() } + } + + /** + * Adds a single [Source] to [sources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: Source) = apply { + sources = + (sources ?: JsonField.of(mutableListOf())).also { + checkKnown("sources", it).add(source) + } + } + + fun spendType(spendType: SpendType) = spendType(JsonField.of(spendType)) + + /** + * Sets [Builder.spendType] to an arbitrary JSON value. + * + * You should usually call [Builder.spendType] with a well-typed [SpendType] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendType(spendType: JsonField) = apply { + this.spendType = spendType + } + + /** Filter by whether the spend was discounted. Defaults to ANY if omitted. */ + fun discounted(discounted: Discounted) = discounted(JsonField.of(discounted)) + + /** + * Sets [Builder.discounted] to an arbitrary JSON value. + * + * You should usually call [Builder.discounted] with a well-typed [Discounted] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun discounted(discounted: JsonField) = apply { + this.discounted = discounted + } + + 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 [ApplicableSpendSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApplicableSpendSpecifier = + ApplicableSpendSpecifier( + checkRequired("sources", sources).map { it.toImmutable() }, + checkRequired("spendType", spendType), + discounted, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ApplicableSpendSpecifier = apply { + if (validated) { + return@apply + } + + sources().forEach { it.validate() } + spendType().validate() + discounted().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (sources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendType.asKnown().getOrNull()?.validity() ?: 0) + + (discounted.asKnown().getOrNull()?.validity() ?: 0) + + class Source @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 THRESHOLD_RECHARGE = of("THRESHOLD_RECHARGE") + + @JvmField val MANUAL = of("MANUAL") + + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) + } + + /** An enum containing [Source]'s known values. */ + enum class Known { + THRESHOLD_RECHARGE, + MANUAL, + } + + /** + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Source] 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 { + THRESHOLD_RECHARGE, + MANUAL, + /** + * An enum member indicating that [Source] 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) { + THRESHOLD_RECHARGE -> Value.THRESHOLD_RECHARGE + MANUAL -> Value.MANUAL + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + THRESHOLD_RECHARGE -> Known.THRESHOLD_RECHARGE + MANUAL -> Known.MANUAL + else -> throw MetronomeInvalidDataException("Unknown Source: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Source && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SpendType @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 COMMIT_PURCHASE = of("COMMIT_PURCHASE") + + @JvmStatic fun of(value: String) = SpendType(JsonField.of(value)) + } + + /** An enum containing [SpendType]'s known values. */ + enum class Known { + COMMIT_PURCHASE + } + + /** + * An enum containing [SpendType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SpendType] 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 { + COMMIT_PURCHASE, + /** + * An enum member indicating that [SpendType] 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) { + COMMIT_PURCHASE -> Value.COMMIT_PURCHASE + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + COMMIT_PURCHASE -> Known.COMMIT_PURCHASE + else -> throw MetronomeInvalidDataException("Unknown SpendType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): SpendType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 SpendType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Filter by whether the spend was discounted. Defaults to ANY if omitted. */ + class Discounted + @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 ANY = of("ANY") + + @JvmField val DISCOUNTED_ONLY = of("DISCOUNTED_ONLY") + + @JvmField val UNDISCOUNTED_ONLY = of("UNDISCOUNTED_ONLY") + + @JvmStatic fun of(value: String) = Discounted(JsonField.of(value)) + } + + /** An enum containing [Discounted]'s known values. */ + enum class Known { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + } + + /** + * An enum containing [Discounted]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Discounted] 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 { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + /** + * An enum member indicating that [Discounted] 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) { + ANY -> Value.ANY + DISCOUNTED_ONLY -> Value.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Value.UNDISCOUNTED_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANY -> Known.ANY + DISCOUNTED_ONLY -> Known.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Known.UNDISCOUNTED_ONLY + else -> throw MetronomeInvalidDataException("Unknown Discounted: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Discounted = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Discounted && 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 ApplicableSpendSpecifier && + sources == other.sources && + spendType == other.spendType && + discounted == other.discounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(sources, spendType, discounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ApplicableSpendSpecifier{sources=$sources, spendType=$spendType, discounted=$discounted, additionalProperties=$additionalProperties}" + } + + class ResetFrequency + @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 BILLING_PERIOD = of("BILLING_PERIOD") + + @JvmStatic fun of(value: String) = ResetFrequency(JsonField.of(value)) + } + + /** An enum containing [ResetFrequency]'s known values. */ + enum class Known { + BILLING_PERIOD + } + + /** + * An enum containing [ResetFrequency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ResetFrequency] 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 { + BILLING_PERIOD, + /** + * An enum member indicating that [ResetFrequency] 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) { + BILLING_PERIOD -> Value.BILLING_PERIOD + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + BILLING_PERIOD -> Known.BILLING_PERIOD + else -> throw MetronomeInvalidDataException("Unknown ResetFrequency: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ResetFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ResetFrequency && 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 SpendTracker && + alias == other.alias && + applicableSpendSpecifiers == other.applicableSpendSpecifiers && + creditTypeId == other.creditTypeId && + resetFrequency == other.resetFrequency && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTracker{alias=$alias, applicableSpendSpecifiers=$applicableSpendSpecifiers, creditTypeId=$creditTypeId, resetFrequency=$resetFrequency, additionalProperties=$additionalProperties}" + } + class Subscription @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractCreateResponse.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractCreateResponse.kt index 65495007..7c770072 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractCreateResponse.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/contracts/ContractCreateResponse.kt @@ -6,41 +6,56 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.metronome.api.core.Enum import com.metronome.api.core.ExcludeMissing import com.metronome.api.core.JsonField import com.metronome.api.core.JsonMissing import com.metronome.api.core.JsonValue +import com.metronome.api.core.checkKnown import com.metronome.api.core.checkRequired +import com.metronome.api.core.toImmutable import com.metronome.api.errors.MetronomeInvalidDataException -import com.metronome.api.models.Id +import com.metronome.api.models.Commit +import com.metronome.api.models.CommitHierarchyConfiguration +import com.metronome.api.models.CommitSpecifier +import com.metronome.api.models.Credit +import com.metronome.api.models.HierarchyConfiguration +import com.metronome.api.models.Override +import com.metronome.api.models.PrepaidBalanceThresholdConfiguration +import com.metronome.api.models.RecurringCommitSubscriptionConfig +import com.metronome.api.models.ScheduledCharge +import com.metronome.api.models.SpendThresholdConfiguration +import com.metronome.api.models.Subscription +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class ContractCreateResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val data: JsonField, + private val data: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of() + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of() ) : this(data, mutableMapOf()) /** * @throws MetronomeInvalidDataException 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 data(): Id = data.getRequired("data") + fun data(): Data = data.getRequired("data") /** * 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 + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -70,7 +85,7 @@ private constructor( /** A builder for [ContractCreateResponse]. */ class Builder internal constructor() { - private var data: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -79,15 +94,15 @@ private constructor( additionalProperties = contractCreateResponse.additionalProperties.toMutableMap() } - fun data(data: Id) = data(JsonField.of(data)) + fun data(data: Data) = data(JsonField.of(data)) /** * Sets [Builder.data] to an arbitrary JSON value. * - * You should usually call [Builder.data] with a well-typed [Id] value instead. This method - * is primarily for setting the field to an undocumented or not yet supported 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 data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -158,6 +173,9710 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = (data.asKnown().getOrNull()?.validity() ?: 0) + class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val contract: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("contract") + @ExcludeMissing + contract: JsonField = JsonMissing.of(), + ) : this(id, contract, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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") + + /** + * The created contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun contract(): Optional = contract.getOptional("contract") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [contract]. + * + * Unlike [contract], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("contract") @ExcludeMissing fun _contract(): JsonField = contract + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Data]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var contract: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + id = data.id + contract = data.contract + additionalProperties = data.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** The created contract. */ + fun contract(contract: Contract) = contract(JsonField.of(contract)) + + /** + * Sets [Builder.contract] to an arbitrary JSON value. + * + * You should usually call [Builder.contract] with a well-typed [Contract] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun contract(contract: JsonField) = apply { this.contract = contract } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Data = + Data(checkRequired("id", id), contract, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Data = apply { + if (validated) { + return@apply + } + + id() + contract().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (contract.asKnown().getOrNull()?.validity() ?: 0) + + /** The created contract. */ + class Contract + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val commits: JsonField>, + private val createdAt: JsonField, + private val createdBy: JsonField, + private val customerId: JsonField, + private val overrides: JsonField>, + private val scheduledCharges: JsonField>, + private val startingAt: JsonField, + private val transitions: JsonField>, + private val usageFilter: JsonField>, + private val usageStatementSchedule: JsonField, + private val credits: JsonField>, + private val customFields: JsonField, + private val customerBillingProviderConfiguration: + JsonField, + private val endingBefore: JsonField, + private val hasMore: JsonField, + private val hierarchyConfiguration: JsonField, + private val multiplierOverridePrioritization: + JsonField, + private val name: JsonField, + private val netPaymentTermsDays: JsonField, + private val packageId: JsonField, + private val prepaidBalanceThresholdConfiguration: + JsonField, + private val rateCardId: JsonField, + private val recurringCommits: JsonField>, + private val recurringCredits: JsonField>, + private val scheduledChargesOnUsageInvoices: JsonField, + private val spendThresholdConfiguration: JsonField, + private val subscriptions: JsonField>, + private val uniquenessKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("commits") + @ExcludeMissing + commits: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("created_by") + @ExcludeMissing + createdBy: JsonField = JsonMissing.of(), + @JsonProperty("customer_id") + @ExcludeMissing + customerId: JsonField = JsonMissing.of(), + @JsonProperty("overrides") + @ExcludeMissing + overrides: JsonField> = JsonMissing.of(), + @JsonProperty("scheduled_charges") + @ExcludeMissing + scheduledCharges: JsonField> = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("transitions") + @ExcludeMissing + transitions: JsonField> = JsonMissing.of(), + @JsonProperty("usage_filter") + @ExcludeMissing + usageFilter: JsonField> = JsonMissing.of(), + @JsonProperty("usage_statement_schedule") + @ExcludeMissing + usageStatementSchedule: JsonField = JsonMissing.of(), + @JsonProperty("credits") + @ExcludeMissing + credits: JsonField> = JsonMissing.of(), + @JsonProperty("custom_fields") + @ExcludeMissing + customFields: JsonField = JsonMissing.of(), + @JsonProperty("customer_billing_provider_configuration") + @ExcludeMissing + customerBillingProviderConfiguration: + JsonField = + JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("has_more") + @ExcludeMissing + hasMore: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("multiplier_override_prioritization") + @ExcludeMissing + multiplierOverridePrioritization: JsonField = + JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("net_payment_terms_days") + @ExcludeMissing + netPaymentTermsDays: JsonField = JsonMissing.of(), + @JsonProperty("package_id") + @ExcludeMissing + packageId: JsonField = JsonMissing.of(), + @JsonProperty("prepaid_balance_threshold_configuration") + @ExcludeMissing + prepaidBalanceThresholdConfiguration: + JsonField = + JsonMissing.of(), + @JsonProperty("rate_card_id") + @ExcludeMissing + rateCardId: JsonField = JsonMissing.of(), + @JsonProperty("recurring_commits") + @ExcludeMissing + recurringCommits: JsonField> = JsonMissing.of(), + @JsonProperty("recurring_credits") + @ExcludeMissing + recurringCredits: JsonField> = JsonMissing.of(), + @JsonProperty("scheduled_charges_on_usage_invoices") + @ExcludeMissing + scheduledChargesOnUsageInvoices: JsonField = + JsonMissing.of(), + @JsonProperty("spend_threshold_configuration") + @ExcludeMissing + spendThresholdConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("subscriptions") + @ExcludeMissing + subscriptions: JsonField> = JsonMissing.of(), + @JsonProperty("uniqueness_key") + @ExcludeMissing + uniquenessKey: JsonField = JsonMissing.of(), + ) : this( + id, + commits, + createdAt, + createdBy, + customerId, + overrides, + scheduledCharges, + startingAt, + transitions, + usageFilter, + usageStatementSchedule, + credits, + customFields, + customerBillingProviderConfiguration, + endingBefore, + hasMore, + hierarchyConfiguration, + multiplierOverridePrioritization, + name, + netPaymentTermsDays, + packageId, + prepaidBalanceThresholdConfiguration, + rateCardId, + recurringCommits, + recurringCredits, + scheduledChargesOnUsageInvoices, + spendThresholdConfiguration, + subscriptions, + uniquenessKey, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException 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 commits(): List = commits.getRequired("commits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("created_at") + + /** + * @throws MetronomeInvalidDataException 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 createdBy(): String = createdBy.getRequired("created_by") + + /** + * @throws MetronomeInvalidDataException 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 customerId(): String = customerId.getRequired("customer_id") + + /** + * @throws MetronomeInvalidDataException 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 overrides(): List = overrides.getRequired("overrides") + + /** + * @throws MetronomeInvalidDataException 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 scheduledCharges(): List = + scheduledCharges.getRequired("scheduled_charges") + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * @throws MetronomeInvalidDataException 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 transitions(): List = transitions.getRequired("transitions") + + /** + * @throws MetronomeInvalidDataException 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 usageFilter(): List = usageFilter.getRequired("usage_filter") + + /** + * @throws MetronomeInvalidDataException 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 usageStatementSchedule(): UsageStatementSchedule = + usageStatementSchedule.getRequired("usage_statement_schedule") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun credits(): Optional> = credits.getOptional("credits") + + /** + * Custom fields to be added eg. { "key1": "value1", "key2": "value2" } + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun customFields(): Optional = customFields.getOptional("custom_fields") + + /** + * The billing provider configuration associated with the contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun customerBillingProviderConfiguration(): + Optional = + customerBillingProviderConfiguration.getOptional( + "customer_billing_provider_configuration" + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = endingBefore.getOptional("ending_before") + + /** + * Indicates whether there are more items than the limit for this endpoint. Use the + * respective list endpoints to get the full lists. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun hasMore(): Optional = hasMore.getOptional("has_more") + + /** + * Either a **parent** configuration with a list of children or a **child** + * configuration with a single parent. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * Defaults to LOWEST_MULTIPLIER, which applies the greatest discount to list prices + * automatically. EXPLICIT prioritization requires specifying priorities for each + * multiplier; the one with the lowest priority value will be prioritized first. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun multiplierOverridePrioritization(): Optional = + multiplierOverridePrioritization.getOptional("multiplier_override_prioritization") + + /** + * @throws MetronomeInvalidDataException 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 MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun netPaymentTermsDays(): Optional = + netPaymentTermsDays.getOptional("net_payment_terms_days") + + /** + * ID of the package this contract was created from, if applicable. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun packageId(): Optional = packageId.getOptional("package_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun prepaidBalanceThresholdConfiguration(): + Optional = + prepaidBalanceThresholdConfiguration.getOptional( + "prepaid_balance_threshold_configuration" + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun rateCardId(): Optional = rateCardId.getOptional("rate_card_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun recurringCommits(): Optional> = + recurringCommits.getOptional("recurring_commits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun recurringCredits(): Optional> = + recurringCredits.getOptional("recurring_credits") + + /** + * Determines which scheduled and commit charges to consolidate onto the Contract's + * usage invoice. The charge's `timestamp` must match the usage invoice's + * `ending_before` date for consolidation to occur. This field cannot be modified after + * a Contract has been created. If this field is omitted, charges will appear on a + * separate invoice from usage charges. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun scheduledChargesOnUsageInvoices(): Optional = + scheduledChargesOnUsageInvoices.getOptional("scheduled_charges_on_usage_invoices") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun spendThresholdConfiguration(): Optional = + spendThresholdConfiguration.getOptional("spend_threshold_configuration") + + /** + * List of subscriptions on the contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun subscriptions(): Optional> = + subscriptions.getOptional("subscriptions") + + /** + * Optional uniqueness key to prevent duplicate contract creations. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun uniquenessKey(): Optional = uniquenessKey.getOptional("uniqueness_key") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [commits]. + * + * Unlike [commits], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("commits") + @ExcludeMissing + fun _commits(): JsonField> = commits + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [createdBy]. + * + * Unlike [createdBy], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("created_by") + @ExcludeMissing + fun _createdBy(): JsonField = createdBy + + /** + * Returns the raw JSON value of [customerId]. + * + * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("customer_id") + @ExcludeMissing + fun _customerId(): JsonField = customerId + + /** + * Returns the raw JSON value of [overrides]. + * + * Unlike [overrides], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("overrides") + @ExcludeMissing + fun _overrides(): JsonField> = overrides + + /** + * Returns the raw JSON value of [scheduledCharges]. + * + * Unlike [scheduledCharges], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("scheduled_charges") + @ExcludeMissing + fun _scheduledCharges(): JsonField> = scheduledCharges + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [transitions]. + * + * Unlike [transitions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("transitions") + @ExcludeMissing + fun _transitions(): JsonField> = transitions + + /** + * Returns the raw JSON value of [usageFilter]. + * + * Unlike [usageFilter], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("usage_filter") + @ExcludeMissing + fun _usageFilter(): JsonField> = usageFilter + + /** + * Returns the raw JSON value of [usageStatementSchedule]. + * + * Unlike [usageStatementSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usage_statement_schedule") + @ExcludeMissing + fun _usageStatementSchedule(): JsonField = + usageStatementSchedule + + /** + * Returns the raw JSON value of [credits]. + * + * Unlike [credits], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credits") + @ExcludeMissing + fun _credits(): JsonField> = credits + + /** + * Returns the raw JSON value of [customFields]. + * + * Unlike [customFields], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("custom_fields") + @ExcludeMissing + fun _customFields(): JsonField = customFields + + /** + * Returns the raw JSON value of [customerBillingProviderConfiguration]. + * + * Unlike [customerBillingProviderConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("customer_billing_provider_configuration") + @ExcludeMissing + fun _customerBillingProviderConfiguration(): + JsonField = + customerBillingProviderConfiguration + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * Returns the raw JSON value of [multiplierOverridePrioritization]. + * + * Unlike [multiplierOverridePrioritization], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("multiplier_override_prioritization") + @ExcludeMissing + fun _multiplierOverridePrioritization(): JsonField = + multiplierOverridePrioritization + + /** + * 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 [netPaymentTermsDays]. + * + * Unlike [netPaymentTermsDays], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("net_payment_terms_days") + @ExcludeMissing + fun _netPaymentTermsDays(): JsonField = netPaymentTermsDays + + /** + * Returns the raw JSON value of [packageId]. + * + * Unlike [packageId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_id") + @ExcludeMissing + fun _packageId(): JsonField = packageId + + /** + * Returns the raw JSON value of [prepaidBalanceThresholdConfiguration]. + * + * Unlike [prepaidBalanceThresholdConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("prepaid_balance_threshold_configuration") + @ExcludeMissing + fun _prepaidBalanceThresholdConfiguration(): + JsonField = + prepaidBalanceThresholdConfiguration + + /** + * Returns the raw JSON value of [rateCardId]. + * + * Unlike [rateCardId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_card_id") + @ExcludeMissing + fun _rateCardId(): JsonField = rateCardId + + /** + * Returns the raw JSON value of [recurringCommits]. + * + * Unlike [recurringCommits], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("recurring_commits") + @ExcludeMissing + fun _recurringCommits(): JsonField> = recurringCommits + + /** + * Returns the raw JSON value of [recurringCredits]. + * + * Unlike [recurringCredits], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("recurring_credits") + @ExcludeMissing + fun _recurringCredits(): JsonField> = recurringCredits + + /** + * Returns the raw JSON value of [scheduledChargesOnUsageInvoices]. + * + * Unlike [scheduledChargesOnUsageInvoices], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("scheduled_charges_on_usage_invoices") + @ExcludeMissing + fun _scheduledChargesOnUsageInvoices(): JsonField = + scheduledChargesOnUsageInvoices + + /** + * Returns the raw JSON value of [spendThresholdConfiguration]. + * + * Unlike [spendThresholdConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("spend_threshold_configuration") + @ExcludeMissing + fun _spendThresholdConfiguration(): JsonField = + spendThresholdConfiguration + + /** + * Returns the raw JSON value of [subscriptions]. + * + * Unlike [subscriptions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subscriptions") + @ExcludeMissing + fun _subscriptions(): JsonField> = subscriptions + + /** + * Returns the raw JSON value of [uniquenessKey]. + * + * Unlike [uniquenessKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("uniqueness_key") + @ExcludeMissing + fun _uniquenessKey(): JsonField = uniquenessKey + + @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 [Contract]. + * + * The following fields are required: + * ```java + * .id() + * .commits() + * .createdAt() + * .createdBy() + * .customerId() + * .overrides() + * .scheduledCharges() + * .startingAt() + * .transitions() + * .usageFilter() + * .usageStatementSchedule() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Contract]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var commits: JsonField>? = null + private var createdAt: JsonField? = null + private var createdBy: JsonField? = null + private var customerId: JsonField? = null + private var overrides: JsonField>? = null + private var scheduledCharges: JsonField>? = null + private var startingAt: JsonField? = null + private var transitions: JsonField>? = null + private var usageFilter: JsonField>? = null + private var usageStatementSchedule: JsonField? = null + private var credits: JsonField>? = null + private var customFields: JsonField = JsonMissing.of() + private var customerBillingProviderConfiguration: + JsonField = + JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var hasMore: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var multiplierOverridePrioritization: + JsonField = + JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netPaymentTermsDays: JsonField = JsonMissing.of() + private var packageId: JsonField = JsonMissing.of() + private var prepaidBalanceThresholdConfiguration: + JsonField = + JsonMissing.of() + private var rateCardId: JsonField = JsonMissing.of() + private var recurringCommits: JsonField>? = null + private var recurringCredits: JsonField>? = null + private var scheduledChargesOnUsageInvoices: + JsonField = + JsonMissing.of() + private var spendThresholdConfiguration: JsonField = + JsonMissing.of() + private var subscriptions: JsonField>? = null + private var uniquenessKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(contract: Contract) = apply { + id = contract.id + commits = contract.commits.map { it.toMutableList() } + createdAt = contract.createdAt + createdBy = contract.createdBy + customerId = contract.customerId + overrides = contract.overrides.map { it.toMutableList() } + scheduledCharges = contract.scheduledCharges.map { it.toMutableList() } + startingAt = contract.startingAt + transitions = contract.transitions.map { it.toMutableList() } + usageFilter = contract.usageFilter.map { it.toMutableList() } + usageStatementSchedule = contract.usageStatementSchedule + credits = contract.credits.map { it.toMutableList() } + customFields = contract.customFields + customerBillingProviderConfiguration = + contract.customerBillingProviderConfiguration + endingBefore = contract.endingBefore + hasMore = contract.hasMore + hierarchyConfiguration = contract.hierarchyConfiguration + multiplierOverridePrioritization = contract.multiplierOverridePrioritization + name = contract.name + netPaymentTermsDays = contract.netPaymentTermsDays + packageId = contract.packageId + prepaidBalanceThresholdConfiguration = + contract.prepaidBalanceThresholdConfiguration + rateCardId = contract.rateCardId + recurringCommits = contract.recurringCommits.map { it.toMutableList() } + recurringCredits = contract.recurringCredits.map { it.toMutableList() } + scheduledChargesOnUsageInvoices = contract.scheduledChargesOnUsageInvoices + spendThresholdConfiguration = contract.spendThresholdConfiguration + subscriptions = contract.subscriptions.map { it.toMutableList() } + uniquenessKey = contract.uniquenessKey + additionalProperties = contract.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 commits(commits: List) = commits(JsonField.of(commits)) + + /** + * Sets [Builder.commits] to an arbitrary JSON value. + * + * You should usually call [Builder.commits] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun commits(commits: JsonField>) = apply { + this.commits = commits.map { it.toMutableList() } + } + + /** + * Adds a single [Commit] to [commits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCommit(commit: Commit) = apply { + commits = + (commits ?: JsonField.of(mutableListOf())).also { + checkKnown("commits", it).add(commit) + } + } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun createdBy(createdBy: String) = createdBy(JsonField.of(createdBy)) + + /** + * Sets [Builder.createdBy] to an arbitrary JSON value. + * + * You should usually call [Builder.createdBy] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun createdBy(createdBy: JsonField) = apply { this.createdBy = createdBy } + + fun customerId(customerId: String) = customerId(JsonField.of(customerId)) + + /** + * Sets [Builder.customerId] to an arbitrary JSON value. + * + * You should usually call [Builder.customerId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun customerId(customerId: JsonField) = apply { + this.customerId = customerId + } + + fun overrides(overrides: List) = overrides(JsonField.of(overrides)) + + /** + * Sets [Builder.overrides] to an arbitrary JSON value. + * + * You should usually call [Builder.overrides] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun overrides(overrides: JsonField>) = apply { + this.overrides = overrides.map { it.toMutableList() } + } + + /** + * Adds a single [Override] to [overrides]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addOverride(override: Override) = apply { + overrides = + (overrides ?: JsonField.of(mutableListOf())).also { + checkKnown("overrides", it).add(override) + } + } + + fun scheduledCharges(scheduledCharges: List) = + scheduledCharges(JsonField.of(scheduledCharges)) + + /** + * Sets [Builder.scheduledCharges] to an arbitrary JSON value. + * + * You should usually call [Builder.scheduledCharges] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun scheduledCharges(scheduledCharges: JsonField>) = apply { + this.scheduledCharges = scheduledCharges.map { it.toMutableList() } + } + + /** + * Adds a single [ScheduledCharge] to [scheduledCharges]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addScheduledCharge(scheduledCharge: ScheduledCharge) = apply { + scheduledCharges = + (scheduledCharges ?: JsonField.of(mutableListOf())).also { + checkKnown("scheduledCharges", it).add(scheduledCharge) + } + } + + fun startingAt(startingAt: OffsetDateTime) = startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + fun transitions(transitions: List) = + transitions(JsonField.of(transitions)) + + /** + * Sets [Builder.transitions] to an arbitrary JSON value. + * + * You should usually call [Builder.transitions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun transitions(transitions: JsonField>) = apply { + this.transitions = transitions.map { it.toMutableList() } + } + + /** + * Adds a single [Transition] to [transitions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTransition(transition: Transition) = apply { + transitions = + (transitions ?: JsonField.of(mutableListOf())).also { + checkKnown("transitions", it).add(transition) + } + } + + fun usageFilter(usageFilter: List) = + usageFilter(JsonField.of(usageFilter)) + + /** + * Sets [Builder.usageFilter] to an arbitrary JSON value. + * + * You should usually call [Builder.usageFilter] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun usageFilter(usageFilter: JsonField>) = apply { + this.usageFilter = usageFilter.map { it.toMutableList() } + } + + /** + * Adds a single [UsageFilter] to [Builder.usageFilter]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUsageFilter(usageFilter: UsageFilter) = apply { + this.usageFilter = + (this.usageFilter ?: JsonField.of(mutableListOf())).also { + checkKnown("usageFilter", it).add(usageFilter) + } + } + + fun usageStatementSchedule(usageStatementSchedule: UsageStatementSchedule) = + usageStatementSchedule(JsonField.of(usageStatementSchedule)) + + /** + * Sets [Builder.usageStatementSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.usageStatementSchedule] with a well-typed + * [UsageStatementSchedule] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun usageStatementSchedule( + usageStatementSchedule: JsonField + ) = apply { this.usageStatementSchedule = usageStatementSchedule } + + fun credits(credits: List) = credits(JsonField.of(credits)) + + /** + * Sets [Builder.credits] to an arbitrary JSON value. + * + * You should usually call [Builder.credits] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun credits(credits: JsonField>) = apply { + this.credits = credits.map { it.toMutableList() } + } + + /** + * Adds a single [Credit] to [credits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCredit(credit: Credit) = apply { + credits = + (credits ?: JsonField.of(mutableListOf())).also { + checkKnown("credits", it).add(credit) + } + } + + /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ + fun customFields(customFields: CustomFields) = + customFields(JsonField.of(customFields)) + + /** + * Sets [Builder.customFields] to an arbitrary JSON value. + * + * You should usually call [Builder.customFields] with a well-typed [CustomFields] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun customFields(customFields: JsonField) = apply { + this.customFields = customFields + } + + /** The billing provider configuration associated with the contract. */ + fun customerBillingProviderConfiguration( + customerBillingProviderConfiguration: CustomerBillingProviderConfiguration + ) = + customerBillingProviderConfiguration( + JsonField.of(customerBillingProviderConfiguration) + ) + + /** + * Sets [Builder.customerBillingProviderConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.customerBillingProviderConfiguration] with a + * well-typed [CustomerBillingProviderConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun customerBillingProviderConfiguration( + customerBillingProviderConfiguration: + JsonField + ) = apply { + this.customerBillingProviderConfiguration = customerBillingProviderConfiguration + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** + * Indicates whether there are more items than the limit for this endpoint. Use the + * respective list endpoints to get the full lists. + */ + fun hasMore(hasMore: HasMore) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [HasMore] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** + * Either a **parent** configuration with a list of children or a **child** + * configuration with a single parent. + */ + fun hierarchyConfiguration(hierarchyConfiguration: HierarchyConfiguration) = + hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [HierarchyConfiguration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + /** + * Alias for calling [hierarchyConfiguration] with + * `HierarchyConfiguration.ofParent(parent)`. + */ + fun hierarchyConfiguration( + parent: HierarchyConfiguration.ParentHierarchyConfiguration + ) = hierarchyConfiguration(HierarchyConfiguration.ofParent(parent)) + + /** + * Alias for calling [hierarchyConfiguration] with + * `HierarchyConfiguration.ofChild(child)`. + */ + fun hierarchyConfiguration( + child: HierarchyConfiguration.ChildHierarchyConfiguration + ) = hierarchyConfiguration(HierarchyConfiguration.ofChild(child)) + + /** + * Defaults to LOWEST_MULTIPLIER, which applies the greatest discount to list prices + * automatically. EXPLICIT prioritization requires specifying priorities for each + * multiplier; the one with the lowest priority value will be prioritized first. + */ + fun multiplierOverridePrioritization( + multiplierOverridePrioritization: MultiplierOverridePrioritization + ) = multiplierOverridePrioritization(JsonField.of(multiplierOverridePrioritization)) + + /** + * Sets [Builder.multiplierOverridePrioritization] to an arbitrary JSON value. + * + * You should usually call [Builder.multiplierOverridePrioritization] with a + * well-typed [MultiplierOverridePrioritization] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun multiplierOverridePrioritization( + multiplierOverridePrioritization: JsonField + ) = apply { + this.multiplierOverridePrioritization = multiplierOverridePrioritization + } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun netPaymentTermsDays(netPaymentTermsDays: Double) = + netPaymentTermsDays(JsonField.of(netPaymentTermsDays)) + + /** + * Sets [Builder.netPaymentTermsDays] to an arbitrary JSON value. + * + * You should usually call [Builder.netPaymentTermsDays] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun netPaymentTermsDays(netPaymentTermsDays: JsonField) = apply { + this.netPaymentTermsDays = netPaymentTermsDays + } + + /** ID of the package this contract was created from, if applicable. */ + fun packageId(packageId: String) = packageId(JsonField.of(packageId)) + + /** + * Sets [Builder.packageId] to an arbitrary JSON value. + * + * You should usually call [Builder.packageId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun packageId(packageId: JsonField) = apply { this.packageId = packageId } + + fun prepaidBalanceThresholdConfiguration( + prepaidBalanceThresholdConfiguration: PrepaidBalanceThresholdConfiguration + ) = + prepaidBalanceThresholdConfiguration( + JsonField.of(prepaidBalanceThresholdConfiguration) + ) + + /** + * Sets [Builder.prepaidBalanceThresholdConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.prepaidBalanceThresholdConfiguration] with a + * well-typed [PrepaidBalanceThresholdConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun prepaidBalanceThresholdConfiguration( + prepaidBalanceThresholdConfiguration: + JsonField + ) = apply { + this.prepaidBalanceThresholdConfiguration = prepaidBalanceThresholdConfiguration + } + + fun rateCardId(rateCardId: String) = rateCardId(JsonField.of(rateCardId)) + + /** + * Sets [Builder.rateCardId] to an arbitrary JSON value. + * + * You should usually call [Builder.rateCardId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun rateCardId(rateCardId: JsonField) = apply { + this.rateCardId = rateCardId + } + + fun recurringCommits(recurringCommits: List) = + recurringCommits(JsonField.of(recurringCommits)) + + /** + * Sets [Builder.recurringCommits] to an arbitrary JSON value. + * + * You should usually call [Builder.recurringCommits] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun recurringCommits(recurringCommits: JsonField>) = apply { + this.recurringCommits = recurringCommits.map { it.toMutableList() } + } + + /** + * Adds a single [RecurringCommit] to [recurringCommits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRecurringCommit(recurringCommit: RecurringCommit) = apply { + recurringCommits = + (recurringCommits ?: JsonField.of(mutableListOf())).also { + checkKnown("recurringCommits", it).add(recurringCommit) + } + } + + fun recurringCredits(recurringCredits: List) = + recurringCredits(JsonField.of(recurringCredits)) + + /** + * Sets [Builder.recurringCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.recurringCredits] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun recurringCredits(recurringCredits: JsonField>) = apply { + this.recurringCredits = recurringCredits.map { it.toMutableList() } + } + + /** + * Adds a single [RecurringCredit] to [recurringCredits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRecurringCredit(recurringCredit: RecurringCredit) = apply { + recurringCredits = + (recurringCredits ?: JsonField.of(mutableListOf())).also { + checkKnown("recurringCredits", it).add(recurringCredit) + } + } + + /** + * Determines which scheduled and commit charges to consolidate onto the Contract's + * usage invoice. The charge's `timestamp` must match the usage invoice's + * `ending_before` date for consolidation to occur. This field cannot be modified + * after a Contract has been created. If this field is omitted, charges will appear + * on a separate invoice from usage charges. + */ + fun scheduledChargesOnUsageInvoices( + scheduledChargesOnUsageInvoices: ScheduledChargesOnUsageInvoices + ) = scheduledChargesOnUsageInvoices(JsonField.of(scheduledChargesOnUsageInvoices)) + + /** + * Sets [Builder.scheduledChargesOnUsageInvoices] to an arbitrary JSON value. + * + * You should usually call [Builder.scheduledChargesOnUsageInvoices] with a + * well-typed [ScheduledChargesOnUsageInvoices] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun scheduledChargesOnUsageInvoices( + scheduledChargesOnUsageInvoices: JsonField + ) = apply { this.scheduledChargesOnUsageInvoices = scheduledChargesOnUsageInvoices } + + fun spendThresholdConfiguration( + spendThresholdConfiguration: SpendThresholdConfiguration + ) = spendThresholdConfiguration(JsonField.of(spendThresholdConfiguration)) + + /** + * Sets [Builder.spendThresholdConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.spendThresholdConfiguration] with a well-typed + * [SpendThresholdConfiguration] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun spendThresholdConfiguration( + spendThresholdConfiguration: JsonField + ) = apply { this.spendThresholdConfiguration = spendThresholdConfiguration } + + /** List of subscriptions on the contract. */ + fun subscriptions(subscriptions: List) = + subscriptions(JsonField.of(subscriptions)) + + /** + * Sets [Builder.subscriptions] to an arbitrary JSON value. + * + * You should usually call [Builder.subscriptions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun subscriptions(subscriptions: JsonField>) = apply { + this.subscriptions = subscriptions.map { it.toMutableList() } + } + + /** + * Adds a single [Subscription] to [subscriptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSubscription(subscription: Subscription) = apply { + subscriptions = + (subscriptions ?: JsonField.of(mutableListOf())).also { + checkKnown("subscriptions", it).add(subscription) + } + } + + /** Optional uniqueness key to prevent duplicate contract creations. */ + fun uniquenessKey(uniquenessKey: String) = + uniquenessKey(JsonField.of(uniquenessKey)) + + /** + * Sets [Builder.uniquenessKey] to an arbitrary JSON value. + * + * You should usually call [Builder.uniquenessKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun uniquenessKey(uniquenessKey: JsonField) = apply { + this.uniquenessKey = uniquenessKey + } + + 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 [Contract]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .commits() + * .createdAt() + * .createdBy() + * .customerId() + * .overrides() + * .scheduledCharges() + * .startingAt() + * .transitions() + * .usageFilter() + * .usageStatementSchedule() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Contract = + Contract( + checkRequired("id", id), + checkRequired("commits", commits).map { it.toImmutable() }, + checkRequired("createdAt", createdAt), + checkRequired("createdBy", createdBy), + checkRequired("customerId", customerId), + checkRequired("overrides", overrides).map { it.toImmutable() }, + checkRequired("scheduledCharges", scheduledCharges).map { + it.toImmutable() + }, + checkRequired("startingAt", startingAt), + checkRequired("transitions", transitions).map { it.toImmutable() }, + checkRequired("usageFilter", usageFilter).map { it.toImmutable() }, + checkRequired("usageStatementSchedule", usageStatementSchedule), + (credits ?: JsonMissing.of()).map { it.toImmutable() }, + customFields, + customerBillingProviderConfiguration, + endingBefore, + hasMore, + hierarchyConfiguration, + multiplierOverridePrioritization, + name, + netPaymentTermsDays, + packageId, + prepaidBalanceThresholdConfiguration, + rateCardId, + (recurringCommits ?: JsonMissing.of()).map { it.toImmutable() }, + (recurringCredits ?: JsonMissing.of()).map { it.toImmutable() }, + scheduledChargesOnUsageInvoices, + spendThresholdConfiguration, + (subscriptions ?: JsonMissing.of()).map { it.toImmutable() }, + uniquenessKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Contract = apply { + if (validated) { + return@apply + } + + id() + commits().forEach { it.validate() } + createdAt() + createdBy() + customerId() + overrides().forEach { it.validate() } + scheduledCharges().forEach { it.validate() } + startingAt() + transitions().forEach { it.validate() } + usageFilter().forEach { it.validate() } + usageStatementSchedule().validate() + credits().ifPresent { it.forEach { it.validate() } } + customFields().ifPresent { it.validate() } + customerBillingProviderConfiguration().ifPresent { it.validate() } + endingBefore() + hasMore().ifPresent { it.validate() } + hierarchyConfiguration().ifPresent { it.validate() } + multiplierOverridePrioritization().ifPresent { it.validate() } + name() + netPaymentTermsDays() + packageId() + prepaidBalanceThresholdConfiguration().ifPresent { it.validate() } + rateCardId() + recurringCommits().ifPresent { it.forEach { it.validate() } } + recurringCredits().ifPresent { it.forEach { it.validate() } } + scheduledChargesOnUsageInvoices().ifPresent { it.validate() } + spendThresholdConfiguration().ifPresent { it.validate() } + subscriptions().ifPresent { it.forEach { it.validate() } } + uniquenessKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (commits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (createdBy.asKnown().isPresent) 1 else 0) + + (if (customerId.asKnown().isPresent) 1 else 0) + + (overrides.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (scheduledCharges.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (transitions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (usageFilter.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (usageStatementSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (credits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (customFields.asKnown().getOrNull()?.validity() ?: 0) + + (customerBillingProviderConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (hasMore.asKnown().getOrNull()?.validity() ?: 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (multiplierOverridePrioritization.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netPaymentTermsDays.asKnown().isPresent) 1 else 0) + + (if (packageId.asKnown().isPresent) 1 else 0) + + (prepaidBalanceThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (rateCardId.asKnown().isPresent) 1 else 0) + + (recurringCommits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (recurringCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (scheduledChargesOnUsageInvoices.asKnown().getOrNull()?.validity() ?: 0) + + (spendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (subscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (uniquenessKey.asKnown().isPresent) 1 else 0) + + class Transition + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val fromContractId: JsonField, + private val toContractId: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("from_contract_id") + @ExcludeMissing + fromContractId: JsonField = JsonMissing.of(), + @JsonProperty("to_contract_id") + @ExcludeMissing + toContractId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(fromContractId, toContractId, type, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 fromContractId(): String = fromContractId.getRequired("from_contract_id") + + /** + * @throws MetronomeInvalidDataException 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 toContractId(): String = toContractId.getRequired("to_contract_id") + + /** + * @throws MetronomeInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [fromContractId]. + * + * Unlike [fromContractId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("from_contract_id") + @ExcludeMissing + fun _fromContractId(): JsonField = fromContractId + + /** + * Returns the raw JSON value of [toContractId]. + * + * Unlike [toContractId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("to_contract_id") + @ExcludeMissing + fun _toContractId(): JsonField = toContractId + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Transition]. + * + * The following fields are required: + * ```java + * .fromContractId() + * .toContractId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Transition]. */ + class Builder internal constructor() { + + private var fromContractId: JsonField? = null + private var toContractId: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(transition: Transition) = apply { + fromContractId = transition.fromContractId + toContractId = transition.toContractId + type = transition.type + additionalProperties = transition.additionalProperties.toMutableMap() + } + + fun fromContractId(fromContractId: String) = + fromContractId(JsonField.of(fromContractId)) + + /** + * Sets [Builder.fromContractId] to an arbitrary JSON value. + * + * You should usually call [Builder.fromContractId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fromContractId(fromContractId: JsonField) = apply { + this.fromContractId = fromContractId + } + + fun toContractId(toContractId: String) = + toContractId(JsonField.of(toContractId)) + + /** + * Sets [Builder.toContractId] to an arbitrary JSON value. + * + * You should usually call [Builder.toContractId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun toContractId(toContractId: JsonField) = apply { + this.toContractId = toContractId + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Transition]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fromContractId() + * .toContractId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Transition = + Transition( + checkRequired("fromContractId", fromContractId), + checkRequired("toContractId", toContractId), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Transition = apply { + if (validated) { + return@apply + } + + fromContractId() + toContractId() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (fromContractId.asKnown().isPresent) 1 else 0) + + (if (toContractId.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val SUPERSEDE = of("SUPERSEDE") + + @JvmField val RENEWAL = of("RENEWAL") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SUPERSEDE, + RENEWAL, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + SUPERSEDE, + RENEWAL, + /** + * An enum member indicating that [Type] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + SUPERSEDE -> Value.SUPERSEDE + RENEWAL -> Value.RENEWAL + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + SUPERSEDE -> Known.SUPERSEDE + RENEWAL -> Known.RENEWAL + else -> throw MetronomeInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Transition && + fromContractId == other.fromContractId && + toContractId == other.toContractId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(fromContractId, toContractId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Transition{fromContractId=$fromContractId, toContractId=$toContractId, type=$type, additionalProperties=$additionalProperties}" + } + + class UsageFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupKey: JsonField, + private val groupValues: JsonField>, + private val startingAt: JsonField, + private val endingBefore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("group_key") + @ExcludeMissing + groupKey: JsonField = JsonMissing.of(), + @JsonProperty("group_values") + @ExcludeMissing + groupValues: JsonField> = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + ) : this(groupKey, groupValues, startingAt, endingBefore, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 groupKey(): String = groupKey.getRequired("group_key") + + /** + * @throws MetronomeInvalidDataException 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 groupValues(): List = groupValues.getRequired("group_values") + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * Returns the raw JSON value of [groupKey]. + * + * Unlike [groupKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("group_key") + @ExcludeMissing + fun _groupKey(): JsonField = groupKey + + /** + * Returns the raw JSON value of [groupValues]. + * + * Unlike [groupValues], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_values") + @ExcludeMissing + fun _groupValues(): JsonField> = groupValues + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + @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 [UsageFilter]. + * + * The following fields are required: + * ```java + * .groupKey() + * .groupValues() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UsageFilter]. */ + class Builder internal constructor() { + + private var groupKey: JsonField? = null + private var groupValues: JsonField>? = null + private var startingAt: JsonField? = null + private var endingBefore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usageFilter: UsageFilter) = apply { + groupKey = usageFilter.groupKey + groupValues = usageFilter.groupValues.map { it.toMutableList() } + startingAt = usageFilter.startingAt + endingBefore = usageFilter.endingBefore + additionalProperties = usageFilter.additionalProperties.toMutableMap() + } + + fun groupKey(groupKey: String) = groupKey(JsonField.of(groupKey)) + + /** + * Sets [Builder.groupKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun groupKey(groupKey: JsonField) = apply { this.groupKey = groupKey } + + fun groupValues(groupValues: List) = + groupValues(JsonField.of(groupValues)) + + /** + * Sets [Builder.groupValues] to an arbitrary JSON value. + * + * You should usually call [Builder.groupValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun groupValues(groupValues: JsonField>) = apply { + this.groupValues = groupValues.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [groupValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupValue(groupValue: String) = apply { + groupValues = + (groupValues ?: JsonField.of(mutableListOf())).also { + checkKnown("groupValues", it).add(groupValue) + } + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + 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 [UsageFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .groupKey() + * .groupValues() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UsageFilter = + UsageFilter( + checkRequired("groupKey", groupKey), + checkRequired("groupValues", groupValues).map { it.toImmutable() }, + checkRequired("startingAt", startingAt), + endingBefore, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UsageFilter = apply { + if (validated) { + return@apply + } + + groupKey() + groupValues() + startingAt() + endingBefore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (groupKey.asKnown().isPresent) 1 else 0) + + (groupValues.asKnown().getOrNull()?.size ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UsageFilter && + groupKey == other.groupKey && + groupValues == other.groupValues && + startingAt == other.startingAt && + endingBefore == other.endingBefore && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupKey, + groupValues, + startingAt, + endingBefore, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UsageFilter{groupKey=$groupKey, groupValues=$groupValues, startingAt=$startingAt, endingBefore=$endingBefore, additionalProperties=$additionalProperties}" + } + + class UsageStatementSchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val billingAnchorDate: JsonField, + private val frequency: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("billing_anchor_date") + @ExcludeMissing + billingAnchorDate: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + frequency: JsonField = JsonMissing.of(), + ) : this(billingAnchorDate, frequency, mutableMapOf()) + + /** + * Contract usage statements follow a selected cadence based on this date. + * + * @throws MetronomeInvalidDataException 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 billingAnchorDate(): OffsetDateTime = + billingAnchorDate.getRequired("billing_anchor_date") + + /** + * @throws MetronomeInvalidDataException 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 frequency(): Frequency = frequency.getRequired("frequency") + + /** + * Returns the raw JSON value of [billingAnchorDate]. + * + * Unlike [billingAnchorDate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billing_anchor_date") + @ExcludeMissing + fun _billingAnchorDate(): JsonField = billingAnchorDate + + /** + * Returns the raw JSON value of [frequency]. + * + * Unlike [frequency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + @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 + * [UsageStatementSchedule]. + * + * The following fields are required: + * ```java + * .billingAnchorDate() + * .frequency() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UsageStatementSchedule]. */ + class Builder internal constructor() { + + private var billingAnchorDate: JsonField? = null + private var frequency: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usageStatementSchedule: UsageStatementSchedule) = apply { + billingAnchorDate = usageStatementSchedule.billingAnchorDate + frequency = usageStatementSchedule.frequency + additionalProperties = + usageStatementSchedule.additionalProperties.toMutableMap() + } + + /** Contract usage statements follow a selected cadence based on this date. */ + fun billingAnchorDate(billingAnchorDate: OffsetDateTime) = + billingAnchorDate(JsonField.of(billingAnchorDate)) + + /** + * Sets [Builder.billingAnchorDate] to an arbitrary JSON value. + * + * You should usually call [Builder.billingAnchorDate] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun billingAnchorDate(billingAnchorDate: JsonField) = apply { + this.billingAnchorDate = billingAnchorDate + } + + fun frequency(frequency: Frequency) = frequency(JsonField.of(frequency)) + + /** + * Sets [Builder.frequency] to an arbitrary JSON value. + * + * You should usually call [Builder.frequency] with a well-typed [Frequency] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + 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 [UsageStatementSchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .billingAnchorDate() + * .frequency() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UsageStatementSchedule = + UsageStatementSchedule( + checkRequired("billingAnchorDate", billingAnchorDate), + checkRequired("frequency", frequency), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UsageStatementSchedule = apply { + if (validated) { + return@apply + } + + billingAnchorDate() + frequency().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (billingAnchorDate.asKnown().isPresent) 1 else 0) + + (frequency.asKnown().getOrNull()?.validity() ?: 0) + + class Frequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = Frequency(JsonField.of(value)) + } + + /** An enum containing [Frequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [Frequency]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Frequency] 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 { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [Frequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> throw MetronomeInvalidDataException("Unknown Frequency: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Frequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Frequency && 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 UsageStatementSchedule && + billingAnchorDate == other.billingAnchorDate && + frequency == other.frequency && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(billingAnchorDate, frequency, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UsageStatementSchedule{billingAnchorDate=$billingAnchorDate, frequency=$frequency, additionalProperties=$additionalProperties}" + } + + /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ + class CustomFields + @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 [CustomFields]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFields]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(customFields: CustomFields) = apply { + additionalProperties = customFields.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 [CustomFields]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CustomFields = CustomFields(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): CustomFields = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 CustomFields && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "CustomFields{additionalProperties=$additionalProperties}" + } + + /** The billing provider configuration associated with the contract. */ + class CustomerBillingProviderConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val billingProvider: JsonField, + private val deliveryMethod: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("billing_provider") + @ExcludeMissing + billingProvider: JsonField = JsonMissing.of(), + @JsonProperty("delivery_method") + @ExcludeMissing + deliveryMethod: JsonField = JsonMissing.of(), + ) : this(id, billingProvider, deliveryMethod, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun id(): Optional = id.getOptional("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun billingProvider(): Optional = + billingProvider.getOptional("billing_provider") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun deliveryMethod(): Optional = + deliveryMethod.getOptional("delivery_method") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [billingProvider]. + * + * Unlike [billingProvider], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billing_provider") + @ExcludeMissing + fun _billingProvider(): JsonField = billingProvider + + /** + * Returns the raw JSON value of [deliveryMethod]. + * + * Unlike [deliveryMethod], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("delivery_method") + @ExcludeMissing + fun _deliveryMethod(): JsonField = deliveryMethod + + @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 + * [CustomerBillingProviderConfiguration]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerBillingProviderConfiguration]. */ + class Builder internal constructor() { + + private var id: JsonField = JsonMissing.of() + private var billingProvider: JsonField = JsonMissing.of() + private var deliveryMethod: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + customerBillingProviderConfiguration: CustomerBillingProviderConfiguration + ) = apply { + id = customerBillingProviderConfiguration.id + billingProvider = customerBillingProviderConfiguration.billingProvider + deliveryMethod = customerBillingProviderConfiguration.deliveryMethod + additionalProperties = + customerBillingProviderConfiguration.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 billingProvider(billingProvider: BillingProvider) = + billingProvider(JsonField.of(billingProvider)) + + /** + * Sets [Builder.billingProvider] to an arbitrary JSON value. + * + * You should usually call [Builder.billingProvider] with a well-typed + * [BillingProvider] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun billingProvider(billingProvider: JsonField) = apply { + this.billingProvider = billingProvider + } + + fun deliveryMethod(deliveryMethod: DeliveryMethod) = + deliveryMethod(JsonField.of(deliveryMethod)) + + /** + * Sets [Builder.deliveryMethod] to an arbitrary JSON value. + * + * You should usually call [Builder.deliveryMethod] with a well-typed + * [DeliveryMethod] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun deliveryMethod(deliveryMethod: JsonField) = apply { + this.deliveryMethod = deliveryMethod + } + + 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 [CustomerBillingProviderConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CustomerBillingProviderConfiguration = + CustomerBillingProviderConfiguration( + id, + billingProvider, + deliveryMethod, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): CustomerBillingProviderConfiguration = apply { + if (validated) { + return@apply + } + + id() + billingProvider().ifPresent { it.validate() } + deliveryMethod().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (billingProvider.asKnown().getOrNull()?.validity() ?: 0) + + (deliveryMethod.asKnown().getOrNull()?.validity() ?: 0) + + class BillingProvider + @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 AWS_MARKETPLACE = of("aws_marketplace") + + @JvmField val STRIPE = of("stripe") + + @JvmField val NETSUITE = of("netsuite") + + @JvmField val CUSTOM = of("custom") + + @JvmField val AZURE_MARKETPLACE = of("azure_marketplace") + + @JvmField val QUICKBOOKS_ONLINE = of("quickbooks_online") + + @JvmField val WORKDAY = of("workday") + + @JvmField val GCP_MARKETPLACE = of("gcp_marketplace") + + @JvmField val METRONOME = of("metronome") + + @JvmStatic fun of(value: String) = BillingProvider(JsonField.of(value)) + } + + /** An enum containing [BillingProvider]'s known values. */ + enum class Known { + AWS_MARKETPLACE, + STRIPE, + NETSUITE, + CUSTOM, + AZURE_MARKETPLACE, + QUICKBOOKS_ONLINE, + WORKDAY, + GCP_MARKETPLACE, + METRONOME, + } + + /** + * An enum containing [BillingProvider]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [BillingProvider] 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 { + AWS_MARKETPLACE, + STRIPE, + NETSUITE, + CUSTOM, + AZURE_MARKETPLACE, + QUICKBOOKS_ONLINE, + WORKDAY, + GCP_MARKETPLACE, + METRONOME, + /** + * An enum member indicating that [BillingProvider] 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) { + AWS_MARKETPLACE -> Value.AWS_MARKETPLACE + STRIPE -> Value.STRIPE + NETSUITE -> Value.NETSUITE + CUSTOM -> Value.CUSTOM + AZURE_MARKETPLACE -> Value.AZURE_MARKETPLACE + QUICKBOOKS_ONLINE -> Value.QUICKBOOKS_ONLINE + WORKDAY -> Value.WORKDAY + GCP_MARKETPLACE -> Value.GCP_MARKETPLACE + METRONOME -> Value.METRONOME + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + AWS_MARKETPLACE -> Known.AWS_MARKETPLACE + STRIPE -> Known.STRIPE + NETSUITE -> Known.NETSUITE + CUSTOM -> Known.CUSTOM + AZURE_MARKETPLACE -> Known.AZURE_MARKETPLACE + QUICKBOOKS_ONLINE -> Known.QUICKBOOKS_ONLINE + WORKDAY -> Known.WORKDAY + GCP_MARKETPLACE -> Known.GCP_MARKETPLACE + METRONOME -> Known.METRONOME + else -> + throw MetronomeInvalidDataException( + "Unknown BillingProvider: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): BillingProvider = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 BillingProvider && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class DeliveryMethod + @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 DIRECT_TO_BILLING_PROVIDER = of("direct_to_billing_provider") + + @JvmField val AWS_SQS = of("aws_sqs") + + @JvmField val TACKLE = of("tackle") + + @JvmField val AWS_SNS = of("aws_sns") + + @JvmStatic fun of(value: String) = DeliveryMethod(JsonField.of(value)) + } + + /** An enum containing [DeliveryMethod]'s known values. */ + enum class Known { + DIRECT_TO_BILLING_PROVIDER, + AWS_SQS, + TACKLE, + AWS_SNS, + } + + /** + * An enum containing [DeliveryMethod]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [DeliveryMethod] 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 { + DIRECT_TO_BILLING_PROVIDER, + AWS_SQS, + TACKLE, + AWS_SNS, + /** + * An enum member indicating that [DeliveryMethod] 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) { + DIRECT_TO_BILLING_PROVIDER -> Value.DIRECT_TO_BILLING_PROVIDER + AWS_SQS -> Value.AWS_SQS + TACKLE -> Value.TACKLE + AWS_SNS -> Value.AWS_SNS + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + DIRECT_TO_BILLING_PROVIDER -> Known.DIRECT_TO_BILLING_PROVIDER + AWS_SQS -> Known.AWS_SQS + TACKLE -> Known.TACKLE + AWS_SNS -> Known.AWS_SNS + else -> + throw MetronomeInvalidDataException( + "Unknown DeliveryMethod: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): DeliveryMethod = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 DeliveryMethod && 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 CustomerBillingProviderConfiguration && + id == other.id && + billingProvider == other.billingProvider && + deliveryMethod == other.deliveryMethod && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, billingProvider, deliveryMethod, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerBillingProviderConfiguration{id=$id, billingProvider=$billingProvider, deliveryMethod=$deliveryMethod, additionalProperties=$additionalProperties}" + } + + /** + * Indicates whether there are more items than the limit for this endpoint. Use the + * respective list endpoints to get the full lists. + */ + class HasMore + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val commits: JsonField, + private val credits: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("commits") + @ExcludeMissing + commits: JsonField = JsonMissing.of(), + @JsonProperty("credits") + @ExcludeMissing + credits: JsonField = JsonMissing.of(), + ) : this(commits, credits, mutableMapOf()) + + /** + * Whether there are more commits on this contract than the limit for this endpoint. + * Use the /contracts/customerCommits/list endpoint to get the full list of commits. + * + * @throws MetronomeInvalidDataException 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 commits(): Boolean = commits.getRequired("commits") + + /** + * Whether there are more credits on this contract than the limit for this endpoint. + * Use the /contracts/customerCredits/list endpoint to get the full list of credits. + * + * @throws MetronomeInvalidDataException 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 credits(): Boolean = credits.getRequired("credits") + + /** + * Returns the raw JSON value of [commits]. + * + * Unlike [commits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("commits") + @ExcludeMissing + fun _commits(): JsonField = commits + + /** + * Returns the raw JSON value of [credits]. + * + * Unlike [credits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credits") + @ExcludeMissing + fun _credits(): JsonField = credits + + @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 [HasMore]. + * + * The following fields are required: + * ```java + * .commits() + * .credits() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [HasMore]. */ + class Builder internal constructor() { + + private var commits: JsonField? = null + private var credits: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(hasMore: HasMore) = apply { + commits = hasMore.commits + credits = hasMore.credits + additionalProperties = hasMore.additionalProperties.toMutableMap() + } + + /** + * Whether there are more commits on this contract than the limit for this + * endpoint. Use the /contracts/customerCommits/list endpoint to get the full + * list of commits. + */ + fun commits(commits: Boolean) = commits(JsonField.of(commits)) + + /** + * Sets [Builder.commits] to an arbitrary JSON value. + * + * You should usually call [Builder.commits] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun commits(commits: JsonField) = apply { this.commits = commits } + + /** + * Whether there are more credits on this contract than the limit for this + * endpoint. Use the /contracts/customerCredits/list endpoint to get the full + * list of credits. + */ + fun credits(credits: Boolean) = credits(JsonField.of(credits)) + + /** + * Sets [Builder.credits] to an arbitrary JSON value. + * + * You should usually call [Builder.credits] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun credits(credits: JsonField) = apply { this.credits = credits } + + 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 [HasMore]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .commits() + * .credits() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): HasMore = + HasMore( + checkRequired("commits", commits), + checkRequired("credits", credits), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): HasMore = apply { + if (validated) { + return@apply + } + + commits() + credits() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (commits.asKnown().isPresent) 1 else 0) + + (if (credits.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is HasMore && + commits == other.commits && + credits == other.credits && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(commits, credits, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "HasMore{commits=$commits, credits=$credits, additionalProperties=$additionalProperties}" + } + + /** + * Defaults to LOWEST_MULTIPLIER, which applies the greatest discount to list prices + * automatically. EXPLICIT prioritization requires specifying priorities for each + * multiplier; the one with the lowest priority value will be prioritized first. + */ + class MultiplierOverridePrioritization + @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 LOWEST_MULTIPLIER = of("LOWEST_MULTIPLIER") + + @JvmField val EXPLICIT = of("EXPLICIT") + + @JvmStatic + fun of(value: String) = MultiplierOverridePrioritization(JsonField.of(value)) + } + + /** An enum containing [MultiplierOverridePrioritization]'s known values. */ + enum class Known { + LOWEST_MULTIPLIER, + EXPLICIT, + } + + /** + * An enum containing [MultiplierOverridePrioritization]'s known values, as well as + * an [_UNKNOWN] member. + * + * An instance of [MultiplierOverridePrioritization] 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 { + LOWEST_MULTIPLIER, + EXPLICIT, + /** + * An enum member indicating that [MultiplierOverridePrioritization] 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) { + LOWEST_MULTIPLIER -> Value.LOWEST_MULTIPLIER + EXPLICIT -> Value.EXPLICIT + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + LOWEST_MULTIPLIER -> Known.LOWEST_MULTIPLIER + EXPLICIT -> Known.EXPLICIT + else -> + throw MetronomeInvalidDataException( + "Unknown MultiplierOverridePrioritization: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): MultiplierOverridePrioritization = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 MultiplierOverridePrioritization && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class RecurringCommit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val accessAmount: JsonField, + private val commitDuration: JsonField, + private val priority: JsonField, + private val product: JsonField, + private val rateType: JsonField, + private val startingAt: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val contract: JsonField, + private val description: JsonField, + private val endingBefore: JsonField, + private val hierarchyConfiguration: JsonField, + private val invoiceAmount: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val proration: JsonField, + private val recurrenceFrequency: JsonField, + private val rolloverFraction: JsonField, + private val specifiers: JsonField>, + private val subscriptionConfig: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("access_amount") + @ExcludeMissing + accessAmount: JsonField = JsonMissing.of(), + @JsonProperty("commit_duration") + @ExcludeMissing + commitDuration: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("contract") + @ExcludeMissing + contract: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("invoice_amount") + @ExcludeMissing + invoiceAmount: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("proration") + @ExcludeMissing + proration: JsonField = JsonMissing.of(), + @JsonProperty("recurrence_frequency") + @ExcludeMissing + recurrenceFrequency: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("subscription_config") + @ExcludeMissing + subscriptionConfig: JsonField = + JsonMissing.of(), + ) : this( + id, + accessAmount, + commitDuration, + priority, + product, + rateType, + startingAt, + applicableProductIds, + applicableProductTags, + contract, + description, + endingBefore, + hierarchyConfiguration, + invoiceAmount, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + specifiers, + subscriptionConfig, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException 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") + + /** + * The amount of commit to grant. + * + * @throws MetronomeInvalidDataException 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 accessAmount(): AccessAmount = accessAmount.getRequired("access_amount") + + /** + * The amount of time the created commits will be valid for + * + * @throws MetronomeInvalidDataException 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 commitDuration(): CommitDuration = commitDuration.getRequired("commit_duration") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException 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 priority(): Double = priority.getRequired("priority") + + /** + * @throws MetronomeInvalidDataException 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 product(): Product = product.getRequired("product") + + /** + * Whether the created commits will use the commit rate or list rate + * + * @throws MetronomeInvalidDataException 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 rateType(): RateType = rateType.getRequired("rate_type") + + /** + * Determines the start time for the first commit + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun contract(): Optional = contract.getOptional("contract") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Determines when the contract will stop creating recurring commits. Optional + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * Optional configuration for recurring commit/credit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * The amount the customer should be billed for the commit. Not required. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun invoiceAmount(): Optional = + invoiceAmount.getOptional("invoice_amount") + + /** + * Displayed on invoices. Will be passed through to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * Determines whether the first and last commit will be prorated. If not provided, + * the default is FIRST_AND_LAST (i.e. prorate both the first and last commits). + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun proration(): Optional = proration.getOptional("proration") + + /** + * The frequency at which the recurring commits will be created. If not provided: - + * The commits will be created on the usage invoice frequency. If provided: - The + * period defined in the duration will correspond to this frequency. - Commits will + * be created aligned with the recurring commit's starting_at rather than the usage + * invoice dates. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun recurrenceFrequency(): Optional = + recurrenceFrequency.getOptional("recurrence_frequency") + + /** + * Will be passed down to the individual commits. This controls how much of an + * individual unexpired commit will roll over upon contract transition. Must be + * between 0 and 1. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = + rolloverFraction.getOptional("rollover_fraction") + + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Attach a subscription to the recurring commit/credit. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun subscriptionConfig(): Optional = + subscriptionConfig.getOptional("subscription_config") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [accessAmount]. + * + * Unlike [accessAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_amount") + @ExcludeMissing + fun _accessAmount(): JsonField = accessAmount + + /** + * Returns the raw JSON value of [commitDuration]. + * + * Unlike [commitDuration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("commit_duration") + @ExcludeMissing + fun _commitDuration(): JsonField = commitDuration + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [contract]. + * + * Unlike [contract], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("contract") + @ExcludeMissing + fun _contract(): JsonField = contract + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * Returns the raw JSON value of [invoiceAmount]. + * + * Unlike [invoiceAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_amount") + @ExcludeMissing + fun _invoiceAmount(): JsonField = invoiceAmount + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [proration]. + * + * Unlike [proration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("proration") + @ExcludeMissing + fun _proration(): JsonField = proration + + /** + * Returns the raw JSON value of [recurrenceFrequency]. + * + * Unlike [recurrenceFrequency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("recurrence_frequency") + @ExcludeMissing + fun _recurrenceFrequency(): JsonField = recurrenceFrequency + + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + /** + * Returns the raw JSON value of [subscriptionConfig]. + * + * Unlike [subscriptionConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("subscription_config") + @ExcludeMissing + fun _subscriptionConfig(): JsonField = + subscriptionConfig + + @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 [RecurringCommit]. + * + * The following fields are required: + * ```java + * .id() + * .accessAmount() + * .commitDuration() + * .priority() + * .product() + * .rateType() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RecurringCommit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var accessAmount: JsonField? = null + private var commitDuration: JsonField? = null + private var priority: JsonField? = null + private var product: JsonField? = null + private var rateType: JsonField? = null + private var startingAt: JsonField? = null + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var contract: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var invoiceAmount: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var proration: JsonField = JsonMissing.of() + private var recurrenceFrequency: JsonField = + JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var specifiers: JsonField>? = null + private var subscriptionConfig: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(recurringCommit: RecurringCommit) = apply { + id = recurringCommit.id + accessAmount = recurringCommit.accessAmount + commitDuration = recurringCommit.commitDuration + priority = recurringCommit.priority + product = recurringCommit.product + rateType = recurringCommit.rateType + startingAt = recurringCommit.startingAt + applicableProductIds = + recurringCommit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + recurringCommit.applicableProductTags.map { it.toMutableList() } + contract = recurringCommit.contract + description = recurringCommit.description + endingBefore = recurringCommit.endingBefore + hierarchyConfiguration = recurringCommit.hierarchyConfiguration + invoiceAmount = recurringCommit.invoiceAmount + name = recurringCommit.name + netsuiteSalesOrderId = recurringCommit.netsuiteSalesOrderId + proration = recurringCommit.proration + recurrenceFrequency = recurringCommit.recurrenceFrequency + rolloverFraction = recurringCommit.rolloverFraction + specifiers = recurringCommit.specifiers.map { it.toMutableList() } + subscriptionConfig = recurringCommit.subscriptionConfig + additionalProperties = recurringCommit.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 } + + /** The amount of commit to grant. */ + fun accessAmount(accessAmount: AccessAmount) = + accessAmount(JsonField.of(accessAmount)) + + /** + * Sets [Builder.accessAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.accessAmount] with a well-typed + * [AccessAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun accessAmount(accessAmount: JsonField) = apply { + this.accessAmount = accessAmount + } + + /** The amount of time the created commits will be valid for */ + fun commitDuration(commitDuration: CommitDuration) = + commitDuration(JsonField.of(commitDuration)) + + /** + * Sets [Builder.commitDuration] to an arbitrary JSON value. + * + * You should usually call [Builder.commitDuration] with a well-typed + * [CommitDuration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun commitDuration(commitDuration: JsonField) = apply { + this.commitDuration = commitDuration + } + + /** Will be passed down to the individual commits */ + fun priority(priority: Double) = priority(JsonField.of(priority)) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + /** Whether the created commits will use the commit rate or list rate */ + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + /** Determines the start time for the first commit */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + /** Will be passed down to the individual commits */ + fun applicableProductIds(applicableProductIds: List) = + applicableProductIds(JsonField.of(applicableProductIds)) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + /** Will be passed down to the individual commits */ + fun applicableProductTags(applicableProductTags: List) = + applicableProductTags(JsonField.of(applicableProductTags)) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun contract(contract: InnerContract) = contract(JsonField.of(contract)) + + /** + * Sets [Builder.contract] to an arbitrary JSON value. + * + * You should usually call [Builder.contract] with a well-typed [InnerContract] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contract(contract: JsonField) = apply { + this.contract = contract + } + + /** Will be passed down to the individual commits */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** + * Determines when the contract will stop creating recurring commits. Optional + */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** + * Optional configuration for recurring commit/credit hierarchy access control + */ + fun hierarchyConfiguration( + hierarchyConfiguration: CommitHierarchyConfiguration + ) = hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + /** The amount the customer should be billed for the commit. Not required. */ + fun invoiceAmount(invoiceAmount: InvoiceAmount) = + invoiceAmount(JsonField.of(invoiceAmount)) + + /** + * Sets [Builder.invoiceAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceAmount] with a well-typed + * [InvoiceAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun invoiceAmount(invoiceAmount: JsonField) = apply { + this.invoiceAmount = invoiceAmount + } + + /** Displayed on invoices. Will be passed through to the individual commits */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Will be passed down to the individual commits */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String) = + netsuiteSalesOrderId(JsonField.of(netsuiteSalesOrderId)) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** + * Determines whether the first and last commit will be prorated. If not + * provided, the default is FIRST_AND_LAST (i.e. prorate both the first and last + * commits). + */ + fun proration(proration: Proration) = proration(JsonField.of(proration)) + + /** + * Sets [Builder.proration] to an arbitrary JSON value. + * + * You should usually call [Builder.proration] with a well-typed [Proration] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun proration(proration: JsonField) = apply { + this.proration = proration + } + + /** + * The frequency at which the recurring commits will be created. If not + * provided: - The commits will be created on the usage invoice frequency. If + * provided: - The period defined in the duration will correspond to this + * frequency. - Commits will be created aligned with the recurring commit's + * starting_at rather than the usage invoice dates. + */ + fun recurrenceFrequency(recurrenceFrequency: RecurrenceFrequency) = + recurrenceFrequency(JsonField.of(recurrenceFrequency)) + + /** + * Sets [Builder.recurrenceFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.recurrenceFrequency] with a well-typed + * [RecurrenceFrequency] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun recurrenceFrequency(recurrenceFrequency: JsonField) = + apply { + this.recurrenceFrequency = recurrenceFrequency + } + + /** + * Will be passed down to the individual commits. This controls how much of an + * individual unexpired commit will roll over upon contract transition. Must be + * between 0 and 1. + */ + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(JsonField.of(rolloverFraction)) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. + */ + fun specifiers(specifiers: List) = + specifiers(JsonField.of(specifiers)) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifier] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpecifier(specifier: CommitSpecifier) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + /** Attach a subscription to the recurring commit/credit. */ + fun subscriptionConfig(subscriptionConfig: RecurringCommitSubscriptionConfig) = + subscriptionConfig(JsonField.of(subscriptionConfig)) + + /** + * Sets [Builder.subscriptionConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.subscriptionConfig] with a well-typed + * [RecurringCommitSubscriptionConfig] value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun subscriptionConfig( + subscriptionConfig: JsonField + ) = apply { this.subscriptionConfig = subscriptionConfig } + + 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 [RecurringCommit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .accessAmount() + * .commitDuration() + * .priority() + * .product() + * .rateType() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RecurringCommit = + RecurringCommit( + checkRequired("id", id), + checkRequired("accessAmount", accessAmount), + checkRequired("commitDuration", commitDuration), + checkRequired("priority", priority), + checkRequired("product", product), + checkRequired("rateType", rateType), + checkRequired("startingAt", startingAt), + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + contract, + description, + endingBefore, + hierarchyConfiguration, + invoiceAmount, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + subscriptionConfig, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): RecurringCommit = apply { + if (validated) { + return@apply + } + + id() + accessAmount().validate() + commitDuration().validate() + priority() + product().validate() + rateType().validate() + startingAt() + applicableProductIds() + applicableProductTags() + contract().ifPresent { it.validate() } + description() + endingBefore() + hierarchyConfiguration().ifPresent { it.validate() } + invoiceAmount().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + proration().ifPresent { it.validate() } + recurrenceFrequency().ifPresent { it.validate() } + rolloverFraction() + specifiers().ifPresent { it.forEach { it.validate() } } + subscriptionConfig().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (accessAmount.asKnown().getOrNull()?.validity() ?: 0) + + (commitDuration.asKnown().getOrNull()?.validity() ?: 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (contract.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (invoiceAmount.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (proration.asKnown().getOrNull()?.validity() ?: 0) + + (recurrenceFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (subscriptionConfig.asKnown().getOrNull()?.validity() ?: 0) + + /** The amount of commit to grant. */ + class AccessAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditTypeId: JsonField, + private val unitPrice: JsonField, + private val quantity: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + ) : this(creditTypeId, unitPrice, quantity, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 unitPrice(): Double = unitPrice.getRequired("unit_price") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + @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 [AccessAmount]. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .unitPrice() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccessAmount]. */ + class Builder internal constructor() { + + private var creditTypeId: JsonField? = null + private var unitPrice: JsonField? = null + private var quantity: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(accessAmount: AccessAmount) = apply { + creditTypeId = accessAmount.creditTypeId + unitPrice = accessAmount.unitPrice + quantity = accessAmount.quantity + additionalProperties = accessAmount.additionalProperties.toMutableMap() + } + + fun creditTypeId(creditTypeId: String) = + creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + 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 [AccessAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AccessAmount = + AccessAmount( + checkRequired("creditTypeId", creditTypeId), + checkRequired("unitPrice", unitPrice), + quantity, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AccessAmount = apply { + if (validated) { + return@apply + } + + creditTypeId() + unitPrice() + quantity() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (creditTypeId.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccessAmount && + creditTypeId == other.creditTypeId && + unitPrice == other.unitPrice && + quantity == other.quantity && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(creditTypeId, unitPrice, quantity, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessAmount{creditTypeId=$creditTypeId, unitPrice=$unitPrice, quantity=$quantity, additionalProperties=$additionalProperties}" + } + + /** The amount of time the created commits will be valid for */ + class CommitDuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val value: JsonField, + private val unit: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + @JsonProperty("unit") + @ExcludeMissing + unit: JsonField = JsonMissing.of(), + ) : this(value, unit, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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(): Double = value.getRequired("value") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unit(): Optional = unit.getOptional("unit") + + /** + * 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 + + /** + * Returns the raw JSON value of [unit]. + * + * Unlike [unit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit") @ExcludeMissing fun _unit(): JsonField = unit + + @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 + * [CommitDuration]. + * + * The following fields are required: + * ```java + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CommitDuration]. */ + class Builder internal constructor() { + + private var value: JsonField? = null + private var unit: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(commitDuration: CommitDuration) = apply { + value = commitDuration.value + unit = commitDuration.unit + additionalProperties = + commitDuration.additionalProperties.toMutableMap() + } + + fun value(value: Double) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Double] 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 unit(unit: Unit) = unit(JsonField.of(unit)) + + /** + * Sets [Builder.unit] to an arbitrary JSON value. + * + * You should usually call [Builder.unit] with a well-typed [Unit] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unit(unit: JsonField) = apply { this.unit = unit } + + 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 [CommitDuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CommitDuration = + CommitDuration( + checkRequired("value", value), + unit, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CommitDuration = apply { + if (validated) { + return@apply + } + + value() + unit().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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.asKnown().isPresent) 1 else 0) + + (unit.asKnown().getOrNull()?.validity() ?: 0) + + class Unit + @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 PERIODS = of("PERIODS") + + @JvmStatic fun of(value: String) = Unit(JsonField.of(value)) + } + + /** An enum containing [Unit]'s known values. */ + enum class Known { + PERIODS + } + + /** + * An enum containing [Unit]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Unit] 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 { + PERIODS, + /** + * An enum member indicating that [Unit] 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) { + PERIODS -> Value.PERIODS + 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + PERIODS -> Known.PERIODS + else -> throw MetronomeInvalidDataException("Unknown Unit: $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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Unit = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Unit && 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 CommitDuration && + value == other.value && + unit == other.unit && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(value, unit, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CommitDuration{value=$value, unit=$unit, additionalProperties=$additionalProperties}" + } + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + /** Whether the created commits will use the commit rate or list rate */ + class RateType + @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 COMMIT_RATE = of("COMMIT_RATE") + + @JvmField val LIST_RATE = of("LIST_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + COMMIT_RATE, + LIST_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + COMMIT_RATE, + LIST_RATE, + /** + * An enum member indicating that [RateType] 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) { + COMMIT_RATE -> Value.COMMIT_RATE + LIST_RATE -> Value.LIST_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_RATE -> Known.COMMIT_RATE + LIST_RATE -> Known.LIST_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InnerContract + @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 MetronomeInvalidDataException 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 + * [InnerContract]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InnerContract]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(innerContract: InnerContract) = apply { + id = innerContract.id + additionalProperties = innerContract.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 [InnerContract]. + * + * 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(): InnerContract = + InnerContract( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InnerContract = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 InnerContract && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InnerContract{id=$id, additionalProperties=$additionalProperties}" + } + + /** The amount the customer should be billed for the commit. Not required. */ + class InvoiceAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditTypeId: JsonField, + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(creditTypeId, quantity, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 quantity(): Double = quantity.getRequired("quantity") + + /** + * @throws MetronomeInvalidDataException 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 unitPrice(): Double = unitPrice.getRequired("unit_price") + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [InvoiceAmount]. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .quantity() + * .unitPrice() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InvoiceAmount]. */ + class Builder internal constructor() { + + private var creditTypeId: JsonField? = null + private var quantity: JsonField? = null + private var unitPrice: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(invoiceAmount: InvoiceAmount) = apply { + creditTypeId = invoiceAmount.creditTypeId + quantity = invoiceAmount.quantity + unitPrice = invoiceAmount.unitPrice + additionalProperties = invoiceAmount.additionalProperties.toMutableMap() + } + + fun creditTypeId(creditTypeId: String) = + creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [InvoiceAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .quantity() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InvoiceAmount = + InvoiceAmount( + checkRequired("creditTypeId", creditTypeId), + checkRequired("quantity", quantity), + checkRequired("unitPrice", unitPrice), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InvoiceAmount = apply { + if (validated) { + return@apply + } + + creditTypeId() + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (creditTypeId.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InvoiceAmount && + creditTypeId == other.creditTypeId && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(creditTypeId, quantity, unitPrice, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InvoiceAmount{creditTypeId=$creditTypeId, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + /** + * Determines whether the first and last commit will be prorated. If not provided, + * the default is FIRST_AND_LAST (i.e. prorate both the first and last commits). + */ + class Proration + @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 FIRST = of("FIRST") + + @JvmField val LAST = of("LAST") + + @JvmField val FIRST_AND_LAST = of("FIRST_AND_LAST") + + @JvmStatic fun of(value: String) = Proration(JsonField.of(value)) + } + + /** An enum containing [Proration]'s known values. */ + enum class Known { + NONE, + FIRST, + LAST, + FIRST_AND_LAST, + } + + /** + * An enum containing [Proration]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Proration] 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, + FIRST, + LAST, + FIRST_AND_LAST, + /** + * An enum member indicating that [Proration] 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 + FIRST -> Value.FIRST + LAST -> Value.LAST + FIRST_AND_LAST -> Value.FIRST_AND_LAST + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + NONE -> Known.NONE + FIRST -> Known.FIRST + LAST -> Known.LAST + FIRST_AND_LAST -> Known.FIRST_AND_LAST + else -> throw MetronomeInvalidDataException("Unknown Proration: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Proration = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Proration && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * The frequency at which the recurring commits will be created. If not provided: - + * The commits will be created on the usage invoice frequency. If provided: - The + * period defined in the duration will correspond to this frequency. - Commits will + * be created aligned with the recurring commit's starting_at rather than the usage + * invoice dates. + */ + class RecurrenceFrequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = RecurrenceFrequency(JsonField.of(value)) + } + + /** An enum containing [RecurrenceFrequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [RecurrenceFrequency]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [RecurrenceFrequency] 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 { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [RecurrenceFrequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> + throw MetronomeInvalidDataException( + "Unknown RecurrenceFrequency: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RecurrenceFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RecurrenceFrequency && 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 RecurringCommit && + id == other.id && + accessAmount == other.accessAmount && + commitDuration == other.commitDuration && + priority == other.priority && + product == other.product && + rateType == other.rateType && + startingAt == other.startingAt && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + contract == other.contract && + description == other.description && + endingBefore == other.endingBefore && + hierarchyConfiguration == other.hierarchyConfiguration && + invoiceAmount == other.invoiceAmount && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + proration == other.proration && + recurrenceFrequency == other.recurrenceFrequency && + rolloverFraction == other.rolloverFraction && + specifiers == other.specifiers && + subscriptionConfig == other.subscriptionConfig && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + accessAmount, + commitDuration, + priority, + product, + rateType, + startingAt, + applicableProductIds, + applicableProductTags, + contract, + description, + endingBefore, + hierarchyConfiguration, + invoiceAmount, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + specifiers, + subscriptionConfig, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RecurringCommit{id=$id, accessAmount=$accessAmount, commitDuration=$commitDuration, priority=$priority, product=$product, rateType=$rateType, startingAt=$startingAt, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, contract=$contract, description=$description, endingBefore=$endingBefore, hierarchyConfiguration=$hierarchyConfiguration, invoiceAmount=$invoiceAmount, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, proration=$proration, recurrenceFrequency=$recurrenceFrequency, rolloverFraction=$rolloverFraction, specifiers=$specifiers, subscriptionConfig=$subscriptionConfig, additionalProperties=$additionalProperties}" + } + + class RecurringCredit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val accessAmount: JsonField, + private val commitDuration: JsonField, + private val priority: JsonField, + private val product: JsonField, + private val rateType: JsonField, + private val startingAt: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val contract: JsonField, + private val description: JsonField, + private val endingBefore: JsonField, + private val hierarchyConfiguration: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val proration: JsonField, + private val recurrenceFrequency: JsonField, + private val rolloverFraction: JsonField, + private val specifiers: JsonField>, + private val subscriptionConfig: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("access_amount") + @ExcludeMissing + accessAmount: JsonField = JsonMissing.of(), + @JsonProperty("commit_duration") + @ExcludeMissing + commitDuration: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("contract") + @ExcludeMissing + contract: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("proration") + @ExcludeMissing + proration: JsonField = JsonMissing.of(), + @JsonProperty("recurrence_frequency") + @ExcludeMissing + recurrenceFrequency: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("subscription_config") + @ExcludeMissing + subscriptionConfig: JsonField = + JsonMissing.of(), + ) : this( + id, + accessAmount, + commitDuration, + priority, + product, + rateType, + startingAt, + applicableProductIds, + applicableProductTags, + contract, + description, + endingBefore, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + specifiers, + subscriptionConfig, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException 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") + + /** + * The amount of commit to grant. + * + * @throws MetronomeInvalidDataException 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 accessAmount(): AccessAmount = accessAmount.getRequired("access_amount") + + /** + * The amount of time the created commits will be valid for + * + * @throws MetronomeInvalidDataException 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 commitDuration(): CommitDuration = commitDuration.getRequired("commit_duration") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException 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 priority(): Double = priority.getRequired("priority") + + /** + * @throws MetronomeInvalidDataException 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 product(): Product = product.getRequired("product") + + /** + * Whether the created commits will use the commit rate or list rate + * + * @throws MetronomeInvalidDataException 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 rateType(): RateType = rateType.getRequired("rate_type") + + /** + * Determines the start time for the first commit + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun contract(): Optional = contract.getOptional("contract") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Determines when the contract will stop creating recurring commits. Optional + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * Optional configuration for recurring commit/credit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * Displayed on invoices. Will be passed through to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * Determines whether the first and last commit will be prorated. If not provided, + * the default is FIRST_AND_LAST (i.e. prorate both the first and last commits). + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun proration(): Optional = proration.getOptional("proration") + + /** + * The frequency at which the recurring commits will be created. If not provided: - + * The commits will be created on the usage invoice frequency. If provided: - The + * period defined in the duration will correspond to this frequency. - Commits will + * be created aligned with the recurring commit's starting_at rather than the usage + * invoice dates. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun recurrenceFrequency(): Optional = + recurrenceFrequency.getOptional("recurrence_frequency") + + /** + * Will be passed down to the individual commits. This controls how much of an + * individual unexpired commit will roll over upon contract transition. Must be + * between 0 and 1. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = + rolloverFraction.getOptional("rollover_fraction") + + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Attach a subscription to the recurring commit/credit. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun subscriptionConfig(): Optional = + subscriptionConfig.getOptional("subscription_config") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [accessAmount]. + * + * Unlike [accessAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_amount") + @ExcludeMissing + fun _accessAmount(): JsonField = accessAmount + + /** + * Returns the raw JSON value of [commitDuration]. + * + * Unlike [commitDuration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("commit_duration") + @ExcludeMissing + fun _commitDuration(): JsonField = commitDuration + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [contract]. + * + * Unlike [contract], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("contract") + @ExcludeMissing + fun _contract(): JsonField = contract + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [proration]. + * + * Unlike [proration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("proration") + @ExcludeMissing + fun _proration(): JsonField = proration + + /** + * Returns the raw JSON value of [recurrenceFrequency]. + * + * Unlike [recurrenceFrequency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("recurrence_frequency") + @ExcludeMissing + fun _recurrenceFrequency(): JsonField = recurrenceFrequency + + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + /** + * Returns the raw JSON value of [subscriptionConfig]. + * + * Unlike [subscriptionConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("subscription_config") + @ExcludeMissing + fun _subscriptionConfig(): JsonField = + subscriptionConfig + + @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 [RecurringCredit]. + * + * The following fields are required: + * ```java + * .id() + * .accessAmount() + * .commitDuration() + * .priority() + * .product() + * .rateType() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RecurringCredit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var accessAmount: JsonField? = null + private var commitDuration: JsonField? = null + private var priority: JsonField? = null + private var product: JsonField? = null + private var rateType: JsonField? = null + private var startingAt: JsonField? = null + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var contract: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var proration: JsonField = JsonMissing.of() + private var recurrenceFrequency: JsonField = + JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var specifiers: JsonField>? = null + private var subscriptionConfig: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(recurringCredit: RecurringCredit) = apply { + id = recurringCredit.id + accessAmount = recurringCredit.accessAmount + commitDuration = recurringCredit.commitDuration + priority = recurringCredit.priority + product = recurringCredit.product + rateType = recurringCredit.rateType + startingAt = recurringCredit.startingAt + applicableProductIds = + recurringCredit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + recurringCredit.applicableProductTags.map { it.toMutableList() } + contract = recurringCredit.contract + description = recurringCredit.description + endingBefore = recurringCredit.endingBefore + hierarchyConfiguration = recurringCredit.hierarchyConfiguration + name = recurringCredit.name + netsuiteSalesOrderId = recurringCredit.netsuiteSalesOrderId + proration = recurringCredit.proration + recurrenceFrequency = recurringCredit.recurrenceFrequency + rolloverFraction = recurringCredit.rolloverFraction + specifiers = recurringCredit.specifiers.map { it.toMutableList() } + subscriptionConfig = recurringCredit.subscriptionConfig + additionalProperties = recurringCredit.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 } + + /** The amount of commit to grant. */ + fun accessAmount(accessAmount: AccessAmount) = + accessAmount(JsonField.of(accessAmount)) + + /** + * Sets [Builder.accessAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.accessAmount] with a well-typed + * [AccessAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun accessAmount(accessAmount: JsonField) = apply { + this.accessAmount = accessAmount + } + + /** The amount of time the created commits will be valid for */ + fun commitDuration(commitDuration: CommitDuration) = + commitDuration(JsonField.of(commitDuration)) + + /** + * Sets [Builder.commitDuration] to an arbitrary JSON value. + * + * You should usually call [Builder.commitDuration] with a well-typed + * [CommitDuration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun commitDuration(commitDuration: JsonField) = apply { + this.commitDuration = commitDuration + } + + /** Will be passed down to the individual commits */ + fun priority(priority: Double) = priority(JsonField.of(priority)) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + /** Whether the created commits will use the commit rate or list rate */ + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + /** Determines the start time for the first commit */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + /** Will be passed down to the individual commits */ + fun applicableProductIds(applicableProductIds: List) = + applicableProductIds(JsonField.of(applicableProductIds)) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + /** Will be passed down to the individual commits */ + fun applicableProductTags(applicableProductTags: List) = + applicableProductTags(JsonField.of(applicableProductTags)) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun contract(contract: InnerContract) = contract(JsonField.of(contract)) + + /** + * Sets [Builder.contract] to an arbitrary JSON value. + * + * You should usually call [Builder.contract] with a well-typed [InnerContract] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contract(contract: JsonField) = apply { + this.contract = contract + } + + /** Will be passed down to the individual commits */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** + * Determines when the contract will stop creating recurring commits. Optional + */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** + * Optional configuration for recurring commit/credit hierarchy access control + */ + fun hierarchyConfiguration( + hierarchyConfiguration: CommitHierarchyConfiguration + ) = hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + /** Displayed on invoices. Will be passed through to the individual commits */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Will be passed down to the individual commits */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String) = + netsuiteSalesOrderId(JsonField.of(netsuiteSalesOrderId)) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** + * Determines whether the first and last commit will be prorated. If not + * provided, the default is FIRST_AND_LAST (i.e. prorate both the first and last + * commits). + */ + fun proration(proration: Proration) = proration(JsonField.of(proration)) + + /** + * Sets [Builder.proration] to an arbitrary JSON value. + * + * You should usually call [Builder.proration] with a well-typed [Proration] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun proration(proration: JsonField) = apply { + this.proration = proration + } + + /** + * The frequency at which the recurring commits will be created. If not + * provided: - The commits will be created on the usage invoice frequency. If + * provided: - The period defined in the duration will correspond to this + * frequency. - Commits will be created aligned with the recurring commit's + * starting_at rather than the usage invoice dates. + */ + fun recurrenceFrequency(recurrenceFrequency: RecurrenceFrequency) = + recurrenceFrequency(JsonField.of(recurrenceFrequency)) + + /** + * Sets [Builder.recurrenceFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.recurrenceFrequency] with a well-typed + * [RecurrenceFrequency] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun recurrenceFrequency(recurrenceFrequency: JsonField) = + apply { + this.recurrenceFrequency = recurrenceFrequency + } + + /** + * Will be passed down to the individual commits. This controls how much of an + * individual unexpired commit will roll over upon contract transition. Must be + * between 0 and 1. + */ + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(JsonField.of(rolloverFraction)) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. + */ + fun specifiers(specifiers: List) = + specifiers(JsonField.of(specifiers)) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifier] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpecifier(specifier: CommitSpecifier) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + /** Attach a subscription to the recurring commit/credit. */ + fun subscriptionConfig(subscriptionConfig: RecurringCommitSubscriptionConfig) = + subscriptionConfig(JsonField.of(subscriptionConfig)) + + /** + * Sets [Builder.subscriptionConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.subscriptionConfig] with a well-typed + * [RecurringCommitSubscriptionConfig] value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun subscriptionConfig( + subscriptionConfig: JsonField + ) = apply { this.subscriptionConfig = subscriptionConfig } + + 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 [RecurringCredit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .accessAmount() + * .commitDuration() + * .priority() + * .product() + * .rateType() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RecurringCredit = + RecurringCredit( + checkRequired("id", id), + checkRequired("accessAmount", accessAmount), + checkRequired("commitDuration", commitDuration), + checkRequired("priority", priority), + checkRequired("product", product), + checkRequired("rateType", rateType), + checkRequired("startingAt", startingAt), + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + contract, + description, + endingBefore, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + subscriptionConfig, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): RecurringCredit = apply { + if (validated) { + return@apply + } + + id() + accessAmount().validate() + commitDuration().validate() + priority() + product().validate() + rateType().validate() + startingAt() + applicableProductIds() + applicableProductTags() + contract().ifPresent { it.validate() } + description() + endingBefore() + hierarchyConfiguration().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + proration().ifPresent { it.validate() } + recurrenceFrequency().ifPresent { it.validate() } + rolloverFraction() + specifiers().ifPresent { it.forEach { it.validate() } } + subscriptionConfig().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (accessAmount.asKnown().getOrNull()?.validity() ?: 0) + + (commitDuration.asKnown().getOrNull()?.validity() ?: 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (contract.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (proration.asKnown().getOrNull()?.validity() ?: 0) + + (recurrenceFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (subscriptionConfig.asKnown().getOrNull()?.validity() ?: 0) + + /** The amount of commit to grant. */ + class AccessAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditTypeId: JsonField, + private val unitPrice: JsonField, + private val quantity: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + ) : this(creditTypeId, unitPrice, quantity, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 unitPrice(): Double = unitPrice.getRequired("unit_price") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + @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 [AccessAmount]. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .unitPrice() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccessAmount]. */ + class Builder internal constructor() { + + private var creditTypeId: JsonField? = null + private var unitPrice: JsonField? = null + private var quantity: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(accessAmount: AccessAmount) = apply { + creditTypeId = accessAmount.creditTypeId + unitPrice = accessAmount.unitPrice + quantity = accessAmount.quantity + additionalProperties = accessAmount.additionalProperties.toMutableMap() + } + + fun creditTypeId(creditTypeId: String) = + creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + 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 [AccessAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AccessAmount = + AccessAmount( + checkRequired("creditTypeId", creditTypeId), + checkRequired("unitPrice", unitPrice), + quantity, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AccessAmount = apply { + if (validated) { + return@apply + } + + creditTypeId() + unitPrice() + quantity() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (creditTypeId.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccessAmount && + creditTypeId == other.creditTypeId && + unitPrice == other.unitPrice && + quantity == other.quantity && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(creditTypeId, unitPrice, quantity, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessAmount{creditTypeId=$creditTypeId, unitPrice=$unitPrice, quantity=$quantity, additionalProperties=$additionalProperties}" + } + + /** The amount of time the created commits will be valid for */ + class CommitDuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val value: JsonField, + private val unit: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + @JsonProperty("unit") + @ExcludeMissing + unit: JsonField = JsonMissing.of(), + ) : this(value, unit, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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(): Double = value.getRequired("value") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unit(): Optional = unit.getOptional("unit") + + /** + * 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 + + /** + * Returns the raw JSON value of [unit]. + * + * Unlike [unit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit") @ExcludeMissing fun _unit(): JsonField = unit + + @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 + * [CommitDuration]. + * + * The following fields are required: + * ```java + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CommitDuration]. */ + class Builder internal constructor() { + + private var value: JsonField? = null + private var unit: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(commitDuration: CommitDuration) = apply { + value = commitDuration.value + unit = commitDuration.unit + additionalProperties = + commitDuration.additionalProperties.toMutableMap() + } + + fun value(value: Double) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Double] 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 unit(unit: Unit) = unit(JsonField.of(unit)) + + /** + * Sets [Builder.unit] to an arbitrary JSON value. + * + * You should usually call [Builder.unit] with a well-typed [Unit] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unit(unit: JsonField) = apply { this.unit = unit } + + 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 [CommitDuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CommitDuration = + CommitDuration( + checkRequired("value", value), + unit, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CommitDuration = apply { + if (validated) { + return@apply + } + + value() + unit().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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.asKnown().isPresent) 1 else 0) + + (unit.asKnown().getOrNull()?.validity() ?: 0) + + class Unit + @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 PERIODS = of("PERIODS") + + @JvmStatic fun of(value: String) = Unit(JsonField.of(value)) + } + + /** An enum containing [Unit]'s known values. */ + enum class Known { + PERIODS + } + + /** + * An enum containing [Unit]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Unit] 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 { + PERIODS, + /** + * An enum member indicating that [Unit] 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) { + PERIODS -> Value.PERIODS + 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + PERIODS -> Known.PERIODS + else -> throw MetronomeInvalidDataException("Unknown Unit: $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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Unit = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Unit && 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 CommitDuration && + value == other.value && + unit == other.unit && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(value, unit, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CommitDuration{value=$value, unit=$unit, additionalProperties=$additionalProperties}" + } + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + /** Whether the created commits will use the commit rate or list rate */ + class RateType + @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 COMMIT_RATE = of("COMMIT_RATE") + + @JvmField val LIST_RATE = of("LIST_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + COMMIT_RATE, + LIST_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + COMMIT_RATE, + LIST_RATE, + /** + * An enum member indicating that [RateType] 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) { + COMMIT_RATE -> Value.COMMIT_RATE + LIST_RATE -> Value.LIST_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_RATE -> Known.COMMIT_RATE + LIST_RATE -> Known.LIST_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InnerContract + @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 MetronomeInvalidDataException 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 + * [InnerContract]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InnerContract]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(innerContract: InnerContract) = apply { + id = innerContract.id + additionalProperties = innerContract.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 [InnerContract]. + * + * 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(): InnerContract = + InnerContract( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InnerContract = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 InnerContract && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InnerContract{id=$id, additionalProperties=$additionalProperties}" + } + + /** + * Determines whether the first and last commit will be prorated. If not provided, + * the default is FIRST_AND_LAST (i.e. prorate both the first and last commits). + */ + class Proration + @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 FIRST = of("FIRST") + + @JvmField val LAST = of("LAST") + + @JvmField val FIRST_AND_LAST = of("FIRST_AND_LAST") + + @JvmStatic fun of(value: String) = Proration(JsonField.of(value)) + } + + /** An enum containing [Proration]'s known values. */ + enum class Known { + NONE, + FIRST, + LAST, + FIRST_AND_LAST, + } + + /** + * An enum containing [Proration]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Proration] 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, + FIRST, + LAST, + FIRST_AND_LAST, + /** + * An enum member indicating that [Proration] 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 + FIRST -> Value.FIRST + LAST -> Value.LAST + FIRST_AND_LAST -> Value.FIRST_AND_LAST + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + NONE -> Known.NONE + FIRST -> Known.FIRST + LAST -> Known.LAST + FIRST_AND_LAST -> Known.FIRST_AND_LAST + else -> throw MetronomeInvalidDataException("Unknown Proration: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Proration = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Proration && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * The frequency at which the recurring commits will be created. If not provided: - + * The commits will be created on the usage invoice frequency. If provided: - The + * period defined in the duration will correspond to this frequency. - Commits will + * be created aligned with the recurring commit's starting_at rather than the usage + * invoice dates. + */ + class RecurrenceFrequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = RecurrenceFrequency(JsonField.of(value)) + } + + /** An enum containing [RecurrenceFrequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [RecurrenceFrequency]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [RecurrenceFrequency] 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 { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [RecurrenceFrequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> + throw MetronomeInvalidDataException( + "Unknown RecurrenceFrequency: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RecurrenceFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RecurrenceFrequency && 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 RecurringCredit && + id == other.id && + accessAmount == other.accessAmount && + commitDuration == other.commitDuration && + priority == other.priority && + product == other.product && + rateType == other.rateType && + startingAt == other.startingAt && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + contract == other.contract && + description == other.description && + endingBefore == other.endingBefore && + hierarchyConfiguration == other.hierarchyConfiguration && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + proration == other.proration && + recurrenceFrequency == other.recurrenceFrequency && + rolloverFraction == other.rolloverFraction && + specifiers == other.specifiers && + subscriptionConfig == other.subscriptionConfig && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + accessAmount, + commitDuration, + priority, + product, + rateType, + startingAt, + applicableProductIds, + applicableProductTags, + contract, + description, + endingBefore, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + specifiers, + subscriptionConfig, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RecurringCredit{id=$id, accessAmount=$accessAmount, commitDuration=$commitDuration, priority=$priority, product=$product, rateType=$rateType, startingAt=$startingAt, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, contract=$contract, description=$description, endingBefore=$endingBefore, hierarchyConfiguration=$hierarchyConfiguration, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, proration=$proration, recurrenceFrequency=$recurrenceFrequency, rolloverFraction=$rolloverFraction, specifiers=$specifiers, subscriptionConfig=$subscriptionConfig, additionalProperties=$additionalProperties}" + } + + /** + * Determines which scheduled and commit charges to consolidate onto the Contract's + * usage invoice. The charge's `timestamp` must match the usage invoice's + * `ending_before` date for consolidation to occur. This field cannot be modified after + * a Contract has been created. If this field is omitted, charges will appear on a + * separate invoice from usage charges. + */ + class ScheduledChargesOnUsageInvoices + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ALL = of("ALL") + + @JvmStatic + fun of(value: String) = ScheduledChargesOnUsageInvoices(JsonField.of(value)) + } + + /** An enum containing [ScheduledChargesOnUsageInvoices]'s known values. */ + enum class Known { + ALL + } + + /** + * An enum containing [ScheduledChargesOnUsageInvoices]'s known values, as well as + * an [_UNKNOWN] member. + * + * An instance of [ScheduledChargesOnUsageInvoices] can contain an unknown value in + * a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ALL, + /** + * An enum member indicating that [ScheduledChargesOnUsageInvoices] was + * instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ALL -> Value.ALL + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ALL -> Known.ALL + else -> + throw MetronomeInvalidDataException( + "Unknown ScheduledChargesOnUsageInvoices: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ScheduledChargesOnUsageInvoices = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ScheduledChargesOnUsageInvoices && 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 Contract && + id == other.id && + commits == other.commits && + createdAt == other.createdAt && + createdBy == other.createdBy && + customerId == other.customerId && + overrides == other.overrides && + scheduledCharges == other.scheduledCharges && + startingAt == other.startingAt && + transitions == other.transitions && + usageFilter == other.usageFilter && + usageStatementSchedule == other.usageStatementSchedule && + credits == other.credits && + customFields == other.customFields && + customerBillingProviderConfiguration == + other.customerBillingProviderConfiguration && + endingBefore == other.endingBefore && + hasMore == other.hasMore && + hierarchyConfiguration == other.hierarchyConfiguration && + multiplierOverridePrioritization == other.multiplierOverridePrioritization && + name == other.name && + netPaymentTermsDays == other.netPaymentTermsDays && + packageId == other.packageId && + prepaidBalanceThresholdConfiguration == + other.prepaidBalanceThresholdConfiguration && + rateCardId == other.rateCardId && + recurringCommits == other.recurringCommits && + recurringCredits == other.recurringCredits && + scheduledChargesOnUsageInvoices == other.scheduledChargesOnUsageInvoices && + spendThresholdConfiguration == other.spendThresholdConfiguration && + subscriptions == other.subscriptions && + uniquenessKey == other.uniquenessKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + commits, + createdAt, + createdBy, + customerId, + overrides, + scheduledCharges, + startingAt, + transitions, + usageFilter, + usageStatementSchedule, + credits, + customFields, + customerBillingProviderConfiguration, + endingBefore, + hasMore, + hierarchyConfiguration, + multiplierOverridePrioritization, + name, + netPaymentTermsDays, + packageId, + prepaidBalanceThresholdConfiguration, + rateCardId, + recurringCommits, + recurringCredits, + scheduledChargesOnUsageInvoices, + spendThresholdConfiguration, + subscriptions, + uniquenessKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Contract{id=$id, commits=$commits, createdAt=$createdAt, createdBy=$createdBy, customerId=$customerId, overrides=$overrides, scheduledCharges=$scheduledCharges, startingAt=$startingAt, transitions=$transitions, usageFilter=$usageFilter, usageStatementSchedule=$usageStatementSchedule, credits=$credits, customFields=$customFields, customerBillingProviderConfiguration=$customerBillingProviderConfiguration, endingBefore=$endingBefore, hasMore=$hasMore, hierarchyConfiguration=$hierarchyConfiguration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, packageId=$packageId, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && + id == other.id && + contract == other.contract && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, contract, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Data{id=$id, contract=$contract, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageCreateParams.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageCreateParams.kt index a8e596dc..08e45da2 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageCreateParams.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageCreateParams.kt @@ -209,6 +209,12 @@ private constructor( fun spendThresholdConfiguration(): Optional = body.spendThresholdConfiguration() + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = body.spendTrackers() + /** * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -376,6 +382,13 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = body._spendThresholdConfiguration() + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _spendTrackers(): JsonField> = body._spendTrackers() + /** * Returns the raw JSON value of [subscriptions]. * @@ -780,6 +793,30 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { body.spendThresholdConfiguration(spendThresholdConfiguration) } + fun spendTrackers(spendTrackers: List) = apply { + body.spendTrackers(spendTrackers) + } + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + body.spendTrackers(spendTrackers) + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + body.addSpendTracker(spendTracker) + } + fun subscriptions(subscriptions: List) = apply { body.subscriptions(subscriptions) } @@ -1004,6 +1041,7 @@ private constructor( private val scheduledCharges: JsonField>, private val scheduledChargesOnUsageInvoices: JsonField, private val spendThresholdConfiguration: JsonField, + private val spendTrackers: JsonField>, private val subscriptions: JsonField>, private val uniquenessKey: JsonField, private val usageStatementSchedule: JsonField, @@ -1070,6 +1108,9 @@ private constructor( @JsonProperty("spend_threshold_configuration") @ExcludeMissing spendThresholdConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("spend_trackers") + @ExcludeMissing + spendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("subscriptions") @ExcludeMissing subscriptions: JsonField> = JsonMissing.of(), @@ -1099,6 +1140,7 @@ private constructor( scheduledCharges, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, uniquenessKey, usageStatementSchedule, @@ -1247,6 +1289,13 @@ private constructor( fun spendThresholdConfiguration(): Optional = spendThresholdConfiguration.getOptional("spend_threshold_configuration") + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = + spendTrackers.getOptional("spend_trackers") + /** * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). @@ -1448,6 +1497,16 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = spendThresholdConfiguration + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_trackers") + @ExcludeMissing + fun _spendTrackers(): JsonField> = spendTrackers + /** * Returns the raw JSON value of [subscriptions]. * @@ -1532,6 +1591,7 @@ private constructor( JsonMissing.of() private var spendThresholdConfiguration: JsonField = JsonMissing.of() + private var spendTrackers: JsonField>? = null private var subscriptions: JsonField>? = null private var uniquenessKey: JsonField = JsonMissing.of() private var usageStatementSchedule: JsonField = JsonMissing.of() @@ -1558,6 +1618,7 @@ private constructor( scheduledCharges = body.scheduledCharges.map { it.toMutableList() } scheduledChargesOnUsageInvoices = body.scheduledChargesOnUsageInvoices spendThresholdConfiguration = body.spendThresholdConfiguration + spendTrackers = body.spendTrackers.map { it.toMutableList() } subscriptions = body.subscriptions.map { it.toMutableList() } uniquenessKey = body.uniquenessKey usageStatementSchedule = body.usageStatementSchedule @@ -1930,6 +1991,32 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { this.spendThresholdConfiguration = spendThresholdConfiguration } + fun spendTrackers(spendTrackers: List) = + spendTrackers(JsonField.of(spendTrackers)) + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + this.spendTrackers = spendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + spendTrackers = + (spendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("spendTrackers", it).add(spendTracker) + } + } + fun subscriptions(subscriptions: List) = subscriptions(JsonField.of(subscriptions)) @@ -2041,6 +2128,7 @@ private constructor( (scheduledCharges ?: JsonMissing.of()).map { it.toImmutable() }, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + (spendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, (subscriptions ?: JsonMissing.of()).map { it.toImmutable() }, uniquenessKey, usageStatementSchedule, @@ -2083,6 +2171,7 @@ private constructor( scheduledCharges().ifPresent { it.forEach { it.validate() } } scheduledChargesOnUsageInvoices().ifPresent { it.validate() } spendThresholdConfiguration().ifPresent { it.validate() } + spendTrackers().ifPresent { it.forEach { it.validate() } } subscriptions().ifPresent { it.forEach { it.validate() } } uniquenessKey() usageStatementSchedule().ifPresent { it.validate() } @@ -2124,6 +2213,7 @@ private constructor( (scheduledCharges.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (scheduledChargesOnUsageInvoices.asKnown().getOrNull()?.validity() ?: 0) + (spendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (spendTrackers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (subscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (uniquenessKey.asKnown().isPresent) 1 else 0) + (usageStatementSchedule.asKnown().getOrNull()?.validity() ?: 0) @@ -2154,6 +2244,7 @@ private constructor( scheduledCharges == other.scheduledCharges && scheduledChargesOnUsageInvoices == other.scheduledChargesOnUsageInvoices && spendThresholdConfiguration == other.spendThresholdConfiguration && + spendTrackers == other.spendTrackers && subscriptions == other.subscriptions && uniquenessKey == other.uniquenessKey && usageStatementSchedule == other.usageStatementSchedule && @@ -2181,6 +2272,7 @@ private constructor( scheduledCharges, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, uniquenessKey, usageStatementSchedule, @@ -2191,7 +2283,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{name=$name, aliases=$aliases, billingProvider=$billingProvider, commits=$commits, contractName=$contractName, credits=$credits, deliveryMethod=$deliveryMethod, duration=$duration, multiplierOverridePrioritization=$multiplierOverridePrioritization, netPaymentTermsDays=$netPaymentTermsDays, overrides=$overrides, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, rateCardAlias=$rateCardAlias, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, scheduledCharges=$scheduledCharges, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, usageStatementSchedule=$usageStatementSchedule, additionalProperties=$additionalProperties}" + "Body{name=$name, aliases=$aliases, billingProvider=$billingProvider, commits=$commits, contractName=$contractName, credits=$credits, deliveryMethod=$deliveryMethod, duration=$duration, multiplierOverridePrioritization=$multiplierOverridePrioritization, netPaymentTermsDays=$netPaymentTermsDays, overrides=$overrides, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, rateCardAlias=$rateCardAlias, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, scheduledCharges=$scheduledCharges, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, spendTrackers=$spendTrackers, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, usageStatementSchedule=$usageStatementSchedule, additionalProperties=$additionalProperties}" } class Alias @@ -20988,6 +21080,1174 @@ private constructor( override fun toString() = value.toString() } + class SpendTracker + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val alias: JsonField, + private val applicableSpendSpecifiers: JsonField>, + private val creditTypeId: JsonField, + private val resetFrequency: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("alias") @ExcludeMissing alias: JsonField = JsonMissing.of(), + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + applicableSpendSpecifiers: JsonField> = JsonMissing.of(), + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("reset_frequency") + @ExcludeMissing + resetFrequency: JsonField = JsonMissing.of(), + ) : this(alias, applicableSpendSpecifiers, creditTypeId, resetFrequency, mutableMapOf()) + + /** + * Human-readable identifier, unique per contract. + * + * @throws MetronomeInvalidDataException 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 alias(): String = alias.getRequired("alias") + + /** + * @throws MetronomeInvalidDataException 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 applicableSpendSpecifiers(): List = + applicableSpendSpecifiers.getRequired("applicable_spend_specifiers") + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 resetFrequency(): ResetFrequency = resetFrequency.getRequired("reset_frequency") + + /** + * Returns the raw JSON value of [alias]. + * + * Unlike [alias], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("alias") @ExcludeMissing fun _alias(): JsonField = alias + + /** + * Returns the raw JSON value of [applicableSpendSpecifiers]. + * + * Unlike [applicableSpendSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + fun _applicableSpendSpecifiers(): JsonField> = + applicableSpendSpecifiers + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [resetFrequency]. + * + * Unlike [resetFrequency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("reset_frequency") + @ExcludeMissing + fun _resetFrequency(): JsonField = resetFrequency + + @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 [SpendTracker]. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTracker]. */ + class Builder internal constructor() { + + private var alias: JsonField? = null + private var applicableSpendSpecifiers: + JsonField>? = + null + private var creditTypeId: JsonField? = null + private var resetFrequency: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTracker: SpendTracker) = apply { + alias = spendTracker.alias + applicableSpendSpecifiers = + spendTracker.applicableSpendSpecifiers.map { it.toMutableList() } + creditTypeId = spendTracker.creditTypeId + resetFrequency = spendTracker.resetFrequency + additionalProperties = spendTracker.additionalProperties.toMutableMap() + } + + /** Human-readable identifier, unique per contract. */ + fun alias(alias: String) = alias(JsonField.of(alias)) + + /** + * Sets [Builder.alias] to an arbitrary JSON value. + * + * You should usually call [Builder.alias] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun alias(alias: JsonField) = apply { this.alias = alias } + + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: List + ) = applicableSpendSpecifiers(JsonField.of(applicableSpendSpecifiers)) + + /** + * Sets [Builder.applicableSpendSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableSpendSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: JsonField> + ) = apply { + this.applicableSpendSpecifiers = + applicableSpendSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ApplicableSpendSpecifier] to [applicableSpendSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableSpendSpecifier(applicableSpendSpecifier: ApplicableSpendSpecifier) = + apply { + applicableSpendSpecifiers = + (applicableSpendSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableSpendSpecifiers", it) + .add(applicableSpendSpecifier) + } + } + + fun creditTypeId(creditTypeId: String) = creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun resetFrequency(resetFrequency: ResetFrequency) = + resetFrequency(JsonField.of(resetFrequency)) + + /** + * Sets [Builder.resetFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.resetFrequency] with a well-typed [ResetFrequency] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun resetFrequency(resetFrequency: JsonField) = apply { + this.resetFrequency = resetFrequency + } + + 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 [SpendTracker]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTracker = + SpendTracker( + checkRequired("alias", alias), + checkRequired("applicableSpendSpecifiers", applicableSpendSpecifiers).map { + it.toImmutable() + }, + checkRequired("creditTypeId", creditTypeId), + checkRequired("resetFrequency", resetFrequency), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendTracker = apply { + if (validated) { + return@apply + } + + alias() + applicableSpendSpecifiers().forEach { it.validate() } + creditTypeId() + resetFrequency().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (alias.asKnown().isPresent) 1 else 0) + + (applicableSpendSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (creditTypeId.asKnown().isPresent) 1 else 0) + + (resetFrequency.asKnown().getOrNull()?.validity() ?: 0) + + class ApplicableSpendSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sources: JsonField>, + private val spendType: JsonField, + private val discounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("sources") + @ExcludeMissing + sources: JsonField> = JsonMissing.of(), + @JsonProperty("spend_type") + @ExcludeMissing + spendType: JsonField = JsonMissing.of(), + @JsonProperty("discounted") + @ExcludeMissing + discounted: JsonField = JsonMissing.of(), + ) : this(sources, spendType, discounted, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 sources(): List = sources.getRequired("sources") + + /** + * @throws MetronomeInvalidDataException 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 spendType(): SpendType = spendType.getRequired("spend_type") + + /** + * Filter by whether the spend was discounted. Defaults to ANY if omitted. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun discounted(): Optional = discounted.getOptional("discounted") + + /** + * Returns the raw JSON value of [sources]. + * + * Unlike [sources], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sources") + @ExcludeMissing + fun _sources(): JsonField> = sources + + /** + * Returns the raw JSON value of [spendType]. + * + * Unlike [spendType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_type") + @ExcludeMissing + fun _spendType(): JsonField = spendType + + /** + * Returns the raw JSON value of [discounted]. + * + * Unlike [discounted], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("discounted") + @ExcludeMissing + fun _discounted(): JsonField = discounted + + @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 + * [ApplicableSpendSpecifier]. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApplicableSpendSpecifier]. */ + class Builder internal constructor() { + + private var sources: JsonField>? = null + private var spendType: JsonField? = null + private var discounted: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { + sources = applicableSpendSpecifier.sources.map { it.toMutableList() } + spendType = applicableSpendSpecifier.spendType + discounted = applicableSpendSpecifier.discounted + additionalProperties = + applicableSpendSpecifier.additionalProperties.toMutableMap() + } + + fun sources(sources: List) = sources(JsonField.of(sources)) + + /** + * Sets [Builder.sources] to an arbitrary JSON value. + * + * You should usually call [Builder.sources] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun sources(sources: JsonField>) = apply { + this.sources = sources.map { it.toMutableList() } + } + + /** + * Adds a single [Source] to [sources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: Source) = apply { + sources = + (sources ?: JsonField.of(mutableListOf())).also { + checkKnown("sources", it).add(source) + } + } + + fun spendType(spendType: SpendType) = spendType(JsonField.of(spendType)) + + /** + * Sets [Builder.spendType] to an arbitrary JSON value. + * + * You should usually call [Builder.spendType] with a well-typed [SpendType] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendType(spendType: JsonField) = apply { + this.spendType = spendType + } + + /** Filter by whether the spend was discounted. Defaults to ANY if omitted. */ + fun discounted(discounted: Discounted) = discounted(JsonField.of(discounted)) + + /** + * Sets [Builder.discounted] to an arbitrary JSON value. + * + * You should usually call [Builder.discounted] with a well-typed [Discounted] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun discounted(discounted: JsonField) = apply { + this.discounted = discounted + } + + 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 [ApplicableSpendSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApplicableSpendSpecifier = + ApplicableSpendSpecifier( + checkRequired("sources", sources).map { it.toImmutable() }, + checkRequired("spendType", spendType), + discounted, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ApplicableSpendSpecifier = apply { + if (validated) { + return@apply + } + + sources().forEach { it.validate() } + spendType().validate() + discounted().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (sources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendType.asKnown().getOrNull()?.validity() ?: 0) + + (discounted.asKnown().getOrNull()?.validity() ?: 0) + + class Source @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 THRESHOLD_RECHARGE = of("THRESHOLD_RECHARGE") + + @JvmField val MANUAL = of("MANUAL") + + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) + } + + /** An enum containing [Source]'s known values. */ + enum class Known { + THRESHOLD_RECHARGE, + MANUAL, + } + + /** + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Source] 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 { + THRESHOLD_RECHARGE, + MANUAL, + /** + * An enum member indicating that [Source] 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) { + THRESHOLD_RECHARGE -> Value.THRESHOLD_RECHARGE + MANUAL -> Value.MANUAL + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + THRESHOLD_RECHARGE -> Known.THRESHOLD_RECHARGE + MANUAL -> Known.MANUAL + else -> throw MetronomeInvalidDataException("Unknown Source: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Source && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SpendType @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 COMMIT_PURCHASE = of("COMMIT_PURCHASE") + + @JvmStatic fun of(value: String) = SpendType(JsonField.of(value)) + } + + /** An enum containing [SpendType]'s known values. */ + enum class Known { + COMMIT_PURCHASE + } + + /** + * An enum containing [SpendType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SpendType] 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 { + COMMIT_PURCHASE, + /** + * An enum member indicating that [SpendType] 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) { + COMMIT_PURCHASE -> Value.COMMIT_PURCHASE + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + COMMIT_PURCHASE -> Known.COMMIT_PURCHASE + else -> throw MetronomeInvalidDataException("Unknown SpendType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): SpendType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 SpendType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Filter by whether the spend was discounted. Defaults to ANY if omitted. */ + class Discounted + @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 ANY = of("ANY") + + @JvmField val DISCOUNTED_ONLY = of("DISCOUNTED_ONLY") + + @JvmField val UNDISCOUNTED_ONLY = of("UNDISCOUNTED_ONLY") + + @JvmStatic fun of(value: String) = Discounted(JsonField.of(value)) + } + + /** An enum containing [Discounted]'s known values. */ + enum class Known { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + } + + /** + * An enum containing [Discounted]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Discounted] 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 { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + /** + * An enum member indicating that [Discounted] 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) { + ANY -> Value.ANY + DISCOUNTED_ONLY -> Value.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Value.UNDISCOUNTED_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANY -> Known.ANY + DISCOUNTED_ONLY -> Known.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Known.UNDISCOUNTED_ONLY + else -> throw MetronomeInvalidDataException("Unknown Discounted: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Discounted = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Discounted && 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 ApplicableSpendSpecifier && + sources == other.sources && + spendType == other.spendType && + discounted == other.discounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(sources, spendType, discounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ApplicableSpendSpecifier{sources=$sources, spendType=$spendType, discounted=$discounted, additionalProperties=$additionalProperties}" + } + + class ResetFrequency + @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 BILLING_PERIOD = of("BILLING_PERIOD") + + @JvmStatic fun of(value: String) = ResetFrequency(JsonField.of(value)) + } + + /** An enum containing [ResetFrequency]'s known values. */ + enum class Known { + BILLING_PERIOD + } + + /** + * An enum containing [ResetFrequency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ResetFrequency] 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 { + BILLING_PERIOD, + /** + * An enum member indicating that [ResetFrequency] 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) { + BILLING_PERIOD -> Value.BILLING_PERIOD + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + BILLING_PERIOD -> Known.BILLING_PERIOD + else -> throw MetronomeInvalidDataException("Unknown ResetFrequency: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ResetFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ResetFrequency && 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 SpendTracker && + alias == other.alias && + applicableSpendSpecifiers == other.applicableSpendSpecifiers && + creditTypeId == other.creditTypeId && + resetFrequency == other.resetFrequency && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTracker{alias=$alias, applicableSpendSpecifiers=$applicableSpendSpecifiers, creditTypeId=$creditTypeId, resetFrequency=$resetFrequency, additionalProperties=$additionalProperties}" + } + class Subscription @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageListContractsOnPackageParams.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageListContractsOnPackageParams.kt index 7528172b..8e564df3 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageListContractsOnPackageParams.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageListContractsOnPackageParams.kt @@ -32,9 +32,9 @@ import kotlin.jvm.optionals.getOrNull * new package, call this endpoint, end contracts, and provision customers on a new package. * * ### **Usage guidelines:** - * Use the **`starting_at`**, **`covering_date`**, and **`include_archived`** parameters to filter - * the list of returned contracts. For example, to list only currently active contracts, - * pass **`covering_date`** equal to the current time. + * Use the **`starting_at`**, **`covering_date`**, and **`include_archived`** parameters to filter + * the list of returned contracts. For example, to list only currently active contracts, pass + * **`covering_date`** equal to the current time. */ class PackageListContractsOnPackageParams private constructor( diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageListResponse.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageListResponse.kt index 33f1e1f4..d2f9098a 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageListResponse.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageListResponse.kt @@ -54,6 +54,7 @@ private constructor( private val recurringCredits: JsonField>, private val scheduledChargesOnUsageInvoices: JsonField, private val spendThresholdConfiguration: JsonField, + private val spendTrackers: JsonField>, private val subscriptions: JsonField>, private val uniquenessKey: JsonField, private val additionalProperties: MutableMap, @@ -123,6 +124,9 @@ private constructor( @JsonProperty("spend_threshold_configuration") @ExcludeMissing spendThresholdConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("spend_trackers") + @ExcludeMissing + spendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("subscriptions") @ExcludeMissing subscriptions: JsonField> = JsonMissing.of(), @@ -153,6 +157,7 @@ private constructor( recurringCredits, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, uniquenessKey, mutableMapOf(), @@ -317,6 +322,12 @@ private constructor( fun spendThresholdConfiguration(): Optional = spendThresholdConfiguration.getOptional("spend_threshold_configuration") + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = spendTrackers.getOptional("spend_trackers") + /** * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -537,6 +548,15 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = spendThresholdConfiguration + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("spend_trackers") + @ExcludeMissing + fun _spendTrackers(): JsonField> = spendTrackers + /** * Returns the raw JSON value of [subscriptions]. * @@ -617,6 +637,7 @@ private constructor( JsonMissing.of() private var spendThresholdConfiguration: JsonField = JsonMissing.of() + private var spendTrackers: JsonField>? = null private var subscriptions: JsonField>? = null private var uniquenessKey: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -647,6 +668,7 @@ private constructor( recurringCredits = packageListResponse.recurringCredits.map { it.toMutableList() } scheduledChargesOnUsageInvoices = packageListResponse.scheduledChargesOnUsageInvoices spendThresholdConfiguration = packageListResponse.spendThresholdConfiguration + spendTrackers = packageListResponse.spendTrackers.map { it.toMutableList() } subscriptions = packageListResponse.subscriptions.map { it.toMutableList() } uniquenessKey = packageListResponse.uniquenessKey additionalProperties = packageListResponse.additionalProperties.toMutableMap() @@ -1050,6 +1072,32 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { this.spendThresholdConfiguration = spendThresholdConfiguration } + fun spendTrackers(spendTrackers: List) = + spendTrackers(JsonField.of(spendTrackers)) + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + this.spendTrackers = spendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + spendTrackers = + (spendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("spendTrackers", it).add(spendTracker) + } + } + fun subscriptions(subscriptions: List) = subscriptions(JsonField.of(subscriptions)) @@ -1156,6 +1204,7 @@ private constructor( (recurringCredits ?: JsonMissing.of()).map { it.toImmutable() }, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + (spendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, (subscriptions ?: JsonMissing.of()).map { it.toImmutable() }, uniquenessKey, additionalProperties.toMutableMap(), @@ -1200,6 +1249,7 @@ private constructor( recurringCredits().ifPresent { it.forEach { it.validate() } } scheduledChargesOnUsageInvoices().ifPresent { it.validate() } spendThresholdConfiguration().ifPresent { it.validate() } + spendTrackers().ifPresent { it.forEach { it.validate() } } subscriptions().ifPresent { it.forEach { it.validate() } } uniquenessKey() validated = true @@ -1243,6 +1293,7 @@ private constructor( (recurringCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (scheduledChargesOnUsageInvoices.asKnown().getOrNull()?.validity() ?: 0) + (spendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (spendTrackers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (subscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (uniquenessKey.asKnown().isPresent) 1 else 0) @@ -20626,6 +20677,1170 @@ private constructor( override fun toString() = value.toString() } + class SpendTracker + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val alias: JsonField, + private val applicableSpendSpecifiers: JsonField>, + private val creditTypeId: JsonField, + private val resetFrequency: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("alias") @ExcludeMissing alias: JsonField = JsonMissing.of(), + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + applicableSpendSpecifiers: JsonField> = JsonMissing.of(), + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("reset_frequency") + @ExcludeMissing + resetFrequency: JsonField = JsonMissing.of(), + ) : this(alias, applicableSpendSpecifiers, creditTypeId, resetFrequency, mutableMapOf()) + + /** + * Human-readable identifier, unique per contract. + * + * @throws MetronomeInvalidDataException 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 alias(): String = alias.getRequired("alias") + + /** + * @throws MetronomeInvalidDataException 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 applicableSpendSpecifiers(): List = + applicableSpendSpecifiers.getRequired("applicable_spend_specifiers") + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 resetFrequency(): ResetFrequency = resetFrequency.getRequired("reset_frequency") + + /** + * Returns the raw JSON value of [alias]. + * + * Unlike [alias], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("alias") @ExcludeMissing fun _alias(): JsonField = alias + + /** + * Returns the raw JSON value of [applicableSpendSpecifiers]. + * + * Unlike [applicableSpendSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + fun _applicableSpendSpecifiers(): JsonField> = + applicableSpendSpecifiers + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [resetFrequency]. + * + * Unlike [resetFrequency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("reset_frequency") + @ExcludeMissing + fun _resetFrequency(): JsonField = resetFrequency + + @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 [SpendTracker]. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTracker]. */ + class Builder internal constructor() { + + private var alias: JsonField? = null + private var applicableSpendSpecifiers: + JsonField>? = + null + private var creditTypeId: JsonField? = null + private var resetFrequency: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTracker: SpendTracker) = apply { + alias = spendTracker.alias + applicableSpendSpecifiers = + spendTracker.applicableSpendSpecifiers.map { it.toMutableList() } + creditTypeId = spendTracker.creditTypeId + resetFrequency = spendTracker.resetFrequency + additionalProperties = spendTracker.additionalProperties.toMutableMap() + } + + /** Human-readable identifier, unique per contract. */ + fun alias(alias: String) = alias(JsonField.of(alias)) + + /** + * Sets [Builder.alias] to an arbitrary JSON value. + * + * You should usually call [Builder.alias] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun alias(alias: JsonField) = apply { this.alias = alias } + + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: List + ) = applicableSpendSpecifiers(JsonField.of(applicableSpendSpecifiers)) + + /** + * Sets [Builder.applicableSpendSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableSpendSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: JsonField> + ) = apply { + this.applicableSpendSpecifiers = + applicableSpendSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ApplicableSpendSpecifier] to [applicableSpendSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableSpendSpecifier(applicableSpendSpecifier: ApplicableSpendSpecifier) = + apply { + applicableSpendSpecifiers = + (applicableSpendSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableSpendSpecifiers", it) + .add(applicableSpendSpecifier) + } + } + + fun creditTypeId(creditTypeId: String) = creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun resetFrequency(resetFrequency: ResetFrequency) = + resetFrequency(JsonField.of(resetFrequency)) + + /** + * Sets [Builder.resetFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.resetFrequency] with a well-typed [ResetFrequency] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun resetFrequency(resetFrequency: JsonField) = apply { + this.resetFrequency = resetFrequency + } + + 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 [SpendTracker]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTracker = + SpendTracker( + checkRequired("alias", alias), + checkRequired("applicableSpendSpecifiers", applicableSpendSpecifiers).map { + it.toImmutable() + }, + checkRequired("creditTypeId", creditTypeId), + checkRequired("resetFrequency", resetFrequency), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendTracker = apply { + if (validated) { + return@apply + } + + alias() + applicableSpendSpecifiers().forEach { it.validate() } + creditTypeId() + resetFrequency().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (alias.asKnown().isPresent) 1 else 0) + + (applicableSpendSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (creditTypeId.asKnown().isPresent) 1 else 0) + + (resetFrequency.asKnown().getOrNull()?.validity() ?: 0) + + class ApplicableSpendSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sources: JsonField>, + private val spendType: JsonField, + private val discounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("sources") + @ExcludeMissing + sources: JsonField> = JsonMissing.of(), + @JsonProperty("spend_type") + @ExcludeMissing + spendType: JsonField = JsonMissing.of(), + @JsonProperty("discounted") + @ExcludeMissing + discounted: JsonField = JsonMissing.of(), + ) : this(sources, spendType, discounted, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 sources(): List = sources.getRequired("sources") + + /** + * @throws MetronomeInvalidDataException 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 spendType(): SpendType = spendType.getRequired("spend_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun discounted(): Optional = discounted.getOptional("discounted") + + /** + * Returns the raw JSON value of [sources]. + * + * Unlike [sources], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sources") + @ExcludeMissing + fun _sources(): JsonField> = sources + + /** + * Returns the raw JSON value of [spendType]. + * + * Unlike [spendType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_type") + @ExcludeMissing + fun _spendType(): JsonField = spendType + + /** + * Returns the raw JSON value of [discounted]. + * + * Unlike [discounted], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("discounted") + @ExcludeMissing + fun _discounted(): JsonField = discounted + + @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 + * [ApplicableSpendSpecifier]. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApplicableSpendSpecifier]. */ + class Builder internal constructor() { + + private var sources: JsonField>? = null + private var spendType: JsonField? = null + private var discounted: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { + sources = applicableSpendSpecifier.sources.map { it.toMutableList() } + spendType = applicableSpendSpecifier.spendType + discounted = applicableSpendSpecifier.discounted + additionalProperties = + applicableSpendSpecifier.additionalProperties.toMutableMap() + } + + fun sources(sources: List) = sources(JsonField.of(sources)) + + /** + * Sets [Builder.sources] to an arbitrary JSON value. + * + * You should usually call [Builder.sources] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun sources(sources: JsonField>) = apply { + this.sources = sources.map { it.toMutableList() } + } + + /** + * Adds a single [Source] to [sources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: Source) = apply { + sources = + (sources ?: JsonField.of(mutableListOf())).also { + checkKnown("sources", it).add(source) + } + } + + fun spendType(spendType: SpendType) = spendType(JsonField.of(spendType)) + + /** + * Sets [Builder.spendType] to an arbitrary JSON value. + * + * You should usually call [Builder.spendType] with a well-typed [SpendType] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun spendType(spendType: JsonField) = apply { + this.spendType = spendType + } + + fun discounted(discounted: Discounted) = discounted(JsonField.of(discounted)) + + /** + * Sets [Builder.discounted] to an arbitrary JSON value. + * + * You should usually call [Builder.discounted] with a well-typed [Discounted] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun discounted(discounted: JsonField) = apply { + this.discounted = discounted + } + + 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 [ApplicableSpendSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApplicableSpendSpecifier = + ApplicableSpendSpecifier( + checkRequired("sources", sources).map { it.toImmutable() }, + checkRequired("spendType", spendType), + discounted, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ApplicableSpendSpecifier = apply { + if (validated) { + return@apply + } + + sources().forEach { it.validate() } + spendType().validate() + discounted().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (sources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendType.asKnown().getOrNull()?.validity() ?: 0) + + (discounted.asKnown().getOrNull()?.validity() ?: 0) + + class Source @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 THRESHOLD_RECHARGE = of("THRESHOLD_RECHARGE") + + @JvmField val MANUAL = of("MANUAL") + + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) + } + + /** An enum containing [Source]'s known values. */ + enum class Known { + THRESHOLD_RECHARGE, + MANUAL, + } + + /** + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Source] 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 { + THRESHOLD_RECHARGE, + MANUAL, + /** + * An enum member indicating that [Source] 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) { + THRESHOLD_RECHARGE -> Value.THRESHOLD_RECHARGE + MANUAL -> Value.MANUAL + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + THRESHOLD_RECHARGE -> Known.THRESHOLD_RECHARGE + MANUAL -> Known.MANUAL + else -> throw MetronomeInvalidDataException("Unknown Source: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Source && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SpendType @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 COMMIT_PURCHASE = of("COMMIT_PURCHASE") + + @JvmStatic fun of(value: String) = SpendType(JsonField.of(value)) + } + + /** An enum containing [SpendType]'s known values. */ + enum class Known { + COMMIT_PURCHASE + } + + /** + * An enum containing [SpendType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SpendType] 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 { + COMMIT_PURCHASE, + /** + * An enum member indicating that [SpendType] 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) { + COMMIT_PURCHASE -> Value.COMMIT_PURCHASE + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + COMMIT_PURCHASE -> Known.COMMIT_PURCHASE + else -> throw MetronomeInvalidDataException("Unknown SpendType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): SpendType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 SpendType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Discounted + @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 ANY = of("ANY") + + @JvmField val DISCOUNTED_ONLY = of("DISCOUNTED_ONLY") + + @JvmField val UNDISCOUNTED_ONLY = of("UNDISCOUNTED_ONLY") + + @JvmStatic fun of(value: String) = Discounted(JsonField.of(value)) + } + + /** An enum containing [Discounted]'s known values. */ + enum class Known { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + } + + /** + * An enum containing [Discounted]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Discounted] 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 { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + /** + * An enum member indicating that [Discounted] 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) { + ANY -> Value.ANY + DISCOUNTED_ONLY -> Value.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Value.UNDISCOUNTED_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANY -> Known.ANY + DISCOUNTED_ONLY -> Known.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Known.UNDISCOUNTED_ONLY + else -> throw MetronomeInvalidDataException("Unknown Discounted: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Discounted = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Discounted && 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 ApplicableSpendSpecifier && + sources == other.sources && + spendType == other.spendType && + discounted == other.discounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(sources, spendType, discounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ApplicableSpendSpecifier{sources=$sources, spendType=$spendType, discounted=$discounted, additionalProperties=$additionalProperties}" + } + + class ResetFrequency + @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 BILLING_PERIOD = of("BILLING_PERIOD") + + @JvmStatic fun of(value: String) = ResetFrequency(JsonField.of(value)) + } + + /** An enum containing [ResetFrequency]'s known values. */ + enum class Known { + BILLING_PERIOD + } + + /** + * An enum containing [ResetFrequency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ResetFrequency] 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 { + BILLING_PERIOD, + /** + * An enum member indicating that [ResetFrequency] 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) { + BILLING_PERIOD -> Value.BILLING_PERIOD + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + BILLING_PERIOD -> Known.BILLING_PERIOD + else -> throw MetronomeInvalidDataException("Unknown ResetFrequency: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ResetFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ResetFrequency && 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 SpendTracker && + alias == other.alias && + applicableSpendSpecifiers == other.applicableSpendSpecifiers && + creditTypeId == other.creditTypeId && + resetFrequency == other.resetFrequency && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTracker{alias=$alias, applicableSpendSpecifiers=$applicableSpendSpecifiers, creditTypeId=$creditTypeId, resetFrequency=$resetFrequency, additionalProperties=$additionalProperties}" + } + class Subscription @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -23620,6 +24835,7 @@ private constructor( recurringCredits == other.recurringCredits && scheduledChargesOnUsageInvoices == other.scheduledChargesOnUsageInvoices && spendThresholdConfiguration == other.spendThresholdConfiguration && + spendTrackers == other.spendTrackers && subscriptions == other.subscriptions && uniquenessKey == other.uniquenessKey && additionalProperties == other.additionalProperties @@ -23650,6 +24866,7 @@ private constructor( recurringCredits, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, uniquenessKey, additionalProperties, @@ -23659,5 +24876,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "PackageListResponse{id=$id, commits=$commits, createdAt=$createdAt, createdBy=$createdBy, overrides=$overrides, scheduledCharges=$scheduledCharges, usageStatementSchedule=$usageStatementSchedule, aliases=$aliases, archivedAt=$archivedAt, billingProvider=$billingProvider, contractName=$contractName, credits=$credits, deliveryMethod=$deliveryMethod, duration=$duration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" + "PackageListResponse{id=$id, commits=$commits, createdAt=$createdAt, createdBy=$createdBy, overrides=$overrides, scheduledCharges=$scheduledCharges, usageStatementSchedule=$usageStatementSchedule, aliases=$aliases, archivedAt=$archivedAt, billingProvider=$billingProvider, contractName=$contractName, credits=$credits, deliveryMethod=$deliveryMethod, duration=$duration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, spendTrackers=$spendTrackers, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" } diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageRetrieveResponse.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageRetrieveResponse.kt index f3d43eef..e06df0c8 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageRetrieveResponse.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/packages/PackageRetrieveResponse.kt @@ -198,6 +198,7 @@ private constructor( private val recurringCredits: JsonField>, private val scheduledChargesOnUsageInvoices: JsonField, private val spendThresholdConfiguration: JsonField, + private val spendTrackers: JsonField>, private val subscriptions: JsonField>, private val uniquenessKey: JsonField, private val additionalProperties: MutableMap, @@ -273,6 +274,9 @@ private constructor( @JsonProperty("spend_threshold_configuration") @ExcludeMissing spendThresholdConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("spend_trackers") + @ExcludeMissing + spendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("subscriptions") @ExcludeMissing subscriptions: JsonField> = JsonMissing.of(), @@ -303,6 +307,7 @@ private constructor( recurringCredits, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, uniquenessKey, mutableMapOf(), @@ -470,6 +475,13 @@ private constructor( fun spendThresholdConfiguration(): Optional = spendThresholdConfiguration.getOptional("spend_threshold_configuration") + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun spendTrackers(): Optional> = + spendTrackers.getOptional("spend_trackers") + /** * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). @@ -696,6 +708,16 @@ private constructor( fun _spendThresholdConfiguration(): JsonField = spendThresholdConfiguration + /** + * Returns the raw JSON value of [spendTrackers]. + * + * Unlike [spendTrackers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_trackers") + @ExcludeMissing + fun _spendTrackers(): JsonField> = spendTrackers + /** * Returns the raw JSON value of [subscriptions]. * @@ -780,6 +802,7 @@ private constructor( JsonMissing.of() private var spendThresholdConfiguration: JsonField = JsonMissing.of() + private var spendTrackers: JsonField>? = null private var subscriptions: JsonField>? = null private var uniquenessKey: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -809,6 +832,7 @@ private constructor( recurringCredits = data.recurringCredits.map { it.toMutableList() } scheduledChargesOnUsageInvoices = data.scheduledChargesOnUsageInvoices spendThresholdConfiguration = data.spendThresholdConfiguration + spendTrackers = data.spendTrackers.map { it.toMutableList() } subscriptions = data.subscriptions.map { it.toMutableList() } uniquenessKey = data.uniquenessKey additionalProperties = data.additionalProperties.toMutableMap() @@ -1222,6 +1246,32 @@ private constructor( spendThresholdConfiguration: JsonField ) = apply { this.spendThresholdConfiguration = spendThresholdConfiguration } + fun spendTrackers(spendTrackers: List) = + spendTrackers(JsonField.of(spendTrackers)) + + /** + * Sets [Builder.spendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackers] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun spendTrackers(spendTrackers: JsonField>) = apply { + this.spendTrackers = spendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [SpendTracker] to [spendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpendTracker(spendTracker: SpendTracker) = apply { + spendTrackers = + (spendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("spendTrackers", it).add(spendTracker) + } + } + fun subscriptions(subscriptions: List) = subscriptions(JsonField.of(subscriptions)) @@ -1328,6 +1378,7 @@ private constructor( (recurringCredits ?: JsonMissing.of()).map { it.toImmutable() }, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + (spendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, (subscriptions ?: JsonMissing.of()).map { it.toImmutable() }, uniquenessKey, additionalProperties.toMutableMap(), @@ -1373,6 +1424,7 @@ private constructor( recurringCredits().ifPresent { it.forEach { it.validate() } } scheduledChargesOnUsageInvoices().ifPresent { it.validate() } spendThresholdConfiguration().ifPresent { it.validate() } + spendTrackers().ifPresent { it.forEach { it.validate() } } subscriptions().ifPresent { it.forEach { it.validate() } } uniquenessKey() validated = true @@ -1417,6 +1469,7 @@ private constructor( (recurringCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (scheduledChargesOnUsageInvoices.asKnown().getOrNull()?.validity() ?: 0) + (spendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (spendTrackers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (subscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (uniquenessKey.asKnown().isPresent) 1 else 0) @@ -21200,6 +21253,1197 @@ private constructor( override fun toString() = value.toString() } + class SpendTracker + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val alias: JsonField, + private val applicableSpendSpecifiers: JsonField>, + private val creditTypeId: JsonField, + private val resetFrequency: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("alias") @ExcludeMissing alias: JsonField = JsonMissing.of(), + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + applicableSpendSpecifiers: JsonField> = + JsonMissing.of(), + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("reset_frequency") + @ExcludeMissing + resetFrequency: JsonField = JsonMissing.of(), + ) : this(alias, applicableSpendSpecifiers, creditTypeId, resetFrequency, mutableMapOf()) + + /** + * Human-readable identifier, unique per contract. + * + * @throws MetronomeInvalidDataException 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 alias(): String = alias.getRequired("alias") + + /** + * @throws MetronomeInvalidDataException 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 applicableSpendSpecifiers(): List = + applicableSpendSpecifiers.getRequired("applicable_spend_specifiers") + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 resetFrequency(): ResetFrequency = resetFrequency.getRequired("reset_frequency") + + /** + * Returns the raw JSON value of [alias]. + * + * Unlike [alias], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("alias") @ExcludeMissing fun _alias(): JsonField = alias + + /** + * Returns the raw JSON value of [applicableSpendSpecifiers]. + * + * Unlike [applicableSpendSpecifiers], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_spend_specifiers") + @ExcludeMissing + fun _applicableSpendSpecifiers(): JsonField> = + applicableSpendSpecifiers + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [resetFrequency]. + * + * Unlike [resetFrequency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reset_frequency") + @ExcludeMissing + fun _resetFrequency(): JsonField = resetFrequency + + @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 [SpendTracker]. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTracker]. */ + class Builder internal constructor() { + + private var alias: JsonField? = null + private var applicableSpendSpecifiers: + JsonField>? = + null + private var creditTypeId: JsonField? = null + private var resetFrequency: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTracker: SpendTracker) = apply { + alias = spendTracker.alias + applicableSpendSpecifiers = + spendTracker.applicableSpendSpecifiers.map { it.toMutableList() } + creditTypeId = spendTracker.creditTypeId + resetFrequency = spendTracker.resetFrequency + additionalProperties = spendTracker.additionalProperties.toMutableMap() + } + + /** Human-readable identifier, unique per contract. */ + fun alias(alias: String) = alias(JsonField.of(alias)) + + /** + * Sets [Builder.alias] to an arbitrary JSON value. + * + * You should usually call [Builder.alias] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun alias(alias: JsonField) = apply { this.alias = alias } + + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: List + ) = applicableSpendSpecifiers(JsonField.of(applicableSpendSpecifiers)) + + /** + * Sets [Builder.applicableSpendSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableSpendSpecifiers] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: JsonField> + ) = apply { + this.applicableSpendSpecifiers = + applicableSpendSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ApplicableSpendSpecifier] to [applicableSpendSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableSpendSpecifier( + applicableSpendSpecifier: ApplicableSpendSpecifier + ) = apply { + applicableSpendSpecifiers = + (applicableSpendSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableSpendSpecifiers", it) + .add(applicableSpendSpecifier) + } + } + + fun creditTypeId(creditTypeId: String) = creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun resetFrequency(resetFrequency: ResetFrequency) = + resetFrequency(JsonField.of(resetFrequency)) + + /** + * Sets [Builder.resetFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.resetFrequency] with a well-typed + * [ResetFrequency] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun resetFrequency(resetFrequency: JsonField) = apply { + this.resetFrequency = resetFrequency + } + + 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 [SpendTracker]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTracker = + SpendTracker( + checkRequired("alias", alias), + checkRequired("applicableSpendSpecifiers", applicableSpendSpecifiers).map { + it.toImmutable() + }, + checkRequired("creditTypeId", creditTypeId), + checkRequired("resetFrequency", resetFrequency), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SpendTracker = apply { + if (validated) { + return@apply + } + + alias() + applicableSpendSpecifiers().forEach { it.validate() } + creditTypeId() + resetFrequency().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (alias.asKnown().isPresent) 1 else 0) + + (applicableSpendSpecifiers.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + (if (creditTypeId.asKnown().isPresent) 1 else 0) + + (resetFrequency.asKnown().getOrNull()?.validity() ?: 0) + + class ApplicableSpendSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sources: JsonField>, + private val spendType: JsonField, + private val discounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("sources") + @ExcludeMissing + sources: JsonField> = JsonMissing.of(), + @JsonProperty("spend_type") + @ExcludeMissing + spendType: JsonField = JsonMissing.of(), + @JsonProperty("discounted") + @ExcludeMissing + discounted: JsonField = JsonMissing.of(), + ) : this(sources, spendType, discounted, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 sources(): List = sources.getRequired("sources") + + /** + * @throws MetronomeInvalidDataException 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 spendType(): SpendType = spendType.getRequired("spend_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun discounted(): Optional = discounted.getOptional("discounted") + + /** + * Returns the raw JSON value of [sources]. + * + * Unlike [sources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("sources") + @ExcludeMissing + fun _sources(): JsonField> = sources + + /** + * Returns the raw JSON value of [spendType]. + * + * Unlike [spendType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("spend_type") + @ExcludeMissing + fun _spendType(): JsonField = spendType + + /** + * Returns the raw JSON value of [discounted]. + * + * Unlike [discounted], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("discounted") + @ExcludeMissing + fun _discounted(): JsonField = discounted + + @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 + * [ApplicableSpendSpecifier]. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApplicableSpendSpecifier]. */ + class Builder internal constructor() { + + private var sources: JsonField>? = null + private var spendType: JsonField? = null + private var discounted: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { + sources = applicableSpendSpecifier.sources.map { it.toMutableList() } + spendType = applicableSpendSpecifier.spendType + discounted = applicableSpendSpecifier.discounted + additionalProperties = + applicableSpendSpecifier.additionalProperties.toMutableMap() + } + + fun sources(sources: List) = sources(JsonField.of(sources)) + + /** + * Sets [Builder.sources] to an arbitrary JSON value. + * + * You should usually call [Builder.sources] with a well-typed `List` + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun sources(sources: JsonField>) = apply { + this.sources = sources.map { it.toMutableList() } + } + + /** + * Adds a single [Source] to [sources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: Source) = apply { + sources = + (sources ?: JsonField.of(mutableListOf())).also { + checkKnown("sources", it).add(source) + } + } + + fun spendType(spendType: SpendType) = spendType(JsonField.of(spendType)) + + /** + * Sets [Builder.spendType] to an arbitrary JSON value. + * + * You should usually call [Builder.spendType] with a well-typed [SpendType] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun spendType(spendType: JsonField) = apply { + this.spendType = spendType + } + + fun discounted(discounted: Discounted) = discounted(JsonField.of(discounted)) + + /** + * Sets [Builder.discounted] to an arbitrary JSON value. + * + * You should usually call [Builder.discounted] with a well-typed [Discounted] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun discounted(discounted: JsonField) = apply { + this.discounted = discounted + } + + 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 [ApplicableSpendSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApplicableSpendSpecifier = + ApplicableSpendSpecifier( + checkRequired("sources", sources).map { it.toImmutable() }, + checkRequired("spendType", spendType), + discounted, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ApplicableSpendSpecifier = apply { + if (validated) { + return@apply + } + + sources().forEach { it.validate() } + spendType().validate() + discounted().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (sources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendType.asKnown().getOrNull()?.validity() ?: 0) + + (discounted.asKnown().getOrNull()?.validity() ?: 0) + + class Source + @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 THRESHOLD_RECHARGE = of("THRESHOLD_RECHARGE") + + @JvmField val MANUAL = of("MANUAL") + + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) + } + + /** An enum containing [Source]'s known values. */ + enum class Known { + THRESHOLD_RECHARGE, + MANUAL, + } + + /** + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Source] 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 { + THRESHOLD_RECHARGE, + MANUAL, + /** + * An enum member indicating that [Source] 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) { + THRESHOLD_RECHARGE -> Value.THRESHOLD_RECHARGE + MANUAL -> Value.MANUAL + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + THRESHOLD_RECHARGE -> Known.THRESHOLD_RECHARGE + MANUAL -> Known.MANUAL + else -> throw MetronomeInvalidDataException("Unknown Source: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Source && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SpendType + @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 COMMIT_PURCHASE = of("COMMIT_PURCHASE") + + @JvmStatic fun of(value: String) = SpendType(JsonField.of(value)) + } + + /** An enum containing [SpendType]'s known values. */ + enum class Known { + COMMIT_PURCHASE + } + + /** + * An enum containing [SpendType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [SpendType] 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 { + COMMIT_PURCHASE, + /** + * An enum member indicating that [SpendType] 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) { + COMMIT_PURCHASE -> Value.COMMIT_PURCHASE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_PURCHASE -> Known.COMMIT_PURCHASE + else -> throw MetronomeInvalidDataException("Unknown SpendType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): SpendType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 SpendType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Discounted + @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 ANY = of("ANY") + + @JvmField val DISCOUNTED_ONLY = of("DISCOUNTED_ONLY") + + @JvmField val UNDISCOUNTED_ONLY = of("UNDISCOUNTED_ONLY") + + @JvmStatic fun of(value: String) = Discounted(JsonField.of(value)) + } + + /** An enum containing [Discounted]'s known values. */ + enum class Known { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + } + + /** + * An enum containing [Discounted]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Discounted] 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 { + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, + /** + * An enum member indicating that [Discounted] 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) { + ANY -> Value.ANY + DISCOUNTED_ONLY -> Value.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Value.UNDISCOUNTED_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + ANY -> Known.ANY + DISCOUNTED_ONLY -> Known.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Known.UNDISCOUNTED_ONLY + else -> + throw MetronomeInvalidDataException("Unknown Discounted: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Discounted = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Discounted && 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 ApplicableSpendSpecifier && + sources == other.sources && + spendType == other.spendType && + discounted == other.discounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(sources, spendType, discounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ApplicableSpendSpecifier{sources=$sources, spendType=$spendType, discounted=$discounted, additionalProperties=$additionalProperties}" + } + + class ResetFrequency + @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 BILLING_PERIOD = of("BILLING_PERIOD") + + @JvmStatic fun of(value: String) = ResetFrequency(JsonField.of(value)) + } + + /** An enum containing [ResetFrequency]'s known values. */ + enum class Known { + BILLING_PERIOD + } + + /** + * An enum containing [ResetFrequency]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ResetFrequency] 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 { + BILLING_PERIOD, + /** + * An enum member indicating that [ResetFrequency] 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) { + BILLING_PERIOD -> Value.BILLING_PERIOD + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + BILLING_PERIOD -> Known.BILLING_PERIOD + else -> + throw MetronomeInvalidDataException("Unknown ResetFrequency: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ResetFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ResetFrequency && 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 SpendTracker && + alias == other.alias && + applicableSpendSpecifiers == other.applicableSpendSpecifiers && + creditTypeId == other.creditTypeId && + resetFrequency == other.resetFrequency && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTracker{alias=$alias, applicableSpendSpecifiers=$applicableSpendSpecifiers, creditTypeId=$creditTypeId, resetFrequency=$resetFrequency, additionalProperties=$additionalProperties}" + } + class Subscription @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -24259,6 +25503,7 @@ private constructor( recurringCredits == other.recurringCredits && scheduledChargesOnUsageInvoices == other.scheduledChargesOnUsageInvoices && spendThresholdConfiguration == other.spendThresholdConfiguration && + spendTrackers == other.spendTrackers && subscriptions == other.subscriptions && uniquenessKey == other.uniquenessKey && additionalProperties == other.additionalProperties @@ -24289,6 +25534,7 @@ private constructor( recurringCredits, scheduledChargesOnUsageInvoices, spendThresholdConfiguration, + spendTrackers, subscriptions, uniquenessKey, additionalProperties, @@ -24298,7 +25544,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Data{id=$id, commits=$commits, createdAt=$createdAt, createdBy=$createdBy, overrides=$overrides, scheduledCharges=$scheduledCharges, usageStatementSchedule=$usageStatementSchedule, aliases=$aliases, archivedAt=$archivedAt, billingProvider=$billingProvider, contractName=$contractName, credits=$credits, deliveryMethod=$deliveryMethod, duration=$duration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" + "Data{id=$id, commits=$commits, createdAt=$createdAt, createdBy=$createdBy, overrides=$overrides, scheduledCharges=$scheduledCharges, usageStatementSchedule=$usageStatementSchedule, aliases=$aliases, archivedAt=$archivedAt, billingProvider=$billingProvider, contractName=$contractName, credits=$credits, deliveryMethod=$deliveryMethod, duration=$duration, multiplierOverridePrioritization=$multiplierOverridePrioritization, name=$name, netPaymentTermsDays=$netPaymentTermsDays, prepaidBalanceThresholdConfiguration=$prepaidBalanceThresholdConfiguration, rateCardId=$rateCardId, recurringCommits=$recurringCommits, recurringCredits=$recurringCredits, scheduledChargesOnUsageInvoices=$scheduledChargesOnUsageInvoices, spendThresholdConfiguration=$spendThresholdConfiguration, spendTrackers=$spendTrackers, subscriptions=$subscriptions, uniquenessKey=$uniquenessKey, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/Payment.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/Payment.kt deleted file mode 100644 index 2e7ac579..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/Payment.kt +++ /dev/null @@ -1,1786 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.metronome.api.core.Enum -import com.metronome.api.core.ExcludeMissing -import com.metronome.api.core.JsonField -import com.metronome.api.core.JsonMissing -import com.metronome.api.core.JsonValue -import com.metronome.api.core.checkKnown -import com.metronome.api.core.checkRequired -import com.metronome.api.core.toImmutable -import com.metronome.api.errors.MetronomeInvalidDataException -import com.metronome.api.models.CreditTypeData -import java.time.OffsetDateTime -import java.util.Collections -import java.util.Objects -import java.util.Optional -import kotlin.jvm.optionals.getOrNull - -class Payment -@JsonCreator(mode = JsonCreator.Mode.DISABLED) -private constructor( - private val id: JsonField, - private val amount: JsonField, - private val amountPaid: JsonField, - private val contractId: JsonField, - private val createdAt: JsonField, - private val customerId: JsonField, - private val errorMessage: JsonField, - private val fiatCreditType: JsonField, - private val invoiceId: JsonField, - private val paymentGateway: JsonField, - private val revenueSystemPayments: JsonField>, - private val status: JsonField, - private val updatedAt: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("amount_paid") - @ExcludeMissing - amountPaid: JsonField = JsonMissing.of(), - @JsonProperty("contract_id") - @ExcludeMissing - contractId: JsonField = JsonMissing.of(), - @JsonProperty("created_at") - @ExcludeMissing - createdAt: JsonField = JsonMissing.of(), - @JsonProperty("customer_id") - @ExcludeMissing - customerId: JsonField = JsonMissing.of(), - @JsonProperty("error_message") - @ExcludeMissing - errorMessage: JsonField = JsonMissing.of(), - @JsonProperty("fiat_credit_type") - @ExcludeMissing - fiatCreditType: JsonField = JsonMissing.of(), - @JsonProperty("invoice_id") @ExcludeMissing invoiceId: JsonField = JsonMissing.of(), - @JsonProperty("payment_gateway") - @ExcludeMissing - paymentGateway: JsonField = JsonMissing.of(), - @JsonProperty("revenue_system_payments") - @ExcludeMissing - revenueSystemPayments: JsonField> = JsonMissing.of(), - @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), - @JsonProperty("updated_at") - @ExcludeMissing - updatedAt: JsonField = JsonMissing.of(), - ) : this( - id, - amount, - amountPaid, - contractId, - createdAt, - customerId, - errorMessage, - fiatCreditType, - invoiceId, - paymentGateway, - revenueSystemPayments, - status, - updatedAt, - mutableMapOf(), - ) - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun id(): String = id.getRequired("id") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun amount(): Optional = amount.getOptional("amount") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun amountPaid(): Optional = amountPaid.getOptional("amount_paid") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun contractId(): Optional = contractId.getOptional("contract_id") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun createdAt(): Optional = createdAt.getOptional("created_at") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun customerId(): Optional = customerId.getOptional("customer_id") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun errorMessage(): Optional = errorMessage.getOptional("error_message") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun fiatCreditType(): Optional = fiatCreditType.getOptional("fiat_credit_type") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun invoiceId(): Optional = invoiceId.getOptional("invoice_id") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun paymentGateway(): Optional = paymentGateway.getOptional("payment_gateway") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun revenueSystemPayments(): Optional> = - revenueSystemPayments.getOptional("revenue_system_payments") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun status(): Optional = status.getOptional("status") - - /** - * @throws MetronomeInvalidDataException 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") - - /** - * Returns the raw JSON value of [id]. - * - * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - - /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount - - /** - * Returns the raw JSON value of [amountPaid]. - * - * Unlike [amountPaid], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("amount_paid") @ExcludeMissing fun _amountPaid(): JsonField = amountPaid - - /** - * Returns the raw JSON value of [contractId]. - * - * Unlike [contractId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("contract_id") @ExcludeMissing fun _contractId(): JsonField = contractId - - /** - * Returns the raw JSON value of [createdAt]. - * - * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("created_at") - @ExcludeMissing - fun _createdAt(): JsonField = createdAt - - /** - * Returns the raw JSON value of [customerId]. - * - * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("customer_id") @ExcludeMissing fun _customerId(): JsonField = customerId - - /** - * Returns the raw JSON value of [errorMessage]. - * - * Unlike [errorMessage], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("error_message") - @ExcludeMissing - fun _errorMessage(): JsonField = errorMessage - - /** - * Returns the raw JSON value of [fiatCreditType]. - * - * Unlike [fiatCreditType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("fiat_credit_type") - @ExcludeMissing - fun _fiatCreditType(): JsonField = fiatCreditType - - /** - * Returns the raw JSON value of [invoiceId]. - * - * Unlike [invoiceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("invoice_id") @ExcludeMissing fun _invoiceId(): JsonField = invoiceId - - /** - * Returns the raw JSON value of [paymentGateway]. - * - * Unlike [paymentGateway], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("payment_gateway") - @ExcludeMissing - fun _paymentGateway(): JsonField = paymentGateway - - /** - * Returns the raw JSON value of [revenueSystemPayments]. - * - * Unlike [revenueSystemPayments], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("revenue_system_payments") - @ExcludeMissing - fun _revenueSystemPayments(): JsonField> = revenueSystemPayments - - /** - * Returns the raw JSON value of [status]. - * - * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status - - /** - * 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 - - @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 [Payment]. - * - * The following fields are required: - * ```java - * .id() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Payment]. */ - class Builder internal constructor() { - - private var id: JsonField? = null - private var amount: JsonField = JsonMissing.of() - private var amountPaid: JsonField = JsonMissing.of() - private var contractId: JsonField = JsonMissing.of() - private var createdAt: JsonField = JsonMissing.of() - private var customerId: JsonField = JsonMissing.of() - private var errorMessage: JsonField = JsonMissing.of() - private var fiatCreditType: JsonField = JsonMissing.of() - private var invoiceId: JsonField = JsonMissing.of() - private var paymentGateway: JsonField = JsonMissing.of() - private var revenueSystemPayments: JsonField>? = null - private var status: JsonField = JsonMissing.of() - private var updatedAt: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(payment: Payment) = apply { - id = payment.id - amount = payment.amount - amountPaid = payment.amountPaid - contractId = payment.contractId - createdAt = payment.createdAt - customerId = payment.customerId - errorMessage = payment.errorMessage - fiatCreditType = payment.fiatCreditType - invoiceId = payment.invoiceId - paymentGateway = payment.paymentGateway - revenueSystemPayments = payment.revenueSystemPayments.map { it.toMutableList() } - status = payment.status - updatedAt = payment.updatedAt - additionalProperties = payment.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 amount(amount: Double) = amount(JsonField.of(amount)) - - /** - * Sets [Builder.amount] to an arbitrary JSON value. - * - * You should usually call [Builder.amount] with a well-typed [Double] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun amount(amount: JsonField) = apply { this.amount = amount } - - fun amountPaid(amountPaid: Double) = amountPaid(JsonField.of(amountPaid)) - - /** - * Sets [Builder.amountPaid] to an arbitrary JSON value. - * - * You should usually call [Builder.amountPaid] with a well-typed [Double] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun amountPaid(amountPaid: JsonField) = apply { this.amountPaid = amountPaid } - - fun contractId(contractId: String) = contractId(JsonField.of(contractId)) - - /** - * Sets [Builder.contractId] to an arbitrary JSON value. - * - * You should usually call [Builder.contractId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun contractId(contractId: JsonField) = apply { this.contractId = contractId } - - fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) - - /** - * Sets [Builder.createdAt] to an arbitrary JSON value. - * - * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } - - fun customerId(customerId: String) = customerId(JsonField.of(customerId)) - - /** - * Sets [Builder.customerId] to an arbitrary JSON value. - * - * You should usually call [Builder.customerId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun customerId(customerId: JsonField) = apply { this.customerId = customerId } - - fun errorMessage(errorMessage: String) = errorMessage(JsonField.of(errorMessage)) - - /** - * Sets [Builder.errorMessage] to an arbitrary JSON value. - * - * You should usually call [Builder.errorMessage] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun errorMessage(errorMessage: JsonField) = apply { - this.errorMessage = errorMessage - } - - fun fiatCreditType(fiatCreditType: CreditTypeData) = - fiatCreditType(JsonField.of(fiatCreditType)) - - /** - * Sets [Builder.fiatCreditType] to an arbitrary JSON value. - * - * You should usually call [Builder.fiatCreditType] with a well-typed [CreditTypeData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fiatCreditType(fiatCreditType: JsonField) = apply { - this.fiatCreditType = fiatCreditType - } - - fun invoiceId(invoiceId: String) = invoiceId(JsonField.of(invoiceId)) - - /** - * Sets [Builder.invoiceId] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun invoiceId(invoiceId: JsonField) = apply { this.invoiceId = invoiceId } - - fun paymentGateway(paymentGateway: PaymentGateway) = - paymentGateway(JsonField.of(paymentGateway)) - - /** - * Sets [Builder.paymentGateway] to an arbitrary JSON value. - * - * You should usually call [Builder.paymentGateway] with a well-typed [PaymentGateway] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun paymentGateway(paymentGateway: JsonField) = apply { - this.paymentGateway = paymentGateway - } - - fun revenueSystemPayments(revenueSystemPayments: List) = - revenueSystemPayments(JsonField.of(revenueSystemPayments)) - - /** - * Sets [Builder.revenueSystemPayments] to an arbitrary JSON value. - * - * You should usually call [Builder.revenueSystemPayments] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun revenueSystemPayments(revenueSystemPayments: JsonField>) = - apply { - this.revenueSystemPayments = revenueSystemPayments.map { it.toMutableList() } - } - - /** - * Adds a single [RevenueSystemPayment] to [revenueSystemPayments]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addRevenueSystemPayment(revenueSystemPayment: RevenueSystemPayment) = apply { - revenueSystemPayments = - (revenueSystemPayments ?: JsonField.of(mutableListOf())).also { - checkKnown("revenueSystemPayments", it).add(revenueSystemPayment) - } - } - - fun status(status: PaymentStatus) = status(JsonField.of(status)) - - /** - * Sets [Builder.status] to an arbitrary JSON value. - * - * You should usually call [Builder.status] with a well-typed [PaymentStatus] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun status(status: JsonField) = apply { this.status = status } - - fun updatedAt(updatedAt: OffsetDateTime) = updatedAt(JsonField.of(updatedAt)) - - /** - * Sets [Builder.updatedAt] to an arbitrary JSON value. - * - * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] 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 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 [Payment]. - * - * 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(): Payment = - Payment( - checkRequired("id", id), - amount, - amountPaid, - contractId, - createdAt, - customerId, - errorMessage, - fiatCreditType, - invoiceId, - paymentGateway, - (revenueSystemPayments ?: JsonMissing.of()).map { it.toImmutable() }, - status, - updatedAt, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): Payment = apply { - if (validated) { - return@apply - } - - id() - amount() - amountPaid() - contractId() - createdAt() - customerId() - errorMessage() - fiatCreditType().ifPresent { it.validate() } - invoiceId() - paymentGateway().ifPresent { it.validate() } - revenueSystemPayments().ifPresent { it.forEach { it.validate() } } - status().ifPresent { it.validate() } - updatedAt() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (if (id.asKnown().isPresent) 1 else 0) + - (if (amount.asKnown().isPresent) 1 else 0) + - (if (amountPaid.asKnown().isPresent) 1 else 0) + - (if (contractId.asKnown().isPresent) 1 else 0) + - (if (createdAt.asKnown().isPresent) 1 else 0) + - (if (customerId.asKnown().isPresent) 1 else 0) + - (if (errorMessage.asKnown().isPresent) 1 else 0) + - (fiatCreditType.asKnown().getOrNull()?.validity() ?: 0) + - (if (invoiceId.asKnown().isPresent) 1 else 0) + - (paymentGateway.asKnown().getOrNull()?.validity() ?: 0) + - (revenueSystemPayments.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (status.asKnown().getOrNull()?.validity() ?: 0) + - (if (updatedAt.asKnown().isPresent) 1 else 0) - - class PaymentGateway - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val stripe: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("stripe") @ExcludeMissing stripe: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(stripe, type, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException 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 stripe(): Stripe = stripe.getRequired("stripe") - - /** - * @throws MetronomeInvalidDataException 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 type(): Type = type.getRequired("type") - - /** - * Returns the raw JSON value of [stripe]. - * - * Unlike [stripe], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("stripe") @ExcludeMissing fun _stripe(): JsonField = stripe - - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [PaymentGateway]. - * - * The following fields are required: - * ```java - * .stripe() - * .type() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentGateway]. */ - class Builder internal constructor() { - - private var stripe: JsonField? = null - private var type: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(paymentGateway: PaymentGateway) = apply { - stripe = paymentGateway.stripe - type = paymentGateway.type - additionalProperties = paymentGateway.additionalProperties.toMutableMap() - } - - fun stripe(stripe: Stripe) = stripe(JsonField.of(stripe)) - - /** - * Sets [Builder.stripe] to an arbitrary JSON value. - * - * You should usually call [Builder.stripe] with a well-typed [Stripe] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun stripe(stripe: JsonField) = apply { this.stripe = stripe } - - fun type(type: Type) = type(JsonField.of(type)) - - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun type(type: JsonField) = apply { this.type = type } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [PaymentGateway]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .stripe() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentGateway = - PaymentGateway( - checkRequired("stripe", stripe), - checkRequired("type", type), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): PaymentGateway = apply { - if (validated) { - return@apply - } - - stripe().validate() - type().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 = - (stripe.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - class Stripe - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val paymentIntentId: JsonField, - private val error: JsonField, - private val paymentMethodId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("payment_intent_id") - @ExcludeMissing - paymentIntentId: JsonField = JsonMissing.of(), - @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), - @JsonProperty("payment_method_id") - @ExcludeMissing - paymentMethodId: JsonField = JsonMissing.of(), - ) : this(paymentIntentId, error, paymentMethodId, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException 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 paymentIntentId(): String = paymentIntentId.getRequired("payment_intent_id") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun error(): Optional = error.getOptional("error") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun paymentMethodId(): Optional = - paymentMethodId.getOptional("payment_method_id") - - /** - * Returns the raw JSON value of [paymentIntentId]. - * - * Unlike [paymentIntentId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("payment_intent_id") - @ExcludeMissing - fun _paymentIntentId(): JsonField = paymentIntentId - - /** - * Returns the raw JSON value of [error]. - * - * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error - - /** - * Returns the raw JSON value of [paymentMethodId]. - * - * Unlike [paymentMethodId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("payment_method_id") - @ExcludeMissing - fun _paymentMethodId(): JsonField = paymentMethodId - - @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 [Stripe]. - * - * The following fields are required: - * ```java - * .paymentIntentId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Stripe]. */ - class Builder internal constructor() { - - private var paymentIntentId: JsonField? = null - private var error: JsonField = JsonMissing.of() - private var paymentMethodId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(stripe: Stripe) = apply { - paymentIntentId = stripe.paymentIntentId - error = stripe.error - paymentMethodId = stripe.paymentMethodId - additionalProperties = stripe.additionalProperties.toMutableMap() - } - - fun paymentIntentId(paymentIntentId: String) = - paymentIntentId(JsonField.of(paymentIntentId)) - - /** - * Sets [Builder.paymentIntentId] to an arbitrary JSON value. - * - * You should usually call [Builder.paymentIntentId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun paymentIntentId(paymentIntentId: JsonField) = apply { - this.paymentIntentId = paymentIntentId - } - - fun error(error: Error) = error(JsonField.of(error)) - - /** - * Sets [Builder.error] to an arbitrary JSON value. - * - * You should usually call [Builder.error] with a well-typed [Error] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun error(error: JsonField) = apply { this.error = error } - - fun paymentMethodId(paymentMethodId: String) = - paymentMethodId(JsonField.of(paymentMethodId)) - - /** - * Sets [Builder.paymentMethodId] to an arbitrary JSON value. - * - * You should usually call [Builder.paymentMethodId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun paymentMethodId(paymentMethodId: JsonField) = apply { - this.paymentMethodId = paymentMethodId - } - - 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 [Stripe]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .paymentIntentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Stripe = - Stripe( - checkRequired("paymentIntentId", paymentIntentId), - error, - paymentMethodId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): Stripe = apply { - if (validated) { - return@apply - } - - paymentIntentId() - error().ifPresent { it.validate() } - paymentMethodId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 (paymentIntentId.asKnown().isPresent) 1 else 0) + - (error.asKnown().getOrNull()?.validity() ?: 0) + - (if (paymentMethodId.asKnown().isPresent) 1 else 0) - - class Error - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val code: JsonField, - private val declineCode: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("code") - @ExcludeMissing - code: JsonField = JsonMissing.of(), - @JsonProperty("decline_code") - @ExcludeMissing - declineCode: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(code, declineCode, type, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun code(): Optional = code.getOptional("code") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun declineCode(): Optional = declineCode.getOptional("decline_code") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun type(): Optional = type.getOptional("type") - - /** - * Returns the raw JSON value of [code]. - * - * Unlike [code], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - - /** - * Returns the raw JSON value of [declineCode]. - * - * Unlike [declineCode], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("decline_code") - @ExcludeMissing - fun _declineCode(): JsonField = declineCode - - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Error]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Error]. */ - class Builder internal constructor() { - - private var code: JsonField = JsonMissing.of() - private var declineCode: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(error: Error) = apply { - code = error.code - declineCode = error.declineCode - type = error.type - additionalProperties = error.additionalProperties.toMutableMap() - } - - fun code(code: String) = code(JsonField.of(code)) - - /** - * Sets [Builder.code] to an arbitrary JSON value. - * - * You should usually call [Builder.code] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun code(code: JsonField) = apply { this.code = code } - - fun declineCode(declineCode: String) = declineCode(JsonField.of(declineCode)) - - /** - * Sets [Builder.declineCode] to an arbitrary JSON value. - * - * You should usually call [Builder.declineCode] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun declineCode(declineCode: JsonField) = apply { - this.declineCode = declineCode - } - - fun type(type: String) = type(JsonField.of(type)) - - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun type(type: JsonField) = apply { this.type = type } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Error]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Error = - Error(code, declineCode, type, additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): Error = apply { - if (validated) { - return@apply - } - - code() - declineCode() - type() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 (code.asKnown().isPresent) 1 else 0) + - (if (declineCode.asKnown().isPresent) 1 else 0) + - (if (type.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Error && - code == other.code && - declineCode == other.declineCode && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(code, declineCode, type, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Error{code=$code, declineCode=$declineCode, type=$type, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Stripe && - paymentIntentId == other.paymentIntentId && - error == other.error && - paymentMethodId == other.paymentMethodId && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(paymentIntentId, error, paymentMethodId, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Stripe{paymentIntentId=$paymentIntentId, error=$error, paymentMethodId=$paymentMethodId, additionalProperties=$additionalProperties}" - } - - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is - * on an older version than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val STRIPE = of("stripe") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - STRIPE - } - - /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - STRIPE, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you - * want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - STRIPE -> Value.STRIPE - 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 MetronomeInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - STRIPE -> Known.STRIPE - else -> throw MetronomeInvalidDataException("Unknown Type: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws MetronomeInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - MetronomeInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Type && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentGateway && - stripe == other.stripe && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(stripe, type, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "PaymentGateway{stripe=$stripe, type=$type, additionalProperties=$additionalProperties}" - } - - class RevenueSystemPayment - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val revenueSystemProvider: JsonField, - private val syncStatus: JsonField, - private val errorMessage: JsonField, - private val revenueSystemExternalPaymentId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("revenue_system_provider") - @ExcludeMissing - revenueSystemProvider: JsonField = JsonMissing.of(), - @JsonProperty("sync_status") - @ExcludeMissing - syncStatus: JsonField = JsonMissing.of(), - @JsonProperty("error_message") - @ExcludeMissing - errorMessage: JsonField = JsonMissing.of(), - @JsonProperty("revenue_system_external_payment_id") - @ExcludeMissing - revenueSystemExternalPaymentId: JsonField = JsonMissing.of(), - ) : this( - revenueSystemProvider, - syncStatus, - errorMessage, - revenueSystemExternalPaymentId, - mutableMapOf(), - ) - - /** - * @throws MetronomeInvalidDataException 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 revenueSystemProvider(): String = - revenueSystemProvider.getRequired("revenue_system_provider") - - /** - * @throws MetronomeInvalidDataException 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 syncStatus(): String = syncStatus.getRequired("sync_status") - - /** - * The error message from the revenue system, if available. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun errorMessage(): Optional = errorMessage.getOptional("error_message") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun revenueSystemExternalPaymentId(): Optional = - revenueSystemExternalPaymentId.getOptional("revenue_system_external_payment_id") - - /** - * Returns the raw JSON value of [revenueSystemProvider]. - * - * Unlike [revenueSystemProvider], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("revenue_system_provider") - @ExcludeMissing - fun _revenueSystemProvider(): JsonField = revenueSystemProvider - - /** - * Returns the raw JSON value of [syncStatus]. - * - * Unlike [syncStatus], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("sync_status") - @ExcludeMissing - fun _syncStatus(): JsonField = syncStatus - - /** - * Returns the raw JSON value of [errorMessage]. - * - * Unlike [errorMessage], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("error_message") - @ExcludeMissing - fun _errorMessage(): JsonField = errorMessage - - /** - * Returns the raw JSON value of [revenueSystemExternalPaymentId]. - * - * Unlike [revenueSystemExternalPaymentId], this method doesn't throw if the JSON field has - * an unexpected type. - */ - @JsonProperty("revenue_system_external_payment_id") - @ExcludeMissing - fun _revenueSystemExternalPaymentId(): JsonField = revenueSystemExternalPaymentId - - @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 [RevenueSystemPayment]. - * - * The following fields are required: - * ```java - * .revenueSystemProvider() - * .syncStatus() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [RevenueSystemPayment]. */ - class Builder internal constructor() { - - private var revenueSystemProvider: JsonField? = null - private var syncStatus: JsonField? = null - private var errorMessage: JsonField = JsonMissing.of() - private var revenueSystemExternalPaymentId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(revenueSystemPayment: RevenueSystemPayment) = apply { - revenueSystemProvider = revenueSystemPayment.revenueSystemProvider - syncStatus = revenueSystemPayment.syncStatus - errorMessage = revenueSystemPayment.errorMessage - revenueSystemExternalPaymentId = revenueSystemPayment.revenueSystemExternalPaymentId - additionalProperties = revenueSystemPayment.additionalProperties.toMutableMap() - } - - fun revenueSystemProvider(revenueSystemProvider: String) = - revenueSystemProvider(JsonField.of(revenueSystemProvider)) - - /** - * Sets [Builder.revenueSystemProvider] to an arbitrary JSON value. - * - * You should usually call [Builder.revenueSystemProvider] with a well-typed [String] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun revenueSystemProvider(revenueSystemProvider: JsonField) = apply { - this.revenueSystemProvider = revenueSystemProvider - } - - fun syncStatus(syncStatus: String) = syncStatus(JsonField.of(syncStatus)) - - /** - * Sets [Builder.syncStatus] to an arbitrary JSON value. - * - * You should usually call [Builder.syncStatus] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun syncStatus(syncStatus: JsonField) = apply { this.syncStatus = syncStatus } - - /** The error message from the revenue system, if available. */ - fun errorMessage(errorMessage: String) = errorMessage(JsonField.of(errorMessage)) - - /** - * Sets [Builder.errorMessage] to an arbitrary JSON value. - * - * You should usually call [Builder.errorMessage] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun errorMessage(errorMessage: JsonField) = apply { - this.errorMessage = errorMessage - } - - fun revenueSystemExternalPaymentId(revenueSystemExternalPaymentId: String) = - revenueSystemExternalPaymentId(JsonField.of(revenueSystemExternalPaymentId)) - - /** - * Sets [Builder.revenueSystemExternalPaymentId] to an arbitrary JSON value. - * - * You should usually call [Builder.revenueSystemExternalPaymentId] with a well-typed - * [String] value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun revenueSystemExternalPaymentId(revenueSystemExternalPaymentId: JsonField) = - apply { - this.revenueSystemExternalPaymentId = revenueSystemExternalPaymentId - } - - 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 [RevenueSystemPayment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .revenueSystemProvider() - * .syncStatus() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RevenueSystemPayment = - RevenueSystemPayment( - checkRequired("revenueSystemProvider", revenueSystemProvider), - checkRequired("syncStatus", syncStatus), - errorMessage, - revenueSystemExternalPaymentId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): RevenueSystemPayment = apply { - if (validated) { - return@apply - } - - revenueSystemProvider() - syncStatus() - errorMessage() - revenueSystemExternalPaymentId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 (revenueSystemProvider.asKnown().isPresent) 1 else 0) + - (if (syncStatus.asKnown().isPresent) 1 else 0) + - (if (errorMessage.asKnown().isPresent) 1 else 0) + - (if (revenueSystemExternalPaymentId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is RevenueSystemPayment && - revenueSystemProvider == other.revenueSystemProvider && - syncStatus == other.syncStatus && - errorMessage == other.errorMessage && - revenueSystemExternalPaymentId == other.revenueSystemExternalPaymentId && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash( - revenueSystemProvider, - syncStatus, - errorMessage, - revenueSystemExternalPaymentId, - additionalProperties, - ) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "RevenueSystemPayment{revenueSystemProvider=$revenueSystemProvider, syncStatus=$syncStatus, errorMessage=$errorMessage, revenueSystemExternalPaymentId=$revenueSystemExternalPaymentId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Payment && - id == other.id && - amount == other.amount && - amountPaid == other.amountPaid && - contractId == other.contractId && - createdAt == other.createdAt && - customerId == other.customerId && - errorMessage == other.errorMessage && - fiatCreditType == other.fiatCreditType && - invoiceId == other.invoiceId && - paymentGateway == other.paymentGateway && - revenueSystemPayments == other.revenueSystemPayments && - status == other.status && - updatedAt == other.updatedAt && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash( - id, - amount, - amountPaid, - contractId, - createdAt, - customerId, - errorMessage, - fiatCreditType, - invoiceId, - paymentGateway, - revenueSystemPayments, - status, - updatedAt, - additionalProperties, - ) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Payment{id=$id, amount=$amount, amountPaid=$amountPaid, contractId=$contractId, createdAt=$createdAt, customerId=$customerId, errorMessage=$errorMessage, fiatCreditType=$fiatCreditType, invoiceId=$invoiceId, paymentGateway=$paymentGateway, revenueSystemPayments=$revenueSystemPayments, status=$status, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptParams.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptParams.kt deleted file mode 100644 index c91e71ec..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptParams.kt +++ /dev/null @@ -1,502 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.metronome.api.core.ExcludeMissing -import com.metronome.api.core.JsonField -import com.metronome.api.core.JsonMissing -import com.metronome.api.core.JsonValue -import com.metronome.api.core.Params -import com.metronome.api.core.checkRequired -import com.metronome.api.core.http.Headers -import com.metronome.api.core.http.QueryParams -import com.metronome.api.errors.MetronomeInvalidDataException -import java.util.Collections -import java.util.Objects - -/** - * Trigger a new attempt by canceling any existing attempts for this invoice and creating a new - * Payment. This will trigger another attempt to charge the Customer's configured Payment Gateway. - * Payment can only be attempted if all of the following are true: - * - The Metronome Invoice is finalized - * - PLG Invoicing is configured for the Customer - * - You cannot attempt payments for invoices that have already been `paid` or `voided`. - * - * Attempting to payment on an ineligible Invoice or Customer will result in a `400` response. - */ -class PaymentAttemptParams -private constructor( - private val body: Body, - private val additionalHeaders: Headers, - private val additionalQueryParams: QueryParams, -) : Params { - - /** - * @throws MetronomeInvalidDataException 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 customerId(): String = body.customerId() - - /** - * @throws MetronomeInvalidDataException 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 invoiceId(): String = body.invoiceId() - - /** - * Returns the raw JSON value of [customerId]. - * - * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _customerId(): JsonField = body._customerId() - - /** - * Returns the raw JSON value of [invoiceId]. - * - * Unlike [invoiceId], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _invoiceId(): JsonField = body._invoiceId() - - fun _additionalBodyProperties(): Map = body._additionalProperties() - - /** Additional headers to send with the request. */ - fun _additionalHeaders(): Headers = additionalHeaders - - /** Additional query param to send with the request. */ - fun _additionalQueryParams(): QueryParams = additionalQueryParams - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [PaymentAttemptParams]. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentAttemptParams]. */ - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(paymentAttemptParams: PaymentAttemptParams) = apply { - body = paymentAttemptParams.body.toBuilder() - additionalHeaders = paymentAttemptParams.additionalHeaders.toBuilder() - additionalQueryParams = paymentAttemptParams.additionalQueryParams.toBuilder() - } - - /** - * Sets the entire request body. - * - * This is generally only useful if you are already constructing the body separately. - * Otherwise, it's more convenient to use the top-level setters instead: - * - [customerId] - * - [invoiceId] - */ - fun body(body: Body) = apply { this.body = body.toBuilder() } - - fun customerId(customerId: String) = apply { body.customerId(customerId) } - - /** - * Sets [Builder.customerId] to an arbitrary JSON value. - * - * You should usually call [Builder.customerId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun customerId(customerId: JsonField) = apply { body.customerId(customerId) } - - fun invoiceId(invoiceId: String) = apply { body.invoiceId(invoiceId) } - - /** - * Sets [Builder.invoiceId] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun invoiceId(invoiceId: JsonField) = apply { body.invoiceId(invoiceId) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } - - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } - - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } - - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } - - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } - - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } - - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } - - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } - - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } - - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } - - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } - - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } - - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } - - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } - - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } - - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } - - /** - * Returns an immutable instance of [PaymentAttemptParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentAttemptParams = - PaymentAttemptParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - - fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - class Body - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val customerId: JsonField, - private val invoiceId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("customer_id") - @ExcludeMissing - customerId: JsonField = JsonMissing.of(), - @JsonProperty("invoice_id") - @ExcludeMissing - invoiceId: JsonField = JsonMissing.of(), - ) : this(customerId, invoiceId, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException 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 customerId(): String = customerId.getRequired("customer_id") - - /** - * @throws MetronomeInvalidDataException 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 invoiceId(): String = invoiceId.getRequired("invoice_id") - - /** - * Returns the raw JSON value of [customerId]. - * - * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("customer_id") - @ExcludeMissing - fun _customerId(): JsonField = customerId - - /** - * Returns the raw JSON value of [invoiceId]. - * - * Unlike [invoiceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("invoice_id") @ExcludeMissing fun _invoiceId(): JsonField = invoiceId - - @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 [Body]. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var customerId: JsonField? = null - private var invoiceId: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - customerId = body.customerId - invoiceId = body.invoiceId - additionalProperties = body.additionalProperties.toMutableMap() - } - - fun customerId(customerId: String) = customerId(JsonField.of(customerId)) - - /** - * Sets [Builder.customerId] to an arbitrary JSON value. - * - * You should usually call [Builder.customerId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun customerId(customerId: JsonField) = apply { this.customerId = customerId } - - fun invoiceId(invoiceId: String) = invoiceId(JsonField.of(invoiceId)) - - /** - * Sets [Builder.invoiceId] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceId(invoiceId: JsonField) = apply { this.invoiceId = invoiceId } - - 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 [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("customerId", customerId), - checkRequired("invoiceId", invoiceId), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): Body = apply { - if (validated) { - return@apply - } - - customerId() - invoiceId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 (customerId.asKnown().isPresent) 1 else 0) + - (if (invoiceId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Body && - customerId == other.customerId && - invoiceId == other.invoiceId && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(customerId, invoiceId, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{customerId=$customerId, invoiceId=$invoiceId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentAttemptParams && - body == other.body && - additionalHeaders == other.additionalHeaders && - additionalQueryParams == other.additionalQueryParams - } - - override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) - - override fun toString() = - "PaymentAttemptParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptResponse.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptResponse.kt deleted file mode 100644 index 8252dd75..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptResponse.kt +++ /dev/null @@ -1,176 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.metronome.api.core.ExcludeMissing -import com.metronome.api.core.JsonField -import com.metronome.api.core.JsonMissing -import com.metronome.api.core.JsonValue -import com.metronome.api.core.checkRequired -import com.metronome.api.errors.MetronomeInvalidDataException -import java.util.Collections -import java.util.Objects -import kotlin.jvm.optionals.getOrNull - -class PaymentAttemptResponse -@JsonCreator(mode = JsonCreator.Mode.DISABLED) -private constructor( - private val data: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of() - ) : this(data, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException 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 data(): Payment = data.getRequired("data") - - /** - * 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 - - @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 [PaymentAttemptResponse]. - * - * The following fields are required: - * ```java - * .data() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentAttemptResponse]. */ - class Builder internal constructor() { - - private var data: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(paymentAttemptResponse: PaymentAttemptResponse) = apply { - data = paymentAttemptResponse.data - additionalProperties = paymentAttemptResponse.additionalProperties.toMutableMap() - } - - fun data(data: Payment) = data(JsonField.of(data)) - - /** - * Sets [Builder.data] to an arbitrary JSON value. - * - * You should usually call [Builder.data] with a well-typed [Payment] 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 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 [PaymentAttemptResponse]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .data() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentAttemptResponse = - PaymentAttemptResponse(checkRequired("data", data), additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): PaymentAttemptResponse = apply { - if (validated) { - return@apply - } - - data().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentAttemptResponse && - data == other.data && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "PaymentAttemptResponse{data=$data, additionalProperties=$additionalProperties}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentCancelParams.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentCancelParams.kt deleted file mode 100644 index 6f369fba..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentCancelParams.kt +++ /dev/null @@ -1,493 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.metronome.api.core.ExcludeMissing -import com.metronome.api.core.JsonField -import com.metronome.api.core.JsonMissing -import com.metronome.api.core.JsonValue -import com.metronome.api.core.Params -import com.metronome.api.core.checkRequired -import com.metronome.api.core.http.Headers -import com.metronome.api.core.http.QueryParams -import com.metronome.api.errors.MetronomeInvalidDataException -import java.util.Collections -import java.util.Objects - -/** Cancel an existing payment attempt for an invoice. */ -class PaymentCancelParams -private constructor( - private val body: Body, - private val additionalHeaders: Headers, - private val additionalQueryParams: QueryParams, -) : Params { - - /** - * @throws MetronomeInvalidDataException 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 customerId(): String = body.customerId() - - /** - * @throws MetronomeInvalidDataException 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 invoiceId(): String = body.invoiceId() - - /** - * Returns the raw JSON value of [customerId]. - * - * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _customerId(): JsonField = body._customerId() - - /** - * Returns the raw JSON value of [invoiceId]. - * - * Unlike [invoiceId], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _invoiceId(): JsonField = body._invoiceId() - - fun _additionalBodyProperties(): Map = body._additionalProperties() - - /** Additional headers to send with the request. */ - fun _additionalHeaders(): Headers = additionalHeaders - - /** Additional query param to send with the request. */ - fun _additionalQueryParams(): QueryParams = additionalQueryParams - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [PaymentCancelParams]. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentCancelParams]. */ - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(paymentCancelParams: PaymentCancelParams) = apply { - body = paymentCancelParams.body.toBuilder() - additionalHeaders = paymentCancelParams.additionalHeaders.toBuilder() - additionalQueryParams = paymentCancelParams.additionalQueryParams.toBuilder() - } - - /** - * Sets the entire request body. - * - * This is generally only useful if you are already constructing the body separately. - * Otherwise, it's more convenient to use the top-level setters instead: - * - [customerId] - * - [invoiceId] - */ - fun body(body: Body) = apply { this.body = body.toBuilder() } - - fun customerId(customerId: String) = apply { body.customerId(customerId) } - - /** - * Sets [Builder.customerId] to an arbitrary JSON value. - * - * You should usually call [Builder.customerId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun customerId(customerId: JsonField) = apply { body.customerId(customerId) } - - fun invoiceId(invoiceId: String) = apply { body.invoiceId(invoiceId) } - - /** - * Sets [Builder.invoiceId] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun invoiceId(invoiceId: JsonField) = apply { body.invoiceId(invoiceId) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } - - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } - - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } - - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } - - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } - - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } - - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } - - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } - - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } - - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } - - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } - - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } - - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } - - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } - - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } - - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } - - /** - * Returns an immutable instance of [PaymentCancelParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentCancelParams = - PaymentCancelParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - - fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - class Body - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val customerId: JsonField, - private val invoiceId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("customer_id") - @ExcludeMissing - customerId: JsonField = JsonMissing.of(), - @JsonProperty("invoice_id") - @ExcludeMissing - invoiceId: JsonField = JsonMissing.of(), - ) : this(customerId, invoiceId, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException 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 customerId(): String = customerId.getRequired("customer_id") - - /** - * @throws MetronomeInvalidDataException 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 invoiceId(): String = invoiceId.getRequired("invoice_id") - - /** - * Returns the raw JSON value of [customerId]. - * - * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("customer_id") - @ExcludeMissing - fun _customerId(): JsonField = customerId - - /** - * Returns the raw JSON value of [invoiceId]. - * - * Unlike [invoiceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("invoice_id") @ExcludeMissing fun _invoiceId(): JsonField = invoiceId - - @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 [Body]. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var customerId: JsonField? = null - private var invoiceId: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - customerId = body.customerId - invoiceId = body.invoiceId - additionalProperties = body.additionalProperties.toMutableMap() - } - - fun customerId(customerId: String) = customerId(JsonField.of(customerId)) - - /** - * Sets [Builder.customerId] to an arbitrary JSON value. - * - * You should usually call [Builder.customerId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun customerId(customerId: JsonField) = apply { this.customerId = customerId } - - fun invoiceId(invoiceId: String) = invoiceId(JsonField.of(invoiceId)) - - /** - * Sets [Builder.invoiceId] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceId(invoiceId: JsonField) = apply { this.invoiceId = invoiceId } - - 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 [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("customerId", customerId), - checkRequired("invoiceId", invoiceId), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): Body = apply { - if (validated) { - return@apply - } - - customerId() - invoiceId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 (customerId.asKnown().isPresent) 1 else 0) + - (if (invoiceId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Body && - customerId == other.customerId && - invoiceId == other.invoiceId && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(customerId, invoiceId, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{customerId=$customerId, invoiceId=$invoiceId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentCancelParams && - body == other.body && - additionalHeaders == other.additionalHeaders && - additionalQueryParams == other.additionalQueryParams - } - - override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) - - override fun toString() = - "PaymentCancelParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentCancelResponse.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentCancelResponse.kt deleted file mode 100644 index 1bc4ca28..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentCancelResponse.kt +++ /dev/null @@ -1,176 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.metronome.api.core.ExcludeMissing -import com.metronome.api.core.JsonField -import com.metronome.api.core.JsonMissing -import com.metronome.api.core.JsonValue -import com.metronome.api.core.checkRequired -import com.metronome.api.errors.MetronomeInvalidDataException -import java.util.Collections -import java.util.Objects -import kotlin.jvm.optionals.getOrNull - -class PaymentCancelResponse -@JsonCreator(mode = JsonCreator.Mode.DISABLED) -private constructor( - private val data: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of() - ) : this(data, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException 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 data(): Payment = data.getRequired("data") - - /** - * 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 - - @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 [PaymentCancelResponse]. - * - * The following fields are required: - * ```java - * .data() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentCancelResponse]. */ - class Builder internal constructor() { - - private var data: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(paymentCancelResponse: PaymentCancelResponse) = apply { - data = paymentCancelResponse.data - additionalProperties = paymentCancelResponse.additionalProperties.toMutableMap() - } - - fun data(data: Payment) = data(JsonField.of(data)) - - /** - * Sets [Builder.data] to an arbitrary JSON value. - * - * You should usually call [Builder.data] with a well-typed [Payment] 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 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 [PaymentCancelResponse]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .data() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentCancelResponse = - PaymentCancelResponse(checkRequired("data", data), additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): PaymentCancelResponse = apply { - if (validated) { - return@apply - } - - data().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentCancelResponse && - data == other.data && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "PaymentCancelResponse{data=$data, additionalProperties=$additionalProperties}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPage.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPage.kt deleted file mode 100644 index d0f72973..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPage.kt +++ /dev/null @@ -1,132 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.metronome.api.core.AutoPager -import com.metronome.api.core.Page -import com.metronome.api.core.checkRequired -import com.metronome.api.services.blocking.v1.PaymentService -import java.util.Objects -import java.util.Optional -import kotlin.jvm.optionals.getOrNull - -/** @see PaymentService.list */ -class PaymentListPage -private constructor( - private val service: PaymentService, - private val params: PaymentListParams, - private val response: PaymentListPageResponse, -) : Page { - - /** - * Delegates to [PaymentListPageResponse], but gracefully handles missing data. - * - * @see PaymentListPageResponse.nextPage - */ - fun nextPageRaw(): Optional = response._nextPage().getOptional("next_page") - - /** - * Delegates to [PaymentListPageResponse], but gracefully handles missing data. - * - * @see PaymentListPageResponse.data - */ - fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - - override fun items(): List = data() - - override fun hasNextPage(): Boolean = nextPageRaw().isPresent - - fun nextPageParams(): PaymentListParams { - val nextCursor = - nextPageRaw().getOrNull() - ?: throw IllegalStateException("Cannot construct next page params") - return params.toBuilder().nextPage(nextCursor).build() - } - - override fun nextPage(): PaymentListPage = service.list(nextPageParams()) - - fun autoPager(): AutoPager = AutoPager.from(this) - - /** The parameters that were used to request this page. */ - fun params(): PaymentListParams = params - - /** The response that this page was parsed from. */ - fun response(): PaymentListPageResponse = response - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [PaymentListPage]. - * - * The following fields are required: - * ```java - * .service() - * .params() - * .response() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentListPage]. */ - class Builder internal constructor() { - - private var service: PaymentService? = null - private var params: PaymentListParams? = null - private var response: PaymentListPageResponse? = null - - @JvmSynthetic - internal fun from(paymentListPage: PaymentListPage) = apply { - service = paymentListPage.service - params = paymentListPage.params - response = paymentListPage.response - } - - fun service(service: PaymentService) = apply { this.service = service } - - /** The parameters that were used to request this page. */ - fun params(params: PaymentListParams) = apply { this.params = params } - - /** The response that this page was parsed from. */ - fun response(response: PaymentListPageResponse) = apply { this.response = response } - - /** - * Returns an immutable instance of [PaymentListPage]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .service() - * .params() - * .response() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentListPage = - PaymentListPage( - checkRequired("service", service), - checkRequired("params", params), - checkRequired("response", response), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentListPage && - service == other.service && - params == other.params && - response == other.response - } - - override fun hashCode(): Int = Objects.hash(service, params, response) - - override fun toString() = - "PaymentListPage{service=$service, params=$params, response=$response}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPageAsync.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPageAsync.kt deleted file mode 100644 index 6001693a..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPageAsync.kt +++ /dev/null @@ -1,146 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.metronome.api.core.AutoPagerAsync -import com.metronome.api.core.PageAsync -import com.metronome.api.core.checkRequired -import com.metronome.api.services.async.v1.PaymentServiceAsync -import java.util.Objects -import java.util.Optional -import java.util.concurrent.CompletableFuture -import java.util.concurrent.Executor -import kotlin.jvm.optionals.getOrNull - -/** @see PaymentServiceAsync.list */ -class PaymentListPageAsync -private constructor( - private val service: PaymentServiceAsync, - private val streamHandlerExecutor: Executor, - private val params: PaymentListParams, - private val response: PaymentListPageResponse, -) : PageAsync { - - /** - * Delegates to [PaymentListPageResponse], but gracefully handles missing data. - * - * @see PaymentListPageResponse.nextPage - */ - fun nextPageRaw(): Optional = response._nextPage().getOptional("next_page") - - /** - * Delegates to [PaymentListPageResponse], but gracefully handles missing data. - * - * @see PaymentListPageResponse.data - */ - fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - - override fun items(): List = data() - - override fun hasNextPage(): Boolean = nextPageRaw().isPresent - - fun nextPageParams(): PaymentListParams { - val nextCursor = - nextPageRaw().getOrNull() - ?: throw IllegalStateException("Cannot construct next page params") - return params.toBuilder().nextPage(nextCursor).build() - } - - override fun nextPage(): CompletableFuture = - service.list(nextPageParams()) - - fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) - - /** The parameters that were used to request this page. */ - fun params(): PaymentListParams = params - - /** The response that this page was parsed from. */ - fun response(): PaymentListPageResponse = response - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [PaymentListPageAsync]. - * - * The following fields are required: - * ```java - * .service() - * .streamHandlerExecutor() - * .params() - * .response() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentListPageAsync]. */ - class Builder internal constructor() { - - private var service: PaymentServiceAsync? = null - private var streamHandlerExecutor: Executor? = null - private var params: PaymentListParams? = null - private var response: PaymentListPageResponse? = null - - @JvmSynthetic - internal fun from(paymentListPageAsync: PaymentListPageAsync) = apply { - service = paymentListPageAsync.service - streamHandlerExecutor = paymentListPageAsync.streamHandlerExecutor - params = paymentListPageAsync.params - response = paymentListPageAsync.response - } - - fun service(service: PaymentServiceAsync) = apply { this.service = service } - - fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { - this.streamHandlerExecutor = streamHandlerExecutor - } - - /** The parameters that were used to request this page. */ - fun params(params: PaymentListParams) = apply { this.params = params } - - /** The response that this page was parsed from. */ - fun response(response: PaymentListPageResponse) = apply { this.response = response } - - /** - * Returns an immutable instance of [PaymentListPageAsync]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .service() - * .streamHandlerExecutor() - * .params() - * .response() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentListPageAsync = - PaymentListPageAsync( - checkRequired("service", service), - checkRequired("streamHandlerExecutor", streamHandlerExecutor), - checkRequired("params", params), - checkRequired("response", response), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentListPageAsync && - service == other.service && - streamHandlerExecutor == other.streamHandlerExecutor && - params == other.params && - response == other.response - } - - override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) - - override fun toString() = - "PaymentListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPageResponse.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPageResponse.kt deleted file mode 100644 index 28677dca..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListPageResponse.kt +++ /dev/null @@ -1,233 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.metronome.api.core.ExcludeMissing -import com.metronome.api.core.JsonField -import com.metronome.api.core.JsonMissing -import com.metronome.api.core.JsonValue -import com.metronome.api.core.checkKnown -import com.metronome.api.core.checkRequired -import com.metronome.api.core.toImmutable -import com.metronome.api.errors.MetronomeInvalidDataException -import java.util.Collections -import java.util.Objects -import java.util.Optional -import kotlin.jvm.optionals.getOrNull - -class PaymentListPageResponse -@JsonCreator(mode = JsonCreator.Mode.DISABLED) -private constructor( - private val data: JsonField>, - private val nextPage: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), - @JsonProperty("next_page") @ExcludeMissing nextPage: JsonField = JsonMissing.of(), - ) : this(data, nextPage, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException 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 data(): List = data.getRequired("data") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun nextPage(): Optional = nextPage.getOptional("next_page") - - /** - * 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 [nextPage]. - * - * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("next_page") @ExcludeMissing fun _nextPage(): JsonField = nextPage - - @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 [PaymentListPageResponse]. - * - * The following fields are required: - * ```java - * .data() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentListPageResponse]. */ - class Builder internal constructor() { - - private var data: JsonField>? = null - private var nextPage: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(paymentListPageResponse: PaymentListPageResponse) = apply { - data = paymentListPageResponse.data.map { it.toMutableList() } - nextPage = paymentListPageResponse.nextPage - additionalProperties = paymentListPageResponse.additionalProperties.toMutableMap() - } - - fun data(data: List) = data(JsonField.of(data)) - - /** - * Sets [Builder.data] to an arbitrary JSON value. - * - * You should usually call [Builder.data] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun data(data: JsonField>) = apply { - this.data = data.map { it.toMutableList() } - } - - /** - * Adds a single [Payment] to [Builder.data]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addData(data: Payment) = apply { - this.data = - (this.data ?: JsonField.of(mutableListOf())).also { - checkKnown("data", it).add(data) - } - } - - fun nextPage(nextPage: String?) = nextPage(JsonField.ofNullable(nextPage)) - - /** Alias for calling [Builder.nextPage] with `nextPage.orElse(null)`. */ - fun nextPage(nextPage: Optional) = nextPage(nextPage.getOrNull()) - - /** - * Sets [Builder.nextPage] to an arbitrary JSON value. - * - * You should usually call [Builder.nextPage] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun nextPage(nextPage: JsonField) = apply { this.nextPage = nextPage } - - 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 [PaymentListPageResponse]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .data() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentListPageResponse = - PaymentListPageResponse( - checkRequired("data", data).map { it.toImmutable() }, - nextPage, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): PaymentListPageResponse = apply { - if (validated) { - return@apply - } - - data().forEach { it.validate() } - nextPage() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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()?.sumOf { it.validity().toInt() } ?: 0) + - (if (nextPage.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentListPageResponse && - data == other.data && - nextPage == other.nextPage && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(data, nextPage, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "PaymentListPageResponse{data=$data, nextPage=$nextPage, additionalProperties=$additionalProperties}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListParams.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListParams.kt deleted file mode 100644 index 71cb7276..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentListParams.kt +++ /dev/null @@ -1,706 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.metronome.api.core.ExcludeMissing -import com.metronome.api.core.JsonField -import com.metronome.api.core.JsonMissing -import com.metronome.api.core.JsonValue -import com.metronome.api.core.Params -import com.metronome.api.core.checkKnown -import com.metronome.api.core.checkRequired -import com.metronome.api.core.http.Headers -import com.metronome.api.core.http.QueryParams -import com.metronome.api.core.toImmutable -import com.metronome.api.errors.MetronomeInvalidDataException -import java.util.Collections -import java.util.Objects -import java.util.Optional -import kotlin.jvm.optionals.getOrNull - -/** Fetch all payment attempts for the given invoice. */ -class PaymentListParams -private constructor( - private val body: Body, - private val additionalHeaders: Headers, - private val additionalQueryParams: QueryParams, -) : Params { - - /** - * @throws MetronomeInvalidDataException 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 customerId(): String = body.customerId() - - /** - * @throws MetronomeInvalidDataException 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 invoiceId(): String = body.invoiceId() - - /** - * The maximum number of payments to return. Defaults to 25. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun limit(): Optional = body.limit() - - /** - * The next page token from a previous response. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun nextPage(): Optional = body.nextPage() - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun statuses(): Optional> = body.statuses() - - /** - * Returns the raw JSON value of [customerId]. - * - * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _customerId(): JsonField = body._customerId() - - /** - * Returns the raw JSON value of [invoiceId]. - * - * Unlike [invoiceId], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _invoiceId(): JsonField = body._invoiceId() - - /** - * Returns the raw JSON value of [limit]. - * - * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _limit(): JsonField = body._limit() - - /** - * Returns the raw JSON value of [nextPage]. - * - * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _nextPage(): JsonField = body._nextPage() - - /** - * Returns the raw JSON value of [statuses]. - * - * Unlike [statuses], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _statuses(): JsonField> = body._statuses() - - fun _additionalBodyProperties(): Map = body._additionalProperties() - - /** Additional headers to send with the request. */ - fun _additionalHeaders(): Headers = additionalHeaders - - /** Additional query param to send with the request. */ - fun _additionalQueryParams(): QueryParams = additionalQueryParams - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [PaymentListParams]. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PaymentListParams]. */ - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(paymentListParams: PaymentListParams) = apply { - body = paymentListParams.body.toBuilder() - additionalHeaders = paymentListParams.additionalHeaders.toBuilder() - additionalQueryParams = paymentListParams.additionalQueryParams.toBuilder() - } - - /** - * Sets the entire request body. - * - * This is generally only useful if you are already constructing the body separately. - * Otherwise, it's more convenient to use the top-level setters instead: - * - [customerId] - * - [invoiceId] - * - [limit] - * - [nextPage] - * - [statuses] - * - etc. - */ - fun body(body: Body) = apply { this.body = body.toBuilder() } - - fun customerId(customerId: String) = apply { body.customerId(customerId) } - - /** - * Sets [Builder.customerId] to an arbitrary JSON value. - * - * You should usually call [Builder.customerId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun customerId(customerId: JsonField) = apply { body.customerId(customerId) } - - fun invoiceId(invoiceId: String) = apply { body.invoiceId(invoiceId) } - - /** - * Sets [Builder.invoiceId] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun invoiceId(invoiceId: JsonField) = apply { body.invoiceId(invoiceId) } - - /** The maximum number of payments to return. Defaults to 25. */ - fun limit(limit: Long) = apply { body.limit(limit) } - - /** - * Sets [Builder.limit] to an arbitrary JSON value. - * - * You should usually call [Builder.limit] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun limit(limit: JsonField) = apply { body.limit(limit) } - - /** The next page token from a previous response. */ - fun nextPage(nextPage: String) = apply { body.nextPage(nextPage) } - - /** - * Sets [Builder.nextPage] to an arbitrary JSON value. - * - * You should usually call [Builder.nextPage] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun nextPage(nextPage: JsonField) = apply { body.nextPage(nextPage) } - - fun statuses(statuses: List) = apply { body.statuses(statuses) } - - /** - * Sets [Builder.statuses] to an arbitrary JSON value. - * - * You should usually call [Builder.statuses] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun statuses(statuses: JsonField>) = apply { body.statuses(statuses) } - - /** - * Adds a single [PaymentStatus] to [statuses]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addStatus(status: PaymentStatus) = apply { body.addStatus(status) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } - - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } - - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } - - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } - - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } - - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } - - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } - - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } - - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } - - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } - - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } - - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } - - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } - - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } - - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } - - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } - - /** - * Returns an immutable instance of [PaymentListParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PaymentListParams = - PaymentListParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - - fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - class Body - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val customerId: JsonField, - private val invoiceId: JsonField, - private val limit: JsonField, - private val nextPage: JsonField, - private val statuses: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("customer_id") - @ExcludeMissing - customerId: JsonField = JsonMissing.of(), - @JsonProperty("invoice_id") - @ExcludeMissing - invoiceId: JsonField = JsonMissing.of(), - @JsonProperty("limit") @ExcludeMissing limit: JsonField = JsonMissing.of(), - @JsonProperty("next_page") - @ExcludeMissing - nextPage: JsonField = JsonMissing.of(), - @JsonProperty("statuses") - @ExcludeMissing - statuses: JsonField> = JsonMissing.of(), - ) : this(customerId, invoiceId, limit, nextPage, statuses, mutableMapOf()) - - /** - * @throws MetronomeInvalidDataException 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 customerId(): String = customerId.getRequired("customer_id") - - /** - * @throws MetronomeInvalidDataException 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 invoiceId(): String = invoiceId.getRequired("invoice_id") - - /** - * The maximum number of payments to return. Defaults to 25. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun limit(): Optional = limit.getOptional("limit") - - /** - * The next page token from a previous response. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun nextPage(): Optional = nextPage.getOptional("next_page") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun statuses(): Optional> = statuses.getOptional("statuses") - - /** - * Returns the raw JSON value of [customerId]. - * - * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("customer_id") - @ExcludeMissing - fun _customerId(): JsonField = customerId - - /** - * Returns the raw JSON value of [invoiceId]. - * - * Unlike [invoiceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("invoice_id") @ExcludeMissing fun _invoiceId(): JsonField = invoiceId - - /** - * Returns the raw JSON value of [limit]. - * - * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("limit") @ExcludeMissing fun _limit(): JsonField = limit - - /** - * Returns the raw JSON value of [nextPage]. - * - * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("next_page") @ExcludeMissing fun _nextPage(): JsonField = nextPage - - /** - * Returns the raw JSON value of [statuses]. - * - * Unlike [statuses], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("statuses") - @ExcludeMissing - fun _statuses(): JsonField> = statuses - - @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 [Body]. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var customerId: JsonField? = null - private var invoiceId: JsonField? = null - private var limit: JsonField = JsonMissing.of() - private var nextPage: JsonField = JsonMissing.of() - private var statuses: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - customerId = body.customerId - invoiceId = body.invoiceId - limit = body.limit - nextPage = body.nextPage - statuses = body.statuses.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - fun customerId(customerId: String) = customerId(JsonField.of(customerId)) - - /** - * Sets [Builder.customerId] to an arbitrary JSON value. - * - * You should usually call [Builder.customerId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun customerId(customerId: JsonField) = apply { this.customerId = customerId } - - fun invoiceId(invoiceId: String) = invoiceId(JsonField.of(invoiceId)) - - /** - * Sets [Builder.invoiceId] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceId(invoiceId: JsonField) = apply { this.invoiceId = invoiceId } - - /** The maximum number of payments to return. Defaults to 25. */ - fun limit(limit: Long) = limit(JsonField.of(limit)) - - /** - * Sets [Builder.limit] to an arbitrary JSON value. - * - * You should usually call [Builder.limit] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun limit(limit: JsonField) = apply { this.limit = limit } - - /** The next page token from a previous response. */ - fun nextPage(nextPage: String) = nextPage(JsonField.of(nextPage)) - - /** - * Sets [Builder.nextPage] to an arbitrary JSON value. - * - * You should usually call [Builder.nextPage] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun nextPage(nextPage: JsonField) = apply { this.nextPage = nextPage } - - fun statuses(statuses: List) = statuses(JsonField.of(statuses)) - - /** - * Sets [Builder.statuses] to an arbitrary JSON value. - * - * You should usually call [Builder.statuses] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun statuses(statuses: JsonField>) = apply { - this.statuses = statuses.map { it.toMutableList() } - } - - /** - * Adds a single [PaymentStatus] to [statuses]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addStatus(status: PaymentStatus) = apply { - statuses = - (statuses ?: JsonField.of(mutableListOf())).also { - checkKnown("statuses", it).add(status) - } - } - - 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 [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .customerId() - * .invoiceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("customerId", customerId), - checkRequired("invoiceId", invoiceId), - limit, - nextPage, - (statuses ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): Body = apply { - if (validated) { - return@apply - } - - customerId() - invoiceId() - limit() - nextPage() - statuses().ifPresent { it.forEach { it.validate() } } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 (customerId.asKnown().isPresent) 1 else 0) + - (if (invoiceId.asKnown().isPresent) 1 else 0) + - (if (limit.asKnown().isPresent) 1 else 0) + - (if (nextPage.asKnown().isPresent) 1 else 0) + - (statuses.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Body && - customerId == other.customerId && - invoiceId == other.invoiceId && - limit == other.limit && - nextPage == other.nextPage && - statuses == other.statuses && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(customerId, invoiceId, limit, nextPage, statuses, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{customerId=$customerId, invoiceId=$invoiceId, limit=$limit, nextPage=$nextPage, statuses=$statuses, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is PaymentListParams && - body == other.body && - additionalHeaders == other.additionalHeaders && - additionalQueryParams == other.additionalQueryParams - } - - override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) - - override fun toString() = - "PaymentListParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentStatus.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentStatus.kt deleted file mode 100644 index d70bd05a..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v1/payments/PaymentStatus.kt +++ /dev/null @@ -1,152 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.annotation.JsonCreator -import com.metronome.api.core.Enum -import com.metronome.api.core.JsonField -import com.metronome.api.errors.MetronomeInvalidDataException - -class PaymentStatus @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 PENDING = of("pending") - - @JvmField val REQUIRES_INTERVENTION = of("requires_intervention") - - @JvmField val PAID = of("paid") - - @JvmField val CANCELED = of("canceled") - - @JvmStatic fun of(value: String) = PaymentStatus(JsonField.of(value)) - } - - /** An enum containing [PaymentStatus]'s known values. */ - enum class Known { - PENDING, - REQUIRES_INTERVENTION, - PAID, - CANCELED, - } - - /** - * An enum containing [PaymentStatus]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PaymentStatus] 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 { - PENDING, - REQUIRES_INTERVENTION, - PAID, - CANCELED, - /** - * An enum member indicating that [PaymentStatus] 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) { - PENDING -> Value.PENDING - REQUIRES_INTERVENTION -> Value.REQUIRES_INTERVENTION - PAID -> Value.PAID - CANCELED -> Value.CANCELED - 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 MetronomeInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - PENDING -> Known.PENDING - REQUIRES_INTERVENTION -> Known.REQUIRES_INTERVENTION - PAID -> Known.PAID - CANCELED -> Known.CANCELED - else -> throw MetronomeInvalidDataException("Unknown PaymentStatus: $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 MetronomeInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { MetronomeInvalidDataException("Value is not a String") } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): PaymentStatus = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 PaymentStatus && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractEditParams.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractEditParams.kt index bc22cbb0..b681cc87 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractEditParams.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractEditParams.kt @@ -165,6 +165,14 @@ private constructor( fun addSpendThresholdConfiguration(): Optional = body.addSpendThresholdConfiguration() + /** + * Spend trackers to add to this contract. Aliases must be unique within a contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun addSpendTrackers(): Optional> = body.addSpendTrackers() + /** * Optional list of * [subscriptions](https://docs.metronome.com/manage-product-access/create-subscription/) to add @@ -211,6 +219,14 @@ private constructor( fun archiveScheduledCharges(): Optional> = body.archiveScheduledCharges() + /** + * Aliases of spend trackers to archive. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun archiveSpendTrackers(): Optional> = body.archiveSpendTrackers() + /** * IDs of overrides to remove * @@ -434,6 +450,14 @@ private constructor( fun _addSpendThresholdConfiguration(): JsonField = body._addSpendThresholdConfiguration() + /** + * Returns the raw JSON value of [addSpendTrackers]. + * + * Unlike [addSpendTrackers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _addSpendTrackers(): JsonField> = body._addSpendTrackers() + /** * Returns the raw JSON value of [addSubscriptions]. * @@ -474,6 +498,14 @@ private constructor( fun _archiveScheduledCharges(): JsonField> = body._archiveScheduledCharges() + /** + * Returns the raw JSON value of [archiveSpendTrackers]. + * + * Unlike [archiveSpendTrackers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _archiveSpendTrackers(): JsonField> = body._archiveSpendTrackers() + /** * Returns the raw JSON value of [removeOverrides]. * @@ -939,6 +971,31 @@ private constructor( addSpendThresholdConfiguration: JsonField ) = apply { body.addSpendThresholdConfiguration(addSpendThresholdConfiguration) } + /** Spend trackers to add to this contract. Aliases must be unique within a contract. */ + fun addSpendTrackers(addSpendTrackers: List) = apply { + body.addSpendTrackers(addSpendTrackers) + } + + /** + * Sets [Builder.addSpendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.addSpendTrackers] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun addSpendTrackers(addSpendTrackers: JsonField>) = apply { + body.addSpendTrackers(addSpendTrackers) + } + + /** + * Adds a single [AddSpendTracker] to [addSpendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddSpendTracker(addSpendTracker: AddSpendTracker) = apply { + body.addAddSpendTracker(addSpendTracker) + } + /** * Optional list of * [subscriptions](https://docs.metronome.com/manage-product-access/create-subscription/) to @@ -1071,6 +1128,31 @@ private constructor( body.addArchiveScheduledCharge(archiveScheduledCharge) } + /** Aliases of spend trackers to archive. */ + fun archiveSpendTrackers(archiveSpendTrackers: List) = apply { + body.archiveSpendTrackers(archiveSpendTrackers) + } + + /** + * Sets [Builder.archiveSpendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.archiveSpendTrackers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun archiveSpendTrackers(archiveSpendTrackers: JsonField>) = apply { + body.archiveSpendTrackers(archiveSpendTrackers) + } + + /** + * Adds a single [String] to [archiveSpendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addArchiveSpendTracker(archiveSpendTracker: String) = apply { + body.addArchiveSpendTracker(archiveSpendTracker) + } + /** IDs of overrides to remove */ fun removeOverrides(removeOverrides: List) = apply { body.removeOverrides(removeOverrides) @@ -1553,11 +1635,13 @@ private constructor( JsonField, private val addScheduledCharges: JsonField>, private val addSpendThresholdConfiguration: JsonField, + private val addSpendTrackers: JsonField>, private val addSubscriptions: JsonField>, private val allowContractEndingBeforeFinalizedInvoice: JsonField, private val archiveCommits: JsonField>, private val archiveCredits: JsonField>, private val archiveScheduledCharges: JsonField>, + private val archiveSpendTrackers: JsonField>, private val removeOverrides: JsonField>, private val uniquenessKey: JsonField, private val updateCommits: JsonField>, @@ -1628,6 +1712,9 @@ private constructor( @ExcludeMissing addSpendThresholdConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("add_spend_trackers") + @ExcludeMissing + addSpendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("add_subscriptions") @ExcludeMissing addSubscriptions: JsonField> = JsonMissing.of(), @@ -1643,6 +1730,9 @@ private constructor( @JsonProperty("archive_scheduled_charges") @ExcludeMissing archiveScheduledCharges: JsonField> = JsonMissing.of(), + @JsonProperty("archive_spend_trackers") + @ExcludeMissing + archiveSpendTrackers: JsonField> = JsonMissing.of(), @JsonProperty("remove_overrides") @ExcludeMissing removeOverrides: JsonField> = JsonMissing.of(), @@ -1701,11 +1791,13 @@ private constructor( addRevenueSystemConfigurationUpdate, addScheduledCharges, addSpendThresholdConfiguration, + addSpendTrackers, addSubscriptions, allowContractEndingBeforeFinalizedInvoice, archiveCommits, archiveCredits, archiveScheduledCharges, + archiveSpendTrackers, removeOverrides, uniquenessKey, updateCommits, @@ -1841,6 +1933,15 @@ private constructor( fun addSpendThresholdConfiguration(): Optional = addSpendThresholdConfiguration.getOptional("add_spend_threshold_configuration") + /** + * Spend trackers to add to this contract. Aliases must be unique within a contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun addSpendTrackers(): Optional> = + addSpendTrackers.getOptional("add_spend_trackers") + /** * Optional list of * [subscriptions](https://docs.metronome.com/manage-product-access/create-subscription/) to @@ -1892,6 +1993,15 @@ private constructor( fun archiveScheduledCharges(): Optional> = archiveScheduledCharges.getOptional("archive_scheduled_charges") + /** + * Aliases of spend trackers to archive. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun archiveSpendTrackers(): Optional> = + archiveSpendTrackers.getOptional("archive_spend_trackers") + /** * IDs of overrides to remove * @@ -2158,6 +2268,16 @@ private constructor( fun _addSpendThresholdConfiguration(): JsonField = addSpendThresholdConfiguration + /** + * Returns the raw JSON value of [addSpendTrackers]. + * + * Unlike [addSpendTrackers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("add_spend_trackers") + @ExcludeMissing + fun _addSpendTrackers(): JsonField> = addSpendTrackers + /** * Returns the raw JSON value of [addSubscriptions]. * @@ -2210,6 +2330,16 @@ private constructor( fun _archiveScheduledCharges(): JsonField> = archiveScheduledCharges + /** + * Returns the raw JSON value of [archiveSpendTrackers]. + * + * Unlike [archiveSpendTrackers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("archive_spend_trackers") + @ExcludeMissing + fun _archiveSpendTrackers(): JsonField> = archiveSpendTrackers + /** * Returns the raw JSON value of [removeOverrides]. * @@ -2398,6 +2528,7 @@ private constructor( private var addScheduledCharges: JsonField>? = null private var addSpendThresholdConfiguration: JsonField = JsonMissing.of() + private var addSpendTrackers: JsonField>? = null private var addSubscriptions: JsonField>? = null private var allowContractEndingBeforeFinalizedInvoice: JsonField = JsonMissing.of() @@ -2405,6 +2536,7 @@ private constructor( private var archiveCredits: JsonField>? = null private var archiveScheduledCharges: JsonField>? = null + private var archiveSpendTrackers: JsonField>? = null private var removeOverrides: JsonField>? = null private var uniquenessKey: JsonField = JsonMissing.of() private var updateCommits: JsonField>? = null @@ -2445,12 +2577,14 @@ private constructor( addRevenueSystemConfigurationUpdate = body.addRevenueSystemConfigurationUpdate addScheduledCharges = body.addScheduledCharges.map { it.toMutableList() } addSpendThresholdConfiguration = body.addSpendThresholdConfiguration + addSpendTrackers = body.addSpendTrackers.map { it.toMutableList() } addSubscriptions = body.addSubscriptions.map { it.toMutableList() } allowContractEndingBeforeFinalizedInvoice = body.allowContractEndingBeforeFinalizedInvoice archiveCommits = body.archiveCommits.map { it.toMutableList() } archiveCredits = body.archiveCredits.map { it.toMutableList() } archiveScheduledCharges = body.archiveScheduledCharges.map { it.toMutableList() } + archiveSpendTrackers = body.archiveSpendTrackers.map { it.toMutableList() } removeOverrides = body.removeOverrides.map { it.toMutableList() } uniquenessKey = body.uniquenessKey updateCommits = body.updateCommits.map { it.toMutableList() } @@ -2817,6 +2951,33 @@ private constructor( addSpendThresholdConfiguration: JsonField ) = apply { this.addSpendThresholdConfiguration = addSpendThresholdConfiguration } + /** Spend trackers to add to this contract. Aliases must be unique within a contract. */ + fun addSpendTrackers(addSpendTrackers: List) = + addSpendTrackers(JsonField.of(addSpendTrackers)) + + /** + * Sets [Builder.addSpendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.addSpendTrackers] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun addSpendTrackers(addSpendTrackers: JsonField>) = apply { + this.addSpendTrackers = addSpendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [AddSpendTracker] to [addSpendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddSpendTracker(addSpendTracker: AddSpendTracker) = apply { + addSpendTrackers = + (addSpendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("addSpendTrackers", it).add(addSpendTracker) + } + } + /** * Optional list of * [subscriptions](https://docs.metronome.com/manage-product-access/create-subscription/) @@ -2958,6 +3119,33 @@ private constructor( } } + /** Aliases of spend trackers to archive. */ + fun archiveSpendTrackers(archiveSpendTrackers: List) = + archiveSpendTrackers(JsonField.of(archiveSpendTrackers)) + + /** + * Sets [Builder.archiveSpendTrackers] to an arbitrary JSON value. + * + * You should usually call [Builder.archiveSpendTrackers] with a well-typed + * `List` value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun archiveSpendTrackers(archiveSpendTrackers: JsonField>) = apply { + this.archiveSpendTrackers = archiveSpendTrackers.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [archiveSpendTrackers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addArchiveSpendTracker(archiveSpendTracker: String) = apply { + archiveSpendTrackers = + (archiveSpendTrackers ?: JsonField.of(mutableListOf())).also { + checkKnown("archiveSpendTrackers", it).add(archiveSpendTracker) + } + } + /** IDs of overrides to remove */ fun removeOverrides(removeOverrides: List) = removeOverrides(JsonField.of(removeOverrides)) @@ -3340,11 +3528,13 @@ private constructor( addRevenueSystemConfigurationUpdate, (addScheduledCharges ?: JsonMissing.of()).map { it.toImmutable() }, addSpendThresholdConfiguration, + (addSpendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, (addSubscriptions ?: JsonMissing.of()).map { it.toImmutable() }, allowContractEndingBeforeFinalizedInvoice, (archiveCommits ?: JsonMissing.of()).map { it.toImmutable() }, (archiveCredits ?: JsonMissing.of()).map { it.toImmutable() }, (archiveScheduledCharges ?: JsonMissing.of()).map { it.toImmutable() }, + (archiveSpendTrackers ?: JsonMissing.of()).map { it.toImmutable() }, (removeOverrides ?: JsonMissing.of()).map { it.toImmutable() }, uniquenessKey, (updateCommits ?: JsonMissing.of()).map { it.toImmutable() }, @@ -3393,11 +3583,13 @@ private constructor( addRevenueSystemConfigurationUpdate().ifPresent { it.validate() } addScheduledCharges().ifPresent { it.forEach { it.validate() } } addSpendThresholdConfiguration().ifPresent { it.validate() } + addSpendTrackers().ifPresent { it.forEach { it.validate() } } addSubscriptions().ifPresent { it.forEach { it.validate() } } allowContractEndingBeforeFinalizedInvoice() archiveCommits().ifPresent { it.forEach { it.validate() } } archiveCredits().ifPresent { it.forEach { it.validate() } } archiveScheduledCharges().ifPresent { it.forEach { it.validate() } } + archiveSpendTrackers() removeOverrides().ifPresent { it.forEach { it.validate() } } uniquenessKey() updateCommits().ifPresent { it.forEach { it.validate() } } @@ -3446,12 +3638,14 @@ private constructor( (addRevenueSystemConfigurationUpdate.asKnown().getOrNull()?.validity() ?: 0) + (addScheduledCharges.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (addSpendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (addSpendTrackers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (addSubscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (allowContractEndingBeforeFinalizedInvoice.asKnown().isPresent) 1 else 0) + (archiveCommits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (archiveCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (archiveScheduledCharges.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (archiveSpendTrackers.asKnown().getOrNull()?.size ?: 0) + (removeOverrides.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (uniquenessKey.asKnown().isPresent) 1 else 0) + (updateCommits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + @@ -3493,12 +3687,14 @@ private constructor( addRevenueSystemConfigurationUpdate == other.addRevenueSystemConfigurationUpdate && addScheduledCharges == other.addScheduledCharges && addSpendThresholdConfiguration == other.addSpendThresholdConfiguration && + addSpendTrackers == other.addSpendTrackers && addSubscriptions == other.addSubscriptions && allowContractEndingBeforeFinalizedInvoice == other.allowContractEndingBeforeFinalizedInvoice && archiveCommits == other.archiveCommits && archiveCredits == other.archiveCredits && archiveScheduledCharges == other.archiveScheduledCharges && + archiveSpendTrackers == other.archiveSpendTrackers && removeOverrides == other.removeOverrides && uniquenessKey == other.uniquenessKey && updateCommits == other.updateCommits && @@ -3533,11 +3729,13 @@ private constructor( addRevenueSystemConfigurationUpdate, addScheduledCharges, addSpendThresholdConfiguration, + addSpendTrackers, addSubscriptions, allowContractEndingBeforeFinalizedInvoice, archiveCommits, archiveCredits, archiveScheduledCharges, + archiveSpendTrackers, removeOverrides, uniquenessKey, updateCommits, @@ -3558,7 +3756,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{contractId=$contractId, customerId=$customerId, addBillingProviderConfigurationUpdate=$addBillingProviderConfigurationUpdate, addCommits=$addCommits, addCredits=$addCredits, addDiscounts=$addDiscounts, addOverrides=$addOverrides, addPrepaidBalanceThresholdConfiguration=$addPrepaidBalanceThresholdConfiguration, addProfessionalServices=$addProfessionalServices, addRecurringCommits=$addRecurringCommits, addRecurringCredits=$addRecurringCredits, addResellerRoyalties=$addResellerRoyalties, addRevenueSystemConfigurationUpdate=$addRevenueSystemConfigurationUpdate, addScheduledCharges=$addScheduledCharges, addSpendThresholdConfiguration=$addSpendThresholdConfiguration, addSubscriptions=$addSubscriptions, allowContractEndingBeforeFinalizedInvoice=$allowContractEndingBeforeFinalizedInvoice, archiveCommits=$archiveCommits, archiveCredits=$archiveCredits, archiveScheduledCharges=$archiveScheduledCharges, removeOverrides=$removeOverrides, uniquenessKey=$uniquenessKey, updateCommits=$updateCommits, updateContractEndDate=$updateContractEndDate, updateContractName=$updateContractName, updateCredits=$updateCredits, updateNetPaymentTermsDays=$updateNetPaymentTermsDays, updatePrepaidBalanceThresholdConfiguration=$updatePrepaidBalanceThresholdConfiguration, updateRecurringCommits=$updateRecurringCommits, updateRecurringCredits=$updateRecurringCredits, updateScheduledCharges=$updateScheduledCharges, updateSpendThresholdConfiguration=$updateSpendThresholdConfiguration, updateSubscriptions=$updateSubscriptions, additionalProperties=$additionalProperties}" + "Body{contractId=$contractId, customerId=$customerId, addBillingProviderConfigurationUpdate=$addBillingProviderConfigurationUpdate, addCommits=$addCommits, addCredits=$addCredits, addDiscounts=$addDiscounts, addOverrides=$addOverrides, addPrepaidBalanceThresholdConfiguration=$addPrepaidBalanceThresholdConfiguration, addProfessionalServices=$addProfessionalServices, addRecurringCommits=$addRecurringCommits, addRecurringCredits=$addRecurringCredits, addResellerRoyalties=$addResellerRoyalties, addRevenueSystemConfigurationUpdate=$addRevenueSystemConfigurationUpdate, addScheduledCharges=$addScheduledCharges, addSpendThresholdConfiguration=$addSpendThresholdConfiguration, addSpendTrackers=$addSpendTrackers, addSubscriptions=$addSubscriptions, allowContractEndingBeforeFinalizedInvoice=$allowContractEndingBeforeFinalizedInvoice, archiveCommits=$archiveCommits, archiveCredits=$archiveCredits, archiveScheduledCharges=$archiveScheduledCharges, archiveSpendTrackers=$archiveSpendTrackers, removeOverrides=$removeOverrides, uniquenessKey=$uniquenessKey, updateCommits=$updateCommits, updateContractEndDate=$updateContractEndDate, updateContractName=$updateContractName, updateCredits=$updateCredits, updateNetPaymentTermsDays=$updateNetPaymentTermsDays, updatePrepaidBalanceThresholdConfiguration=$updatePrepaidBalanceThresholdConfiguration, updateRecurringCommits=$updateRecurringCommits, updateRecurringCredits=$updateRecurringCredits, updateScheduledCharges=$updateScheduledCharges, updateSpendThresholdConfiguration=$updateSpendThresholdConfiguration, updateSubscriptions=$updateSubscriptions, additionalProperties=$additionalProperties}" } /** @@ -4748,6 +4946,7 @@ private constructor( private val rateType: JsonField, private val rolloverFraction: JsonField, private val specifiers: JsonField>, + private val spendTrackerAttributes: JsonField, private val temporaryId: JsonField, private val additionalProperties: MutableMap, ) { @@ -4799,6 +4998,9 @@ private constructor( @JsonProperty("specifiers") @ExcludeMissing specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + spendTrackerAttributes: JsonField = JsonMissing.of(), @JsonProperty("temporary_id") @ExcludeMissing temporaryId: JsonField = JsonMissing.of(), @@ -4820,6 +5022,7 @@ private constructor( rateType, rolloverFraction, specifiers, + spendTrackerAttributes, temporaryId, mutableMapOf(), ) @@ -4972,6 +5175,15 @@ private constructor( fun specifiers(): Optional> = specifiers.getOptional("specifiers") + /** + * Optional attributes for spend tracker integration. Immutable after creation. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun spendTrackerAttributes(): Optional = + spendTrackerAttributes.getOptional("spend_tracker_attributes") + /** * A temporary ID for the commit that can be used to reference the commit for commit * specific overrides. @@ -5132,6 +5344,16 @@ private constructor( @ExcludeMissing fun _specifiers(): JsonField> = specifiers + /** + * Returns the raw JSON value of [spendTrackerAttributes]. + * + * Unlike [spendTrackerAttributes], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_attributes") + @ExcludeMissing + fun _spendTrackerAttributes(): JsonField = spendTrackerAttributes + /** * Returns the raw JSON value of [temporaryId]. * @@ -5188,6 +5410,7 @@ private constructor( private var rateType: JsonField = JsonMissing.of() private var rolloverFraction: JsonField = JsonMissing.of() private var specifiers: JsonField>? = null + private var spendTrackerAttributes: JsonField = JsonMissing.of() private var temporaryId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -5210,6 +5433,7 @@ private constructor( rateType = addCommit.rateType rolloverFraction = addCommit.rolloverFraction specifiers = addCommit.specifiers.map { it.toMutableList() } + spendTrackerAttributes = addCommit.spendTrackerAttributes temporaryId = addCommit.temporaryId additionalProperties = addCommit.additionalProperties.toMutableMap() } @@ -5507,6 +5731,22 @@ private constructor( } } + /** Optional attributes for spend tracker integration. Immutable after creation. */ + fun spendTrackerAttributes(spendTrackerAttributes: SpendTrackerAttributes) = + spendTrackerAttributes(JsonField.of(spendTrackerAttributes)) + + /** + * Sets [Builder.spendTrackerAttributes] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAttributes] with a well-typed + * [SpendTrackerAttributes] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun spendTrackerAttributes(spendTrackerAttributes: JsonField) = + apply { + this.spendTrackerAttributes = spendTrackerAttributes + } + /** * A temporary ID for the commit that can be used to reference the commit for commit * specific overrides. @@ -5575,6 +5815,7 @@ private constructor( rateType, rolloverFraction, (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + spendTrackerAttributes, temporaryId, additionalProperties.toMutableMap(), ) @@ -5613,6 +5854,7 @@ private constructor( rateType().ifPresent { it.validate() } rolloverFraction() specifiers().ifPresent { it.forEach { it.validate() } } + spendTrackerAttributes().ifPresent { it.validate() } temporaryId() validated = true } @@ -5650,6 +5892,7 @@ private constructor( (rateType.asKnown().getOrNull()?.validity() ?: 0) + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendTrackerAttributes.asKnown().getOrNull()?.validity() ?: 0) + (if (temporaryId.asKnown().isPresent) 1 else 0) class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -9453,6 +9696,198 @@ private constructor( override fun toString() = value.toString() } + /** Optional attributes for spend tracker integration. Immutable after creation. */ + class SpendTrackerAttributes + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val countsAsDiscounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("counts_as_discounted") + @ExcludeMissing + countsAsDiscounted: JsonField = JsonMissing.of() + ) : this(countsAsDiscounted, mutableMapOf()) + + /** + * If true, this commit will be included in spend trackers with discounted set to + * DISCOUNTED_ONLY + * + * @throws MetronomeInvalidDataException 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 countsAsDiscounted(): Boolean = + countsAsDiscounted.getRequired("counts_as_discounted") + + /** + * Returns the raw JSON value of [countsAsDiscounted]. + * + * Unlike [countsAsDiscounted], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("counts_as_discounted") + @ExcludeMissing + fun _countsAsDiscounted(): JsonField = countsAsDiscounted + + @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 + * [SpendTrackerAttributes]. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendTrackerAttributes]. */ + class Builder internal constructor() { + + private var countsAsDiscounted: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendTrackerAttributes: SpendTrackerAttributes) = apply { + countsAsDiscounted = spendTrackerAttributes.countsAsDiscounted + additionalProperties = + spendTrackerAttributes.additionalProperties.toMutableMap() + } + + /** + * If true, this commit will be included in spend trackers with discounted set to + * DISCOUNTED_ONLY + */ + fun countsAsDiscounted(countsAsDiscounted: Boolean) = + countsAsDiscounted(JsonField.of(countsAsDiscounted)) + + /** + * Sets [Builder.countsAsDiscounted] to an arbitrary JSON value. + * + * You should usually call [Builder.countsAsDiscounted] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun countsAsDiscounted(countsAsDiscounted: JsonField) = apply { + this.countsAsDiscounted = countsAsDiscounted + } + + 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 [SpendTrackerAttributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .countsAsDiscounted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendTrackerAttributes = + SpendTrackerAttributes( + checkRequired("countsAsDiscounted", countsAsDiscounted), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SpendTrackerAttributes = apply { + if (validated) { + return@apply + } + + countsAsDiscounted() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (countsAsDiscounted.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendTrackerAttributes && + countsAsDiscounted == other.countsAsDiscounted && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(countsAsDiscounted, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendTrackerAttributes{countsAsDiscounted=$countsAsDiscounted, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -9476,6 +9911,7 @@ private constructor( rateType == other.rateType && rolloverFraction == other.rolloverFraction && specifiers == other.specifiers && + spendTrackerAttributes == other.spendTrackerAttributes && temporaryId == other.temporaryId && additionalProperties == other.additionalProperties } @@ -9499,6 +9935,7 @@ private constructor( rateType, rolloverFraction, specifiers, + spendTrackerAttributes, temporaryId, additionalProperties, ) @@ -9507,7 +9944,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "AddCommit{productId=$productId, type=$type, accessSchedule=$accessSchedule, amount=$amount, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, paymentGateConfig=$paymentGateConfig, priority=$priority, rateType=$rateType, rolloverFraction=$rolloverFraction, specifiers=$specifiers, temporaryId=$temporaryId, additionalProperties=$additionalProperties}" + "AddCommit{productId=$productId, type=$type, accessSchedule=$accessSchedule, amount=$amount, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, customFields=$customFields, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, paymentGateConfig=$paymentGateConfig, priority=$priority, rateType=$rateType, rolloverFraction=$rolloverFraction, specifiers=$specifiers, spendTrackerAttributes=$spendTrackerAttributes, temporaryId=$temporaryId, additionalProperties=$additionalProperties}" } class AddCredit @@ -26515,284 +26952,94 @@ private constructor( "AddScheduledCharge{productId=$productId, schedule=$schedule, customFields=$customFields, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, additionalProperties=$additionalProperties}" } - class AddSubscription + class AddSpendTracker @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val collectionSchedule: JsonField, - private val proration: JsonField, - private val subscriptionRate: JsonField, - private val customFields: JsonField, - private val description: JsonField, - private val endingBefore: JsonField, - private val initialQuantity: JsonField, - private val name: JsonField, - private val quantityManagementMode: JsonField, - private val seatConfig: JsonField, - private val startingAt: JsonField, - private val temporaryId: JsonField, + private val alias: JsonField, + private val applicableSpendSpecifiers: JsonField>, + private val creditTypeId: JsonField, + private val resetFrequency: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("collection_schedule") - @ExcludeMissing - collectionSchedule: JsonField = JsonMissing.of(), - @JsonProperty("proration") - @ExcludeMissing - proration: JsonField = JsonMissing.of(), - @JsonProperty("subscription_rate") - @ExcludeMissing - subscriptionRate: JsonField = JsonMissing.of(), - @JsonProperty("custom_fields") - @ExcludeMissing - customFields: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - description: JsonField = JsonMissing.of(), - @JsonProperty("ending_before") - @ExcludeMissing - endingBefore: JsonField = JsonMissing.of(), - @JsonProperty("initial_quantity") + @JsonProperty("alias") @ExcludeMissing alias: JsonField = JsonMissing.of(), + @JsonProperty("applicable_spend_specifiers") @ExcludeMissing - initialQuantity: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("quantity_management_mode") - @ExcludeMissing - quantityManagementMode: JsonField = JsonMissing.of(), - @JsonProperty("seat_config") - @ExcludeMissing - seatConfig: JsonField = JsonMissing.of(), - @JsonProperty("starting_at") + applicableSpendSpecifiers: JsonField> = JsonMissing.of(), + @JsonProperty("credit_type_id") @ExcludeMissing - startingAt: JsonField = JsonMissing.of(), - @JsonProperty("temporary_id") + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("reset_frequency") @ExcludeMissing - temporaryId: JsonField = JsonMissing.of(), - ) : this( - collectionSchedule, - proration, - subscriptionRate, - customFields, - description, - endingBefore, - initialQuantity, - name, - quantityManagementMode, - seatConfig, - startingAt, - temporaryId, - mutableMapOf(), - ) + resetFrequency: JsonField = JsonMissing.of(), + ) : this(alias, applicableSpendSpecifiers, creditTypeId, resetFrequency, mutableMapOf()) /** + * Human-readable identifier, unique per contract. + * * @throws MetronomeInvalidDataException 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 collectionSchedule(): CollectionSchedule = - collectionSchedule.getRequired("collection_schedule") + fun alias(): String = alias.getRequired("alias") /** * @throws MetronomeInvalidDataException 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 proration(): Proration = proration.getRequired("proration") + fun applicableSpendSpecifiers(): List = + applicableSpendSpecifiers.getRequired("applicable_spend_specifiers") /** * @throws MetronomeInvalidDataException 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 subscriptionRate(): SubscriptionRate = subscriptionRate.getRequired("subscription_rate") - - /** - * Custom fields to be added eg. { "key1": "value1", "key2": "value2" } - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun customFields(): Optional = customFields.getOptional("custom_fields") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = description.getOptional("description") - - /** - * Exclusive end time for the subscription. If not provided, subscription inherits contract - * end date. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun endingBefore(): Optional = endingBefore.getOptional("ending_before") - - /** - * The initial quantity for the subscription. It must be non-negative value. Required if - * quantity_management_mode is QUANTITY_ONLY. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun initialQuantity(): Optional = initialQuantity.getOptional("initial_quantity") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = name.getOptional("name") - - /** - * Determines how the subscription's quantity is controlled. Defaults to QUANTITY_ONLY. - * **QUANTITY_ONLY**: The subscription quantity is specified directly on the subscription. - * `initial_quantity` must be provided with this option. Compatible with recurring - * commits/credits that use POOLED allocation. **SEAT_BASED**: Use when you want to pass - * specific seat identifiers (e.g. add user_123) to increment and decrement a subscription - * quantity, rather than directly providing the quantity. You must use a **SEAT_BASED** - * subscription to use a linked recurring credit with an allocation per seat. `seat_config` - * must be provided with this option. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun quantityManagementMode(): Optional = - quantityManagementMode.getOptional("quantity_management_mode") - - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun seatConfig(): Optional = seatConfig.getOptional("seat_config") + fun creditTypeId(): String = creditTypeId.getRequired("credit_type_id") /** - * Inclusive start time for the subscription. If not provided, defaults to contract start - * date - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws MetronomeInvalidDataException 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 startingAt(): Optional = startingAt.getOptional("starting_at") + fun resetFrequency(): ResetFrequency = resetFrequency.getRequired("reset_frequency") /** - * A temporary ID used to reference the subscription in recurring commit/credit subscription - * configs created within the same payload. + * Returns the raw JSON value of [alias]. * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Unlike [alias], this method doesn't throw if the JSON field has an unexpected type. */ - fun temporaryId(): Optional = temporaryId.getOptional("temporary_id") + @JsonProperty("alias") @ExcludeMissing fun _alias(): JsonField = alias /** - * Returns the raw JSON value of [collectionSchedule]. + * Returns the raw JSON value of [applicableSpendSpecifiers]. * - * Unlike [collectionSchedule], this method doesn't throw if the JSON field has an + * Unlike [applicableSpendSpecifiers], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("collection_schedule") - @ExcludeMissing - fun _collectionSchedule(): JsonField = collectionSchedule - - /** - * Returns the raw JSON value of [proration]. - * - * Unlike [proration], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("proration") - @ExcludeMissing - fun _proration(): JsonField = proration - - /** - * Returns the raw JSON value of [subscriptionRate]. - * - * Unlike [subscriptionRate], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("subscription_rate") - @ExcludeMissing - fun _subscriptionRate(): JsonField = subscriptionRate - - /** - * Returns the raw JSON value of [customFields]. - * - * Unlike [customFields], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("custom_fields") - @ExcludeMissing - fun _customFields(): JsonField = customFields - - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") + @JsonProperty("applicable_spend_specifiers") @ExcludeMissing - fun _description(): JsonField = description + fun _applicableSpendSpecifiers(): JsonField> = + applicableSpendSpecifiers /** - * Returns the raw JSON value of [endingBefore]. + * Returns the raw JSON value of [creditTypeId]. * - * Unlike [endingBefore], this method doesn't throw if the JSON field has an unexpected + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an unexpected * type. */ - @JsonProperty("ending_before") + @JsonProperty("credit_type_id") @ExcludeMissing - fun _endingBefore(): JsonField = endingBefore + fun _creditTypeId(): JsonField = creditTypeId /** - * Returns the raw JSON value of [initialQuantity]. + * Returns the raw JSON value of [resetFrequency]. * - * Unlike [initialQuantity], this method doesn't throw if the JSON field has an unexpected + * Unlike [resetFrequency], this method doesn't throw if the JSON field has an unexpected * type. */ - @JsonProperty("initial_quantity") - @ExcludeMissing - fun _initialQuantity(): JsonField = initialQuantity - - /** - * 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 [quantityManagementMode]. - * - * Unlike [quantityManagementMode], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("quantity_management_mode") - @ExcludeMissing - fun _quantityManagementMode(): JsonField = quantityManagementMode - - /** - * Returns the raw JSON value of [seatConfig]. - * - * Unlike [seatConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("seat_config") - @ExcludeMissing - fun _seatConfig(): JsonField = seatConfig - - /** - * Returns the raw JSON value of [startingAt]. - * - * Unlike [startingAt], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("starting_at") - @ExcludeMissing - fun _startingAt(): JsonField = startingAt - - /** - * Returns the raw JSON value of [temporaryId]. - * - * Unlike [temporaryId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("temporary_id") + @JsonProperty("reset_frequency") @ExcludeMissing - fun _temporaryId(): JsonField = temporaryId + fun _resetFrequency(): JsonField = resetFrequency @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -26809,235 +27056,109 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [AddSubscription]. + * Returns a mutable builder for constructing an instance of [AddSpendTracker]. * * The following fields are required: * ```java - * .collectionSchedule() - * .proration() - * .subscriptionRate() + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [AddSubscription]. */ + /** A builder for [AddSpendTracker]. */ class Builder internal constructor() { - private var collectionSchedule: JsonField? = null - private var proration: JsonField? = null - private var subscriptionRate: JsonField? = null - private var customFields: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() - private var endingBefore: JsonField = JsonMissing.of() - private var initialQuantity: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var quantityManagementMode: JsonField = JsonMissing.of() - private var seatConfig: JsonField = JsonMissing.of() - private var startingAt: JsonField = JsonMissing.of() - private var temporaryId: JsonField = JsonMissing.of() + private var alias: JsonField? = null + private var applicableSpendSpecifiers: + JsonField>? = + null + private var creditTypeId: JsonField? = null + private var resetFrequency: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(addSubscription: AddSubscription) = apply { - collectionSchedule = addSubscription.collectionSchedule - proration = addSubscription.proration - subscriptionRate = addSubscription.subscriptionRate - customFields = addSubscription.customFields - description = addSubscription.description - endingBefore = addSubscription.endingBefore - initialQuantity = addSubscription.initialQuantity - name = addSubscription.name - quantityManagementMode = addSubscription.quantityManagementMode - seatConfig = addSubscription.seatConfig - startingAt = addSubscription.startingAt - temporaryId = addSubscription.temporaryId - additionalProperties = addSubscription.additionalProperties.toMutableMap() - } - - fun collectionSchedule(collectionSchedule: CollectionSchedule) = - collectionSchedule(JsonField.of(collectionSchedule)) - - /** - * Sets [Builder.collectionSchedule] to an arbitrary JSON value. - * - * You should usually call [Builder.collectionSchedule] with a well-typed - * [CollectionSchedule] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun collectionSchedule(collectionSchedule: JsonField) = apply { - this.collectionSchedule = collectionSchedule - } - - fun proration(proration: Proration) = proration(JsonField.of(proration)) - - /** - * Sets [Builder.proration] to an arbitrary JSON value. - * - * You should usually call [Builder.proration] with a well-typed [Proration] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun proration(proration: JsonField) = apply { this.proration = proration } - - fun subscriptionRate(subscriptionRate: SubscriptionRate) = - subscriptionRate(JsonField.of(subscriptionRate)) - - /** - * Sets [Builder.subscriptionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.subscriptionRate] with a well-typed - * [SubscriptionRate] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun subscriptionRate(subscriptionRate: JsonField) = apply { - this.subscriptionRate = subscriptionRate - } - - /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ - fun customFields(customFields: CustomFields) = customFields(JsonField.of(customFields)) - - /** - * Sets [Builder.customFields] to an arbitrary JSON value. - * - * You should usually call [Builder.customFields] with a well-typed [CustomFields] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun customFields(customFields: JsonField) = apply { - this.customFields = customFields + internal fun from(addSpendTracker: AddSpendTracker) = apply { + alias = addSpendTracker.alias + applicableSpendSpecifiers = + addSpendTracker.applicableSpendSpecifiers.map { it.toMutableList() } + creditTypeId = addSpendTracker.creditTypeId + resetFrequency = addSpendTracker.resetFrequency + additionalProperties = addSpendTracker.additionalProperties.toMutableMap() } - fun description(description: String) = description(JsonField.of(description)) + /** Human-readable identifier, unique per contract. */ + fun alias(alias: String) = alias(JsonField.of(alias)) /** - * Sets [Builder.description] to an arbitrary JSON value. + * Sets [Builder.alias] to an arbitrary JSON value. * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet + * You should usually call [Builder.alias] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** - * Exclusive end time for the subscription. If not provided, subscription inherits - * contract end date. - */ - fun endingBefore(endingBefore: OffsetDateTime) = - endingBefore(JsonField.of(endingBefore)) - - /** - * Sets [Builder.endingBefore] to an arbitrary JSON value. - * - * You should usually call [Builder.endingBefore] with a well-typed [OffsetDateTime] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun endingBefore(endingBefore: JsonField) = apply { - this.endingBefore = endingBefore - } + fun alias(alias: JsonField) = apply { this.alias = alias } - /** - * The initial quantity for the subscription. It must be non-negative value. Required if - * quantity_management_mode is QUANTITY_ONLY. - */ - fun initialQuantity(initialQuantity: Double) = - initialQuantity(JsonField.of(initialQuantity)) + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: List + ) = applicableSpendSpecifiers(JsonField.of(applicableSpendSpecifiers)) /** - * Sets [Builder.initialQuantity] to an arbitrary JSON value. + * Sets [Builder.applicableSpendSpecifiers] to an arbitrary JSON value. * - * You should usually call [Builder.initialQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.applicableSpendSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. */ - fun initialQuantity(initialQuantity: JsonField) = apply { - this.initialQuantity = initialQuantity + fun applicableSpendSpecifiers( + applicableSpendSpecifiers: JsonField> + ) = apply { + this.applicableSpendSpecifiers = + applicableSpendSpecifiers.map { it.toMutableList() } } - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - /** - * Determines how the subscription's quantity is controlled. Defaults to QUANTITY_ONLY. - * **QUANTITY_ONLY**: The subscription quantity is specified directly on the - * subscription. `initial_quantity` must be provided with this option. Compatible with - * recurring commits/credits that use POOLED allocation. **SEAT_BASED**: Use when you - * want to pass specific seat identifiers (e.g. add user_123) to increment and decrement - * a subscription quantity, rather than directly providing the quantity. You must use a - * **SEAT_BASED** subscription to use a linked recurring credit with an allocation per - * seat. `seat_config` must be provided with this option. - */ - fun quantityManagementMode(quantityManagementMode: QuantityManagementMode) = - quantityManagementMode(JsonField.of(quantityManagementMode)) - - /** - * Sets [Builder.quantityManagementMode] to an arbitrary JSON value. + * Adds a single [ApplicableSpendSpecifier] to [applicableSpendSpecifiers]. * - * You should usually call [Builder.quantityManagementMode] with a well-typed - * [QuantityManagementMode] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun quantityManagementMode(quantityManagementMode: JsonField) = + fun addApplicableSpendSpecifier(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { - this.quantityManagementMode = quantityManagementMode + applicableSpendSpecifiers = + (applicableSpendSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableSpendSpecifiers", it) + .add(applicableSpendSpecifier) + } } - fun seatConfig(seatConfig: SeatConfig) = seatConfig(JsonField.of(seatConfig)) - - /** - * Sets [Builder.seatConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.seatConfig] with a well-typed [SeatConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun seatConfig(seatConfig: JsonField) = apply { - this.seatConfig = seatConfig - } - - /** - * Inclusive start time for the subscription. If not provided, defaults to contract - * start date - */ - fun startingAt(startingAt: OffsetDateTime) = startingAt(JsonField.of(startingAt)) + fun creditTypeId(creditTypeId: String) = creditTypeId(JsonField.of(creditTypeId)) /** - * Sets [Builder.startingAt] to an arbitrary JSON value. + * Sets [Builder.creditTypeId] to an arbitrary JSON value. * - * You should usually call [Builder.startingAt] with a well-typed [OffsetDateTime] value + * You should usually call [Builder.creditTypeId] with a well-typed [String] value * instead. This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun startingAt(startingAt: JsonField) = apply { - this.startingAt = startingAt + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId } - /** - * A temporary ID used to reference the subscription in recurring commit/credit - * subscription configs created within the same payload. - */ - fun temporaryId(temporaryId: String) = temporaryId(JsonField.of(temporaryId)) + fun resetFrequency(resetFrequency: ResetFrequency) = + resetFrequency(JsonField.of(resetFrequency)) /** - * Sets [Builder.temporaryId] to an arbitrary JSON value. + * Sets [Builder.resetFrequency] to an arbitrary JSON value. * - * You should usually call [Builder.temporaryId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.resetFrequency] with a well-typed [ResetFrequency] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. */ - fun temporaryId(temporaryId: JsonField) = apply { - this.temporaryId = temporaryId + fun resetFrequency(resetFrequency: JsonField) = apply { + this.resetFrequency = resetFrequency } fun additionalProperties(additionalProperties: Map) = apply { @@ -27060,33 +27181,28 @@ private constructor( } /** - * Returns an immutable instance of [AddSubscription]. + * Returns an immutable instance of [AddSpendTracker]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java - * .collectionSchedule() - * .proration() - * .subscriptionRate() + * .alias() + * .applicableSpendSpecifiers() + * .creditTypeId() + * .resetFrequency() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): AddSubscription = - AddSubscription( - checkRequired("collectionSchedule", collectionSchedule), - checkRequired("proration", proration), - checkRequired("subscriptionRate", subscriptionRate), - customFields, - description, - endingBefore, - initialQuantity, - name, - quantityManagementMode, - seatConfig, - startingAt, - temporaryId, + fun build(): AddSpendTracker = + AddSpendTracker( + checkRequired("alias", alias), + checkRequired("applicableSpendSpecifiers", applicableSpendSpecifiers).map { + it.toImmutable() + }, + checkRequired("creditTypeId", creditTypeId), + checkRequired("resetFrequency", resetFrequency), additionalProperties.toMutableMap(), ) } @@ -27102,23 +27218,15 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't match its * expected type. */ - fun validate(): AddSubscription = apply { + fun validate(): AddSpendTracker = apply { if (validated) { return@apply } - collectionSchedule().validate() - proration().validate() - subscriptionRate().validate() - customFields().ifPresent { it.validate() } - description() - endingBefore() - initialQuantity() - name() - quantityManagementMode().ifPresent { it.validate() } - seatConfig().ifPresent { it.validate() } - startingAt() - temporaryId() + alias() + applicableSpendSpecifiers().forEach { it.validate() } + creditTypeId() + resetFrequency().validate() validated = true } @@ -27138,221 +27246,84 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (collectionSchedule.asKnown().getOrNull()?.validity() ?: 0) + - (proration.asKnown().getOrNull()?.validity() ?: 0) + - (subscriptionRate.asKnown().getOrNull()?.validity() ?: 0) + - (customFields.asKnown().getOrNull()?.validity() ?: 0) + - (if (description.asKnown().isPresent) 1 else 0) + - (if (endingBefore.asKnown().isPresent) 1 else 0) + - (if (initialQuantity.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (quantityManagementMode.asKnown().getOrNull()?.validity() ?: 0) + - (seatConfig.asKnown().getOrNull()?.validity() ?: 0) + - (if (startingAt.asKnown().isPresent) 1 else 0) + - (if (temporaryId.asKnown().isPresent) 1 else 0) + (if (alias.asKnown().isPresent) 1 else 0) + + (applicableSpendSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (creditTypeId.asKnown().isPresent) 1 else 0) + + (resetFrequency.asKnown().getOrNull()?.validity() ?: 0) - class CollectionSchedule - @JsonCreator - private constructor(private val value: JsonField) : Enum { + class ApplicableSpendSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sources: JsonField>, + private val spendType: JsonField, + private val discounted: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("sources") + @ExcludeMissing + sources: JsonField> = JsonMissing.of(), + @JsonProperty("spend_type") + @ExcludeMissing + spendType: JsonField = JsonMissing.of(), + @JsonProperty("discounted") + @ExcludeMissing + discounted: JsonField = JsonMissing.of(), + ) : this(sources, spendType, discounted, mutableMapOf()) /** - * 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. + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + fun sources(): List = sources.getRequired("sources") - companion object { - - @JvmField val ADVANCE = of("ADVANCE") + /** + * @throws MetronomeInvalidDataException 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 spendType(): SpendType = spendType.getRequired("spend_type") - @JvmField val ARREARS = of("ARREARS") + /** + * Filter by whether the spend was discounted. Defaults to ANY if omitted. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun discounted(): Optional = discounted.getOptional("discounted") - @JvmStatic fun of(value: String) = CollectionSchedule(JsonField.of(value)) - } - - /** An enum containing [CollectionSchedule]'s known values. */ - enum class Known { - ADVANCE, - ARREARS, - } - - /** - * An enum containing [CollectionSchedule]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [CollectionSchedule] 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 { - ADVANCE, - ARREARS, - /** - * An enum member indicating that [CollectionSchedule] 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) { - ADVANCE -> Value.ADVANCE - ARREARS -> Value.ARREARS - 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 MetronomeInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - ADVANCE -> Known.ADVANCE - ARREARS -> Known.ARREARS - else -> - throw MetronomeInvalidDataException("Unknown CollectionSchedule: $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 MetronomeInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - MetronomeInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): CollectionSchedule = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 CollectionSchedule && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Proration - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val invoiceBehavior: JsonField, - private val isProrated: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("invoice_behavior") - @ExcludeMissing - invoiceBehavior: JsonField = JsonMissing.of(), - @JsonProperty("is_prorated") - @ExcludeMissing - isProrated: JsonField = JsonMissing.of(), - ) : this(invoiceBehavior, isProrated, mutableMapOf()) - - /** - * Indicates how mid-period quantity adjustments are invoiced. **BILL_IMMEDIATELY**: - * Only available when collection schedule is `ADVANCE`. The quantity increase will be - * billed immediately on the scheduled date. **BILL_ON_NEXT_COLLECTION_DATE**: The - * quantity increase will be billed for in-arrears at the end of the period. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun invoiceBehavior(): Optional = - invoiceBehavior.getOptional("invoice_behavior") - - /** - * Indicates if the partial period will be prorated or charged a full amount. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun isProrated(): Optional = isProrated.getOptional("is_prorated") + /** + * Returns the raw JSON value of [sources]. + * + * Unlike [sources], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sources") + @ExcludeMissing + fun _sources(): JsonField> = sources /** - * Returns the raw JSON value of [invoiceBehavior]. + * Returns the raw JSON value of [spendType]. * - * Unlike [invoiceBehavior], this method doesn't throw if the JSON field has an - * unexpected type. + * Unlike [spendType], this method doesn't throw if the JSON field has an unexpected + * type. */ - @JsonProperty("invoice_behavior") + @JsonProperty("spend_type") @ExcludeMissing - fun _invoiceBehavior(): JsonField = invoiceBehavior + fun _spendType(): JsonField = spendType /** - * Returns the raw JSON value of [isProrated]. + * Returns the raw JSON value of [discounted]. * - * Unlike [isProrated], this method doesn't throw if the JSON field has an unexpected + * Unlike [discounted], this method doesn't throw if the JSON field has an unexpected * type. */ - @JsonProperty("is_prorated") + @JsonProperty("discounted") @ExcludeMissing - fun _isProrated(): JsonField = isProrated + fun _discounted(): JsonField = discounted @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -27368,56 +27339,86 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Proration]. */ + /** + * Returns a mutable builder for constructing an instance of + * [ApplicableSpendSpecifier]. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + */ @JvmStatic fun builder() = Builder() } - /** A builder for [Proration]. */ + /** A builder for [ApplicableSpendSpecifier]. */ class Builder internal constructor() { - private var invoiceBehavior: JsonField = JsonMissing.of() - private var isProrated: JsonField = JsonMissing.of() + private var sources: JsonField>? = null + private var spendType: JsonField? = null + private var discounted: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(proration: Proration) = apply { - invoiceBehavior = proration.invoiceBehavior - isProrated = proration.isProrated - additionalProperties = proration.additionalProperties.toMutableMap() + internal fun from(applicableSpendSpecifier: ApplicableSpendSpecifier) = apply { + sources = applicableSpendSpecifier.sources.map { it.toMutableList() } + spendType = applicableSpendSpecifier.spendType + discounted = applicableSpendSpecifier.discounted + additionalProperties = + applicableSpendSpecifier.additionalProperties.toMutableMap() } + fun sources(sources: List) = sources(JsonField.of(sources)) + /** - * Indicates how mid-period quantity adjustments are invoiced. **BILL_IMMEDIATELY**: - * Only available when collection schedule is `ADVANCE`. The quantity increase will - * be billed immediately on the scheduled date. **BILL_ON_NEXT_COLLECTION_DATE**: - * The quantity increase will be billed for in-arrears at the end of the period. + * Sets [Builder.sources] to an arbitrary JSON value. + * + * You should usually call [Builder.sources] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - fun invoiceBehavior(invoiceBehavior: InvoiceBehavior) = - invoiceBehavior(JsonField.of(invoiceBehavior)) + fun sources(sources: JsonField>) = apply { + this.sources = sources.map { it.toMutableList() } + } /** - * Sets [Builder.invoiceBehavior] to an arbitrary JSON value. + * Adds a single [Source] to [sources]. * - * You should usually call [Builder.invoiceBehavior] with a well-typed - * [InvoiceBehavior] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun invoiceBehavior(invoiceBehavior: JsonField) = apply { - this.invoiceBehavior = invoiceBehavior + fun addSource(source: Source) = apply { + sources = + (sources ?: JsonField.of(mutableListOf())).also { + checkKnown("sources", it).add(source) + } } - /** Indicates if the partial period will be prorated or charged a full amount. */ - fun isProrated(isProrated: Boolean) = isProrated(JsonField.of(isProrated)) + fun spendType(spendType: SpendType) = spendType(JsonField.of(spendType)) /** - * Sets [Builder.isProrated] to an arbitrary JSON value. + * Sets [Builder.spendType] to an arbitrary JSON value. * - * You should usually call [Builder.isProrated] with a well-typed [Boolean] value + * You should usually call [Builder.spendType] with a well-typed [SpendType] value * instead. This method is primarily for setting the field to an undocumented or not * yet supported value. */ - fun isProrated(isProrated: JsonField) = apply { - this.isProrated = isProrated + fun spendType(spendType: JsonField) = apply { + this.spendType = spendType + } + + /** Filter by whether the spend was discounted. Defaults to ANY if omitted. */ + fun discounted(discounted: Discounted) = discounted(JsonField.of(discounted)) + + /** + * Sets [Builder.discounted] to an arbitrary JSON value. + * + * You should usually call [Builder.discounted] with a well-typed [Discounted] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun discounted(discounted: JsonField) = apply { + this.discounted = discounted } fun additionalProperties(additionalProperties: Map) = apply { @@ -27443,12 +27444,25 @@ private constructor( } /** - * Returns an immutable instance of [Proration]. + * Returns an immutable instance of [ApplicableSpendSpecifier]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sources() + * .spendType() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Proration = - Proration(invoiceBehavior, isProrated, additionalProperties.toMutableMap()) + fun build(): ApplicableSpendSpecifier = + ApplicableSpendSpecifier( + checkRequired("sources", sources).map { it.toImmutable() }, + checkRequired("spendType", spendType), + discounted, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -27463,13 +27477,14 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't match * its expected type. */ - fun validate(): Proration = apply { + fun validate(): ApplicableSpendSpecifier = apply { if (validated) { return@apply } - invoiceBehavior().ifPresent { it.validate() } - isProrated() + sources().forEach { it.validate() } + spendType().validate() + discounted().ifPresent { it.validate() } validated = true } @@ -27489,18 +27504,12 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (invoiceBehavior.asKnown().getOrNull()?.validity() ?: 0) + - (if (isProrated.asKnown().isPresent) 1 else 0) + (sources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (spendType.asKnown().getOrNull()?.validity() ?: 0) + + (discounted.asKnown().getOrNull()?.validity() ?: 0) - /** - * Indicates how mid-period quantity adjustments are invoiced. **BILL_IMMEDIATELY**: - * Only available when collection schedule is `ADVANCE`. The quantity increase will be - * billed immediately on the scheduled date. **BILL_ON_NEXT_COLLECTION_DATE**: The - * quantity increase will be billed for in-arrears at the end of the period. - */ - class InvoiceBehavior - @JsonCreator - private constructor(private val value: JsonField) : Enum { + class Source @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -27514,36 +27523,34 @@ private constructor( companion object { - @JvmField val BILL_IMMEDIATELY = of("BILL_IMMEDIATELY") + @JvmField val THRESHOLD_RECHARGE = of("THRESHOLD_RECHARGE") - @JvmField val BILL_ON_NEXT_COLLECTION_DATE = of("BILL_ON_NEXT_COLLECTION_DATE") + @JvmField val MANUAL = of("MANUAL") - @JvmStatic fun of(value: String) = InvoiceBehavior(JsonField.of(value)) + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) } - /** An enum containing [InvoiceBehavior]'s known values. */ + /** An enum containing [Source]'s known values. */ enum class Known { - BILL_IMMEDIATELY, - BILL_ON_NEXT_COLLECTION_DATE, + THRESHOLD_RECHARGE, + MANUAL, } /** - * An enum containing [InvoiceBehavior]'s known values, as well as an [_UNKNOWN] - * member. + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [InvoiceBehavior] can contain an unknown value in a couple of - * cases: + * An instance of [Source] 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 { - BILL_IMMEDIATELY, - BILL_ON_NEXT_COLLECTION_DATE, + THRESHOLD_RECHARGE, + MANUAL, /** - * An enum member indicating that [InvoiceBehavior] was instantiated with an - * unknown value. + * An enum member indicating that [Source] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -27557,8 +27564,8 @@ private constructor( */ fun value(): Value = when (this) { - BILL_IMMEDIATELY -> Value.BILL_IMMEDIATELY - BILL_ON_NEXT_COLLECTION_DATE -> Value.BILL_ON_NEXT_COLLECTION_DATE + THRESHOLD_RECHARGE -> Value.THRESHOLD_RECHARGE + MANUAL -> Value.MANUAL else -> Value._UNKNOWN } @@ -27573,10 +27580,9 @@ private constructor( */ fun known(): Known = when (this) { - BILL_IMMEDIATELY -> Known.BILL_IMMEDIATELY - BILL_ON_NEXT_COLLECTION_DATE -> Known.BILL_ON_NEXT_COLLECTION_DATE - else -> - throw MetronomeInvalidDataException("Unknown InvoiceBehavior: $value") + THRESHOLD_RECHARGE -> Known.THRESHOLD_RECHARGE + MANUAL -> Known.MANUAL + else -> throw MetronomeInvalidDataException("Unknown Source: $value") } /** @@ -27605,7 +27611,7 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't * match its expected type. */ - fun validate(): InvoiceBehavior = apply { + fun validate(): Source = apply { if (validated) { return@apply } @@ -27635,7 +27641,7 @@ private constructor( return true } - return other is InvoiceBehavior && value == other.value + return other is Source && value == other.value } override fun hashCode() = value.hashCode() @@ -27643,297 +27649,190 @@ private constructor( override fun toString() = value.toString() } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Proration && - invoiceBehavior == other.invoiceBehavior && - isProrated == other.isProrated && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(invoiceBehavior, isProrated, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Proration{invoiceBehavior=$invoiceBehavior, isProrated=$isProrated, additionalProperties=$additionalProperties}" - } - - class SubscriptionRate - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val billingFrequency: JsonField, - private val productId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("billing_frequency") - @ExcludeMissing - billingFrequency: JsonField = JsonMissing.of(), - @JsonProperty("product_id") - @ExcludeMissing - productId: JsonField = JsonMissing.of(), - ) : this(billingFrequency, productId, mutableMapOf()) + class SpendType @JsonCreator private constructor(private val value: JsonField) : + Enum { - /** - * Frequency to bill subscription with. Together with product_id, must match existing - * rate on the rate card. - * - * @throws MetronomeInvalidDataException 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 billingFrequency(): BillingFrequency = - billingFrequency.getRequired("billing_frequency") + /** + * 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 - /** - * Must be subscription type product - * - * @throws MetronomeInvalidDataException 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 productId(): String = productId.getRequired("product_id") + companion object { - /** - * Returns the raw JSON value of [billingFrequency]. - * - * Unlike [billingFrequency], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_frequency") - @ExcludeMissing - fun _billingFrequency(): JsonField = billingFrequency + @JvmField val COMMIT_PURCHASE = of("COMMIT_PURCHASE") - /** - * Returns the raw JSON value of [productId]. - * - * Unlike [productId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("product_id") - @ExcludeMissing - fun _productId(): JsonField = productId + @JvmStatic fun of(value: String) = SpendType(JsonField.of(value)) + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** An enum containing [SpendType]'s known values. */ + enum class Known { + COMMIT_PURCHASE + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * An enum containing [SpendType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SpendType] 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 { + COMMIT_PURCHASE, + /** + * An enum member indicating that [SpendType] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - fun toBuilder() = Builder().from(this) + /** + * 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) { + COMMIT_PURCHASE -> Value.COMMIT_PURCHASE + else -> Value._UNKNOWN + } - companion object { + /** + * 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + COMMIT_PURCHASE -> Known.COMMIT_PURCHASE + else -> throw MetronomeInvalidDataException("Unknown SpendType: $value") + } /** - * Returns a mutable builder for constructing an instance of [SubscriptionRate]. + * Returns this class instance's primitive wire representation. * - * The following fields are required: - * ```java - * .billingFrequency() - * .productId() - * ``` + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. */ - @JvmStatic fun builder() = Builder() - } + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } - /** A builder for [SubscriptionRate]. */ - class Builder internal constructor() { + private var validated: Boolean = false - private var billingFrequency: JsonField? = null - private var productId: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): SpendType = apply { + if (validated) { + return@apply + } - @JvmSynthetic - internal fun from(subscriptionRate: SubscriptionRate) = apply { - billingFrequency = subscriptionRate.billingFrequency - productId = subscriptionRate.productId - additionalProperties = subscriptionRate.additionalProperties.toMutableMap() + known() + validated = true } - /** - * Frequency to bill subscription with. Together with product_id, must match - * existing rate on the rate card. - */ - fun billingFrequency(billingFrequency: BillingFrequency) = - billingFrequency(JsonField.of(billingFrequency)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } /** - * Sets [Builder.billingFrequency] to an arbitrary JSON value. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * You should usually call [Builder.billingFrequency] with a well-typed - * [BillingFrequency] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. + * Used for best match union deserialization. */ - fun billingFrequency(billingFrequency: JsonField) = apply { - this.billingFrequency = billingFrequency + @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 SpendType && value == other.value } - /** Must be subscription type product */ - fun productId(productId: String) = productId(JsonField.of(productId)) + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Filter by whether the spend was discounted. Defaults to ANY if omitted. */ + class Discounted + @JsonCreator + private constructor(private val value: JsonField) : Enum { /** - * Sets [Builder.productId] to an arbitrary JSON value. + * Returns this class instance's raw value. * - * You should usually call [Builder.productId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported 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. */ - fun productId(productId: JsonField) = apply { this.productId = productId } + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + companion object { - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + @JvmField val ANY = of("ANY") - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + @JvmField val DISCOUNTED_ONLY = of("DISCOUNTED_ONLY") - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + @JvmField val UNDISCOUNTED_ONLY = of("UNDISCOUNTED_ONLY") - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) + @JvmStatic fun of(value: String) = Discounted(JsonField.of(value)) } - /** - * Returns an immutable instance of [SubscriptionRate]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .billingFrequency() - * .productId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): SubscriptionRate = - SubscriptionRate( - checkRequired("billingFrequency", billingFrequency), - checkRequired("productId", productId), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): SubscriptionRate = apply { - if (validated) { - return@apply - } - - billingFrequency().validate() - productId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 = - (billingFrequency.asKnown().getOrNull()?.validity() ?: 0) + - (if (productId.asKnown().isPresent) 1 else 0) - - /** - * Frequency to bill subscription with. Together with product_id, must match existing - * rate on the rate card. - */ - class BillingFrequency - @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 MONTHLY = of("MONTHLY") - - @JvmField val QUARTERLY = of("QUARTERLY") - - @JvmField val ANNUAL = of("ANNUAL") - - @JvmField val WEEKLY = of("WEEKLY") - - @JvmStatic fun of(value: String) = BillingFrequency(JsonField.of(value)) - } - - /** An enum containing [BillingFrequency]'s known values. */ + /** An enum containing [Discounted]'s known values. */ enum class Known { - MONTHLY, - QUARTERLY, - ANNUAL, - WEEKLY, + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, } /** - * An enum containing [BillingFrequency]'s known values, as well as an [_UNKNOWN] - * member. + * An enum containing [Discounted]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [BillingFrequency] can contain an unknown value in a couple of - * cases: + * An instance of [Discounted] 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 { - MONTHLY, - QUARTERLY, - ANNUAL, - WEEKLY, + ANY, + DISCOUNTED_ONLY, + UNDISCOUNTED_ONLY, /** - * An enum member indicating that [BillingFrequency] was instantiated with an - * unknown value. + * An enum member indicating that [Discounted] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -27947,10 +27846,9 @@ private constructor( */ fun value(): Value = when (this) { - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ANNUAL -> Value.ANNUAL - WEEKLY -> Value.WEEKLY + ANY -> Value.ANY + DISCOUNTED_ONLY -> Value.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Value.UNDISCOUNTED_ONLY else -> Value._UNKNOWN } @@ -27965,12 +27863,10 @@ private constructor( */ fun known(): Known = when (this) { - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ANNUAL -> Known.ANNUAL - WEEKLY -> Known.WEEKLY - else -> - throw MetronomeInvalidDataException("Unknown BillingFrequency: $value") + ANY -> Known.ANY + DISCOUNTED_ONLY -> Known.DISCOUNTED_ONLY + UNDISCOUNTED_ONLY -> Known.UNDISCOUNTED_ONLY + else -> throw MetronomeInvalidDataException("Unknown Discounted: $value") } /** @@ -27999,7 +27895,7 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't * match its expected type. */ - fun validate(): BillingFrequency = apply { + fun validate(): Discounted = apply { if (validated) { return@apply } @@ -28029,7 +27925,7 @@ private constructor( return true } - return other is BillingFrequency && value == other.value + return other is Discounted && value == other.value } override fun hashCode() = value.hashCode() @@ -28042,146 +27938,24 @@ private constructor( return true } - return other is SubscriptionRate && - billingFrequency == other.billingFrequency && - productId == other.productId && + return other is ApplicableSpendSpecifier && + sources == other.sources && + spendType == other.spendType && + discounted == other.discounted && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(billingFrequency, productId, additionalProperties) + Objects.hash(sources, spendType, discounted, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "SubscriptionRate{billingFrequency=$billingFrequency, productId=$productId, additionalProperties=$additionalProperties}" - } - - /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ - class CustomFields - @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 [CustomFields]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CustomFields]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(customFields: CustomFields) = apply { - additionalProperties = customFields.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 [CustomFields]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): CustomFields = CustomFields(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): CustomFields = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - 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 CustomFields && additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = "CustomFields{additionalProperties=$additionalProperties}" + "ApplicableSpendSpecifier{sources=$sources, spendType=$spendType, discounted=$discounted, additionalProperties=$additionalProperties}" } - /** - * Determines how the subscription's quantity is controlled. Defaults to QUANTITY_ONLY. - * **QUANTITY_ONLY**: The subscription quantity is specified directly on the subscription. - * `initial_quantity` must be provided with this option. Compatible with recurring - * commits/credits that use POOLED allocation. **SEAT_BASED**: Use when you want to pass - * specific seat identifiers (e.g. add user_123) to increment and decrement a subscription - * quantity, rather than directly providing the quantity. You must use a **SEAT_BASED** - * subscription to use a linked recurring credit with an allocation per seat. `seat_config` - * must be provided with this option. - */ - class QuantityManagementMode + class ResetFrequency @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -28197,36 +27971,30 @@ private constructor( companion object { - @JvmField val SEAT_BASED = of("SEAT_BASED") - - @JvmField val QUANTITY_ONLY = of("QUANTITY_ONLY") + @JvmField val BILLING_PERIOD = of("BILLING_PERIOD") - @JvmStatic fun of(value: String) = QuantityManagementMode(JsonField.of(value)) + @JvmStatic fun of(value: String) = ResetFrequency(JsonField.of(value)) } - /** An enum containing [QuantityManagementMode]'s known values. */ + /** An enum containing [ResetFrequency]'s known values. */ enum class Known { - SEAT_BASED, - QUANTITY_ONLY, + BILLING_PERIOD } /** - * An enum containing [QuantityManagementMode]'s known values, as well as an [_UNKNOWN] - * member. + * An enum containing [ResetFrequency]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [QuantityManagementMode] can contain an unknown value in a couple of - * cases: + * An instance of [ResetFrequency] 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 { - SEAT_BASED, - QUANTITY_ONLY, + BILLING_PERIOD, /** - * An enum member indicating that [QuantityManagementMode] was instantiated with an - * unknown value. + * An enum member indicating that [ResetFrequency] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -28240,8 +28008,7 @@ private constructor( */ fun value(): Value = when (this) { - SEAT_BASED -> Value.SEAT_BASED - QUANTITY_ONLY -> Value.QUANTITY_ONLY + BILLING_PERIOD -> Value.BILLING_PERIOD else -> Value._UNKNOWN } @@ -28256,12 +28023,8 @@ private constructor( */ fun known(): Known = when (this) { - SEAT_BASED -> Known.SEAT_BASED - QUANTITY_ONLY -> Known.QUANTITY_ONLY - else -> - throw MetronomeInvalidDataException( - "Unknown QuantityManagementMode: $value" - ) + BILLING_PERIOD -> Known.BILLING_PERIOD + else -> throw MetronomeInvalidDataException("Unknown ResetFrequency: $value") } /** @@ -28290,7 +28053,7 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't match * its expected type. */ - fun validate(): QuantityManagementMode = apply { + fun validate(): ResetFrequency = apply { if (validated) { return@apply } @@ -28320,7 +28083,7 @@ private constructor( return true } - return other is QuantityManagementMode && value == other.value + return other is ResetFrequency && value == other.value } override fun hashCode() = value.hashCode() @@ -28328,376 +28091,313 @@ private constructor( override fun toString() = value.toString() } - class SeatConfig - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val initialSeatIds: JsonField>, - private val seatGroupKey: JsonField, - private val initialUnassignedSeats: JsonField, - private val additionalProperties: MutableMap, - ) { + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - @JsonCreator - private constructor( - @JsonProperty("initial_seat_ids") - @ExcludeMissing - initialSeatIds: JsonField> = JsonMissing.of(), - @JsonProperty("seat_group_key") - @ExcludeMissing - seatGroupKey: JsonField = JsonMissing.of(), - @JsonProperty("initial_unassigned_seats") - @ExcludeMissing - initialUnassignedSeats: JsonField = JsonMissing.of(), - ) : this(initialSeatIds, seatGroupKey, initialUnassignedSeats, mutableMapOf()) + return other is AddSpendTracker && + alias == other.alias && + applicableSpendSpecifiers == other.applicableSpendSpecifiers && + creditTypeId == other.creditTypeId && + resetFrequency == other.resetFrequency && + additionalProperties == other.additionalProperties + } - /** - * The initial assigned seats on this subscription. - * - * @throws MetronomeInvalidDataException 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 initialSeatIds(): List = initialSeatIds.getRequired("initial_seat_ids") + private val hashCode: Int by lazy { + Objects.hash( + alias, + applicableSpendSpecifiers, + creditTypeId, + resetFrequency, + additionalProperties, + ) + } - /** - * The property name, sent on usage events, that identifies the seat ID associated with - * the usage event. For example, the property name might be seat_id or user_id. The - * property must be set as a group key on billable metrics and a presentation/pricing - * group key on contract products. This allows linked recurring credits with an - * allocation per seat to be consumed by only one seat's usage. - * - * @throws MetronomeInvalidDataException 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 seatGroupKey(): String = seatGroupKey.getRequired("seat_group_key") + override fun hashCode(): Int = hashCode - /** - * The initial amount of unassigned seats on this subscription. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun initialUnassignedSeats(): Optional = - initialUnassignedSeats.getOptional("initial_unassigned_seats") + override fun toString() = + "AddSpendTracker{alias=$alias, applicableSpendSpecifiers=$applicableSpendSpecifiers, creditTypeId=$creditTypeId, resetFrequency=$resetFrequency, additionalProperties=$additionalProperties}" + } - /** - * Returns the raw JSON value of [initialSeatIds]. - * - * Unlike [initialSeatIds], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("initial_seat_ids") - @ExcludeMissing - fun _initialSeatIds(): JsonField> = initialSeatIds + class AddSubscription + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val collectionSchedule: JsonField, + private val proration: JsonField, + private val subscriptionRate: JsonField, + private val customFields: JsonField, + private val description: JsonField, + private val endingBefore: JsonField, + private val initialQuantity: JsonField, + private val name: JsonField, + private val quantityManagementMode: JsonField, + private val seatConfig: JsonField, + private val startingAt: JsonField, + private val temporaryId: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * Returns the raw JSON value of [seatGroupKey]. - * - * Unlike [seatGroupKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("seat_group_key") + @JsonCreator + private constructor( + @JsonProperty("collection_schedule") @ExcludeMissing - fun _seatGroupKey(): JsonField = seatGroupKey - - /** - * Returns the raw JSON value of [initialUnassignedSeats]. - * - * Unlike [initialUnassignedSeats], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("initial_unassigned_seats") + collectionSchedule: JsonField = JsonMissing.of(), + @JsonProperty("proration") @ExcludeMissing - fun _initialUnassignedSeats(): JsonField = initialUnassignedSeats - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter + proration: JsonField = JsonMissing.of(), + @JsonProperty("subscription_rate") @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + subscriptionRate: JsonField = JsonMissing.of(), + @JsonProperty("custom_fields") + @ExcludeMissing + customFields: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("initial_quantity") + @ExcludeMissing + initialQuantity: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("quantity_management_mode") + @ExcludeMissing + quantityManagementMode: JsonField = JsonMissing.of(), + @JsonProperty("seat_config") + @ExcludeMissing + seatConfig: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("temporary_id") + @ExcludeMissing + temporaryId: JsonField = JsonMissing.of(), + ) : this( + collectionSchedule, + proration, + subscriptionRate, + customFields, + description, + endingBefore, + initialQuantity, + name, + quantityManagementMode, + seatConfig, + startingAt, + temporaryId, + mutableMapOf(), + ) - fun toBuilder() = Builder().from(this) + /** + * @throws MetronomeInvalidDataException 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 collectionSchedule(): CollectionSchedule = + collectionSchedule.getRequired("collection_schedule") - companion object { + /** + * @throws MetronomeInvalidDataException 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 proration(): Proration = proration.getRequired("proration") - /** - * Returns a mutable builder for constructing an instance of [SeatConfig]. - * - * The following fields are required: - * ```java - * .initialSeatIds() - * .seatGroupKey() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + /** + * @throws MetronomeInvalidDataException 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 subscriptionRate(): SubscriptionRate = subscriptionRate.getRequired("subscription_rate") - /** A builder for [SeatConfig]. */ - class Builder internal constructor() { + /** + * Custom fields to be added eg. { "key1": "value1", "key2": "value2" } + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun customFields(): Optional = customFields.getOptional("custom_fields") - private var initialSeatIds: JsonField>? = null - private var seatGroupKey: JsonField? = null - private var initialUnassignedSeats: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") - @JvmSynthetic - internal fun from(seatConfig: SeatConfig) = apply { - initialSeatIds = seatConfig.initialSeatIds.map { it.toMutableList() } - seatGroupKey = seatConfig.seatGroupKey - initialUnassignedSeats = seatConfig.initialUnassignedSeats - additionalProperties = seatConfig.additionalProperties.toMutableMap() - } + /** + * Exclusive end time for the subscription. If not provided, subscription inherits contract + * end date. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun endingBefore(): Optional = endingBefore.getOptional("ending_before") - /** The initial assigned seats on this subscription. */ - fun initialSeatIds(initialSeatIds: List) = - initialSeatIds(JsonField.of(initialSeatIds)) + /** + * The initial quantity for the subscription. It must be non-negative value. Required if + * quantity_management_mode is QUANTITY_ONLY. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun initialQuantity(): Optional = initialQuantity.getOptional("initial_quantity") - /** - * Sets [Builder.initialSeatIds] to an arbitrary JSON value. - * - * You should usually call [Builder.initialSeatIds] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun initialSeatIds(initialSeatIds: JsonField>) = apply { - this.initialSeatIds = initialSeatIds.map { it.toMutableList() } - } - - /** - * Adds a single [String] to [initialSeatIds]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addInitialSeatId(initialSeatId: String) = apply { - initialSeatIds = - (initialSeatIds ?: JsonField.of(mutableListOf())).also { - checkKnown("initialSeatIds", it).add(initialSeatId) - } - } - - /** - * The property name, sent on usage events, that identifies the seat ID associated - * with the usage event. For example, the property name might be seat_id or user_id. - * The property must be set as a group key on billable metrics and a - * presentation/pricing group key on contract products. This allows linked recurring - * credits with an allocation per seat to be consumed by only one seat's usage. - */ - fun seatGroupKey(seatGroupKey: String) = seatGroupKey(JsonField.of(seatGroupKey)) - - /** - * Sets [Builder.seatGroupKey] to an arbitrary JSON value. - * - * You should usually call [Builder.seatGroupKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun seatGroupKey(seatGroupKey: JsonField) = apply { - this.seatGroupKey = seatGroupKey - } - - /** The initial amount of unassigned seats on this subscription. */ - fun initialUnassignedSeats(initialUnassignedSeats: Double) = - initialUnassignedSeats(JsonField.of(initialUnassignedSeats)) - - /** - * Sets [Builder.initialUnassignedSeats] to an arbitrary JSON value. - * - * You should usually call [Builder.initialUnassignedSeats] with a well-typed - * [Double] value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun initialUnassignedSeats(initialUnassignedSeats: JsonField) = apply { - this.initialUnassignedSeats = initialUnassignedSeats - } - - 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 [SeatConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .initialSeatIds() - * .seatGroupKey() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): SeatConfig = - SeatConfig( - checkRequired("initialSeatIds", initialSeatIds).map { it.toImmutable() }, - checkRequired("seatGroupKey", seatGroupKey), - initialUnassignedSeats, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): SeatConfig = apply { - if (validated) { - return@apply - } - - initialSeatIds() - seatGroupKey() - initialUnassignedSeats() - validated = true - } + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + /** + * Determines how the subscription's quantity is controlled. Defaults to QUANTITY_ONLY. + * **QUANTITY_ONLY**: The subscription quantity is specified directly on the subscription. + * `initial_quantity` must be provided with this option. Compatible with recurring + * commits/credits that use POOLED allocation. **SEAT_BASED**: Use when you want to pass + * specific seat identifiers (e.g. add user_123) to increment and decrement a subscription + * quantity, rather than directly providing the quantity. You must use a **SEAT_BASED** + * subscription to use a linked recurring credit with an allocation per seat. `seat_config` + * must be provided with this option. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun quantityManagementMode(): Optional = + quantityManagementMode.getOptional("quantity_management_mode") - /** - * 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 = - (initialSeatIds.asKnown().getOrNull()?.size ?: 0) + - (if (seatGroupKey.asKnown().isPresent) 1 else 0) + - (if (initialUnassignedSeats.asKnown().isPresent) 1 else 0) + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun seatConfig(): Optional = seatConfig.getOptional("seat_config") - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Inclusive start time for the subscription. If not provided, defaults to contract start + * date + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun startingAt(): Optional = startingAt.getOptional("starting_at") - return other is SeatConfig && - initialSeatIds == other.initialSeatIds && - seatGroupKey == other.seatGroupKey && - initialUnassignedSeats == other.initialUnassignedSeats && - additionalProperties == other.additionalProperties - } + /** + * A temporary ID used to reference the subscription in recurring commit/credit subscription + * configs created within the same payload. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun temporaryId(): Optional = temporaryId.getOptional("temporary_id") - private val hashCode: Int by lazy { - Objects.hash( - initialSeatIds, - seatGroupKey, - initialUnassignedSeats, - additionalProperties, - ) - } + /** + * Returns the raw JSON value of [collectionSchedule]. + * + * Unlike [collectionSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("collection_schedule") + @ExcludeMissing + fun _collectionSchedule(): JsonField = collectionSchedule - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [proration]. + * + * Unlike [proration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("proration") + @ExcludeMissing + fun _proration(): JsonField = proration - override fun toString() = - "SeatConfig{initialSeatIds=$initialSeatIds, seatGroupKey=$seatGroupKey, initialUnassignedSeats=$initialUnassignedSeats, additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [subscriptionRate]. + * + * Unlike [subscriptionRate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subscription_rate") + @ExcludeMissing + fun _subscriptionRate(): JsonField = subscriptionRate - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [customFields]. + * + * Unlike [customFields], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("custom_fields") + @ExcludeMissing + fun _customFields(): JsonField = customFields - return other is AddSubscription && - collectionSchedule == other.collectionSchedule && - proration == other.proration && - subscriptionRate == other.subscriptionRate && - customFields == other.customFields && - description == other.description && - endingBefore == other.endingBefore && - initialQuantity == other.initialQuantity && - name == other.name && - quantityManagementMode == other.quantityManagementMode && - seatConfig == other.seatConfig && - startingAt == other.startingAt && - temporaryId == other.temporaryId && - additionalProperties == other.additionalProperties - } + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - private val hashCode: Int by lazy { - Objects.hash( - collectionSchedule, - proration, - subscriptionRate, - customFields, - description, - endingBefore, - initialQuantity, - name, - quantityManagementMode, - seatConfig, - startingAt, - temporaryId, - additionalProperties, - ) - } + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [initialQuantity]. + * + * Unlike [initialQuantity], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("initial_quantity") + @ExcludeMissing + fun _initialQuantity(): JsonField = initialQuantity - override fun toString() = - "AddSubscription{collectionSchedule=$collectionSchedule, proration=$proration, subscriptionRate=$subscriptionRate, customFields=$customFields, description=$description, endingBefore=$endingBefore, initialQuantity=$initialQuantity, name=$name, quantityManagementMode=$quantityManagementMode, seatConfig=$seatConfig, startingAt=$startingAt, temporaryId=$temporaryId, additionalProperties=$additionalProperties}" - } + /** + * 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 - class ArchiveCommit - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val id: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * Returns the raw JSON value of [quantityManagementMode]. + * + * Unlike [quantityManagementMode], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity_management_mode") + @ExcludeMissing + fun _quantityManagementMode(): JsonField = quantityManagementMode - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() - ) : this(id, mutableMapOf()) + /** + * Returns the raw JSON value of [seatConfig]. + * + * Unlike [seatConfig], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("seat_config") + @ExcludeMissing + fun _seatConfig(): JsonField = seatConfig /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an unexpected type. */ - fun id(): String = id.getRequired("id") + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt /** - * Returns the raw JSON value of [id]. + * Returns the raw JSON value of [temporaryId]. * - * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [temporaryId], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + @JsonProperty("temporary_id") + @ExcludeMissing + fun _temporaryId(): JsonField = temporaryId @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -28714,200 +28414,236 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [ArchiveCommit]. + * Returns a mutable builder for constructing an instance of [AddSubscription]. * * The following fields are required: * ```java - * .id() + * .collectionSchedule() + * .proration() + * .subscriptionRate() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [ArchiveCommit]. */ + /** A builder for [AddSubscription]. */ class Builder internal constructor() { - private var id: JsonField? = null + private var collectionSchedule: JsonField? = null + private var proration: JsonField? = null + private var subscriptionRate: JsonField? = null + private var customFields: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var initialQuantity: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var quantityManagementMode: JsonField = JsonMissing.of() + private var seatConfig: JsonField = JsonMissing.of() + private var startingAt: JsonField = JsonMissing.of() + private var temporaryId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(archiveCommit: ArchiveCommit) = apply { - id = archiveCommit.id - additionalProperties = archiveCommit.additionalProperties.toMutableMap() + internal fun from(addSubscription: AddSubscription) = apply { + collectionSchedule = addSubscription.collectionSchedule + proration = addSubscription.proration + subscriptionRate = addSubscription.subscriptionRate + customFields = addSubscription.customFields + description = addSubscription.description + endingBefore = addSubscription.endingBefore + initialQuantity = addSubscription.initialQuantity + name = addSubscription.name + quantityManagementMode = addSubscription.quantityManagementMode + seatConfig = addSubscription.seatConfig + startingAt = addSubscription.startingAt + temporaryId = addSubscription.temporaryId + additionalProperties = addSubscription.additionalProperties.toMutableMap() } - fun id(id: String) = id(JsonField.of(id)) + fun collectionSchedule(collectionSchedule: CollectionSchedule) = + collectionSchedule(JsonField.of(collectionSchedule)) /** - * Sets [Builder.id] to an arbitrary JSON value. + * Sets [Builder.collectionSchedule] 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. + * You should usually call [Builder.collectionSchedule] with a well-typed + * [CollectionSchedule] 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 collectionSchedule(collectionSchedule: JsonField) = apply { + this.collectionSchedule = collectionSchedule } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun proration(proration: Proration) = proration(JsonField.of(proration)) - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Sets [Builder.proration] to an arbitrary JSON value. + * + * You should usually call [Builder.proration] with a well-typed [Proration] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun proration(proration: JsonField) = apply { this.proration = proration } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun subscriptionRate(subscriptionRate: SubscriptionRate) = + subscriptionRate(JsonField.of(subscriptionRate)) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) + /** + * Sets [Builder.subscriptionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.subscriptionRate] with a well-typed + * [SubscriptionRate] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun subscriptionRate(subscriptionRate: JsonField) = apply { + this.subscriptionRate = subscriptionRate } + /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ + fun customFields(customFields: CustomFields) = customFields(JsonField.of(customFields)) + /** - * Returns an immutable instance of [ArchiveCommit]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .id() - * ``` + * Sets [Builder.customFields] to an arbitrary JSON value. * - * @throws IllegalStateException if any required field is unset. + * You should usually call [Builder.customFields] with a well-typed [CustomFields] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun build(): ArchiveCommit = - ArchiveCommit(checkRequired("id", id), additionalProperties.toMutableMap()) - } + fun customFields(customFields: JsonField) = apply { + this.customFields = customFields + } - private var validated: Boolean = false + fun description(description: String) = description(JsonField.of(description)) - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): ArchiveCommit = apply { - if (validated) { - return@apply + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description } - id() - validated = true - } + /** + * Exclusive end time for the subscription. If not provided, subscription inherits + * contract end date. + */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore } - /** - * 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) + /** + * The initial quantity for the subscription. It must be non-negative value. Required if + * quantity_management_mode is QUANTITY_ONLY. + */ + fun initialQuantity(initialQuantity: Double) = + initialQuantity(JsonField.of(initialQuantity)) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * Sets [Builder.initialQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.initialQuantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun initialQuantity(initialQuantity: JsonField) = apply { + this.initialQuantity = initialQuantity } - return other is ArchiveCommit && - id == other.id && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ArchiveCommit{id=$id, additionalProperties=$additionalProperties}" - } - - class ArchiveCredit - @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 MetronomeInvalidDataException 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 + fun name(name: String) = name(JsonField.of(name)) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * 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 } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Determines how the subscription's quantity is controlled. Defaults to QUANTITY_ONLY. + * **QUANTITY_ONLY**: The subscription quantity is specified directly on the + * subscription. `initial_quantity` must be provided with this option. Compatible with + * recurring commits/credits that use POOLED allocation. **SEAT_BASED**: Use when you + * want to pass specific seat identifiers (e.g. add user_123) to increment and decrement + * a subscription quantity, rather than directly providing the quantity. You must use a + * **SEAT_BASED** subscription to use a linked recurring credit with an allocation per + * seat. `seat_config` must be provided with this option. + */ + fun quantityManagementMode(quantityManagementMode: QuantityManagementMode) = + quantityManagementMode(JsonField.of(quantityManagementMode)) - fun toBuilder() = Builder().from(this) + /** + * Sets [Builder.quantityManagementMode] to an arbitrary JSON value. + * + * You should usually call [Builder.quantityManagementMode] with a well-typed + * [QuantityManagementMode] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun quantityManagementMode(quantityManagementMode: JsonField) = + apply { + this.quantityManagementMode = quantityManagementMode + } - companion object { + fun seatConfig(seatConfig: SeatConfig) = seatConfig(JsonField.of(seatConfig)) /** - * Returns a mutable builder for constructing an instance of [ArchiveCredit]. + * Sets [Builder.seatConfig] to an arbitrary JSON value. * - * The following fields are required: - * ```java - * .id() - * ``` + * You should usually call [Builder.seatConfig] with a well-typed [SeatConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ArchiveCredit]. */ - class Builder internal constructor() { + fun seatConfig(seatConfig: JsonField) = apply { + this.seatConfig = seatConfig + } - private var id: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Inclusive start time for the subscription. If not provided, defaults to contract + * start date + */ + fun startingAt(startingAt: OffsetDateTime) = startingAt(JsonField.of(startingAt)) - @JvmSynthetic - internal fun from(archiveCredit: ArchiveCredit) = apply { - id = archiveCredit.id - additionalProperties = archiveCredit.additionalProperties.toMutableMap() + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt } - fun id(id: String) = id(JsonField.of(id)) + /** + * A temporary ID used to reference the subscription in recurring commit/credit + * subscription configs created within the same payload. + */ + fun temporaryId(temporaryId: String) = temporaryId(JsonField.of(temporaryId)) /** - * Sets [Builder.id] to an arbitrary JSON value. + * Sets [Builder.temporaryId] 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. + * You should usually call [Builder.temporaryId] 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 temporaryId(temporaryId: JsonField) = apply { + this.temporaryId = temporaryId + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -28929,19 +28665,35 @@ private constructor( } /** - * Returns an immutable instance of [ArchiveCredit]. + * Returns an immutable instance of [AddSubscription]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java - * .id() + * .collectionSchedule() + * .proration() + * .subscriptionRate() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): ArchiveCredit = - ArchiveCredit(checkRequired("id", id), additionalProperties.toMutableMap()) + fun build(): AddSubscription = + AddSubscription( + checkRequired("collectionSchedule", collectionSchedule), + checkRequired("proration", proration), + checkRequired("subscriptionRate", subscriptionRate), + customFields, + description, + endingBefore, + initialQuantity, + name, + quantityManagementMode, + seatConfig, + startingAt, + temporaryId, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -28955,12 +28707,23 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't match its * expected type. */ - fun validate(): ArchiveCredit = apply { + fun validate(): AddSubscription = apply { if (validated) { return@apply } - id() + collectionSchedule().validate() + proration().validate() + subscriptionRate().validate() + customFields().ifPresent { it.validate() } + description() + endingBefore() + initialQuantity() + name() + quantityManagementMode().ifPresent { it.validate() } + seatConfig().ifPresent { it.validate() } + startingAt() + temporaryId() validated = true } @@ -28978,377 +28741,2219 @@ private constructor( * * 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 ArchiveCredit && - id == other.id && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + @JvmSynthetic + internal fun validity(): Int = + (collectionSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (proration.asKnown().getOrNull()?.validity() ?: 0) + + (subscriptionRate.asKnown().getOrNull()?.validity() ?: 0) + + (customFields.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (initialQuantity.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (quantityManagementMode.asKnown().getOrNull()?.validity() ?: 0) + + (seatConfig.asKnown().getOrNull()?.validity() ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (if (temporaryId.asKnown().isPresent) 1 else 0) - override fun hashCode(): Int = hashCode + class CollectionSchedule + @JsonCreator + private constructor(private val value: JsonField) : Enum { - override fun toString() = - "ArchiveCredit{id=$id, additionalProperties=$additionalProperties}" - } + /** + * 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 - class ArchiveScheduledCharge - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val id: JsonField, - private val additionalProperties: MutableMap, - ) { + companion object { - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() - ) : this(id, mutableMapOf()) + @JvmField val ADVANCE = of("ADVANCE") - /** - * @throws MetronomeInvalidDataException 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") + @JvmField val ARREARS = of("ARREARS") - /** - * 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 + @JvmStatic fun of(value: String) = CollectionSchedule(JsonField.of(value)) + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** An enum containing [CollectionSchedule]'s known values. */ + enum class Known { + ADVANCE, + ARREARS, + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * An enum containing [CollectionSchedule]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [CollectionSchedule] 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 { + ADVANCE, + ARREARS, + /** + * An enum member indicating that [CollectionSchedule] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } - fun toBuilder() = Builder().from(this) + /** + * 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) { + ADVANCE -> Value.ADVANCE + ARREARS -> Value.ARREARS + else -> Value._UNKNOWN + } - companion object { + /** + * 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ADVANCE -> Known.ADVANCE + ARREARS -> Known.ARREARS + else -> + throw MetronomeInvalidDataException("Unknown CollectionSchedule: $value") + } /** - * Returns a mutable builder for constructing an instance of [ArchiveScheduledCharge]. + * Returns this class instance's primitive wire representation. * - * The following fields are required: - * ```java - * .id() - * ``` + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. */ - @JvmStatic fun builder() = Builder() - } + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } - /** A builder for [ArchiveScheduledCharge]. */ - class Builder internal constructor() { + private var validated: Boolean = false - private var id: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): CollectionSchedule = apply { + if (validated) { + return@apply + } - @JvmSynthetic - internal fun from(archiveScheduledCharge: ArchiveScheduledCharge) = apply { - id = archiveScheduledCharge.id - additionalProperties = archiveScheduledCharge.additionalProperties.toMutableMap() + known() + validated = true } - fun id(id: String) = id(JsonField.of(id)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } /** - * Sets [Builder.id] to an arbitrary JSON value. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * 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. + * Used for best match union deserialization. */ - fun id(id: JsonField) = apply { this.id = id } + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) + return other is CollectionSchedule && value == other.value } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + override fun hashCode() = value.hashCode() - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + override fun toString() = value.toString() + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + class Proration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val invoiceBehavior: JsonField, + private val isProrated: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("invoice_behavior") + @ExcludeMissing + invoiceBehavior: JsonField = JsonMissing.of(), + @JsonProperty("is_prorated") + @ExcludeMissing + isProrated: JsonField = JsonMissing.of(), + ) : this(invoiceBehavior, isProrated, mutableMapOf()) /** - * Returns an immutable instance of [ArchiveScheduledCharge]. + * Indicates how mid-period quantity adjustments are invoiced. **BILL_IMMEDIATELY**: + * Only available when collection schedule is `ADVANCE`. The quantity increase will be + * billed immediately on the scheduled date. **BILL_ON_NEXT_COLLECTION_DATE**: The + * quantity increase will be billed for in-arrears at the end of the period. * - * Further updates to this [Builder] will not mutate the returned instance. + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun invoiceBehavior(): Optional = + invoiceBehavior.getOptional("invoice_behavior") + + /** + * Indicates if the partial period will be prorated or charged a full amount. * - * The following fields are required: - * ```java - * .id() - * ``` + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun isProrated(): Optional = isProrated.getOptional("is_prorated") + + /** + * Returns the raw JSON value of [invoiceBehavior]. * - * @throws IllegalStateException if any required field is unset. + * Unlike [invoiceBehavior], this method doesn't throw if the JSON field has an + * unexpected type. */ - fun build(): ArchiveScheduledCharge = - ArchiveScheduledCharge(checkRequired("id", id), additionalProperties.toMutableMap()) - } + @JsonProperty("invoice_behavior") + @ExcludeMissing + fun _invoiceBehavior(): JsonField = invoiceBehavior - private var validated: Boolean = false + /** + * Returns the raw JSON value of [isProrated]. + * + * Unlike [isProrated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("is_prorated") + @ExcludeMissing + fun _isProrated(): JsonField = isProrated - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): ArchiveScheduledCharge = apply { - if (validated) { - return@apply + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - id() - validated = true - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - /** - * 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) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** Returns a mutable builder for constructing an instance of [Proration]. */ + @JvmStatic fun builder() = Builder() } - return other is ArchiveScheduledCharge && - id == other.id && - additionalProperties == other.additionalProperties - } + /** A builder for [Proration]. */ + class Builder internal constructor() { - private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + private var invoiceBehavior: JsonField = JsonMissing.of() + private var isProrated: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode(): Int = hashCode + @JvmSynthetic + internal fun from(proration: Proration) = apply { + invoiceBehavior = proration.invoiceBehavior + isProrated = proration.isProrated + additionalProperties = proration.additionalProperties.toMutableMap() + } - override fun toString() = - "ArchiveScheduledCharge{id=$id, additionalProperties=$additionalProperties}" - } + /** + * Indicates how mid-period quantity adjustments are invoiced. **BILL_IMMEDIATELY**: + * Only available when collection schedule is `ADVANCE`. The quantity increase will + * be billed immediately on the scheduled date. **BILL_ON_NEXT_COLLECTION_DATE**: + * The quantity increase will be billed for in-arrears at the end of the period. + */ + fun invoiceBehavior(invoiceBehavior: InvoiceBehavior) = + invoiceBehavior(JsonField.of(invoiceBehavior)) - class RemoveOverride - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val id: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * Sets [Builder.invoiceBehavior] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceBehavior] with a well-typed + * [InvoiceBehavior] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun invoiceBehavior(invoiceBehavior: JsonField) = apply { + this.invoiceBehavior = invoiceBehavior + } - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() - ) : this(id, mutableMapOf()) + /** Indicates if the partial period will be prorated or charged a full amount. */ + fun isProrated(isProrated: Boolean) = isProrated(JsonField.of(isProrated)) - /** - * @throws MetronomeInvalidDataException 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") + /** + * Sets [Builder.isProrated] to an arbitrary JSON value. + * + * You should usually call [Builder.isProrated] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun isProrated(isProrated: JsonField) = apply { + this.isProrated = isProrated + } - /** - * Returns the raw JSON value of [id]. - * - * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - companion object { + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Proration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Proration = + Proration(invoiceBehavior, isProrated, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false /** - * Returns a mutable builder for constructing an instance of [RemoveOverride]. + * Validates that the types of all values in this object match their expected types + * recursively. * - * The following fields are required: - * ```java - * .id() - * ``` + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [RemoveOverride]. */ - class Builder internal constructor() { - - private var id: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + fun validate(): Proration = apply { + if (validated) { + return@apply + } - @JvmSynthetic - internal fun from(removeOverride: RemoveOverride) = apply { - id = removeOverride.id - additionalProperties = removeOverride.additionalProperties.toMutableMap() + invoiceBehavior().ifPresent { it.validate() } + isProrated() + validated = true } - fun id(id: String) = id(JsonField.of(id)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } /** - * Sets [Builder.id] to an arbitrary JSON value. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * 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. + * Used for best match union deserialization. */ - fun id(id: JsonField) = apply { this.id = id } + @JvmSynthetic + internal fun validity(): Int = + (invoiceBehavior.asKnown().getOrNull()?.validity() ?: 0) + + (if (isProrated.asKnown().isPresent) 1 else 0) - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) + /** + * Indicates how mid-period quantity adjustments are invoiced. **BILL_IMMEDIATELY**: + * Only available when collection schedule is `ADVANCE`. The quantity increase will be + * billed immediately on the scheduled date. **BILL_ON_NEXT_COLLECTION_DATE**: The + * quantity increase will be billed for in-arrears at the end of the period. + */ + class InvoiceBehavior + @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 BILL_IMMEDIATELY = of("BILL_IMMEDIATELY") + + @JvmField val BILL_ON_NEXT_COLLECTION_DATE = of("BILL_ON_NEXT_COLLECTION_DATE") + + @JvmStatic fun of(value: String) = InvoiceBehavior(JsonField.of(value)) + } + + /** An enum containing [InvoiceBehavior]'s known values. */ + enum class Known { + BILL_IMMEDIATELY, + BILL_ON_NEXT_COLLECTION_DATE, + } + + /** + * An enum containing [InvoiceBehavior]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [InvoiceBehavior] 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 { + BILL_IMMEDIATELY, + BILL_ON_NEXT_COLLECTION_DATE, + /** + * An enum member indicating that [InvoiceBehavior] 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) { + BILL_IMMEDIATELY -> Value.BILL_IMMEDIATELY + BILL_ON_NEXT_COLLECTION_DATE -> Value.BILL_ON_NEXT_COLLECTION_DATE + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + BILL_IMMEDIATELY -> Known.BILL_IMMEDIATELY + BILL_ON_NEXT_COLLECTION_DATE -> Known.BILL_ON_NEXT_COLLECTION_DATE + else -> + throw MetronomeInvalidDataException("Unknown InvoiceBehavior: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): InvoiceBehavior = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 InvoiceBehavior && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Proration && + invoiceBehavior == other.invoiceBehavior && + isProrated == other.isProrated && + additionalProperties == other.additionalProperties } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) + private val hashCode: Int by lazy { + Objects.hash(invoiceBehavior, isProrated, additionalProperties) } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + override fun hashCode(): Int = hashCode - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + override fun toString() = + "Proration{invoiceBehavior=$invoiceBehavior, isProrated=$isProrated, additionalProperties=$additionalProperties}" + } + + class SubscriptionRate + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val billingFrequency: JsonField, + private val productId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("billing_frequency") + @ExcludeMissing + billingFrequency: JsonField = JsonMissing.of(), + @JsonProperty("product_id") + @ExcludeMissing + productId: JsonField = JsonMissing.of(), + ) : this(billingFrequency, productId, mutableMapOf()) /** - * Returns an immutable instance of [RemoveOverride]. + * Frequency to bill subscription with. Together with product_id, must match existing + * rate on the rate card. * - * Further updates to this [Builder] will not mutate the returned instance. + * @throws MetronomeInvalidDataException 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 billingFrequency(): BillingFrequency = + billingFrequency.getRequired("billing_frequency") + + /** + * Must be subscription type product * - * The following fields are required: - * ```java - * .id() - * ``` + * @throws MetronomeInvalidDataException 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 productId(): String = productId.getRequired("product_id") + + /** + * Returns the raw JSON value of [billingFrequency]. * - * @throws IllegalStateException if any required field is unset. + * Unlike [billingFrequency], this method doesn't throw if the JSON field has an + * unexpected type. */ - fun build(): RemoveOverride = - RemoveOverride(checkRequired("id", id), additionalProperties.toMutableMap()) - } + @JsonProperty("billing_frequency") + @ExcludeMissing + fun _billingFrequency(): JsonField = billingFrequency - private var validated: Boolean = false + /** + * Returns the raw JSON value of [productId]. + * + * Unlike [productId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product_id") + @ExcludeMissing + fun _productId(): JsonField = productId - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): RemoveOverride = apply { - if (validated) { - return@apply + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - id() - validated = true - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - /** - * 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) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * Returns a mutable builder for constructing an instance of [SubscriptionRate]. + * + * The following fields are required: + * ```java + * .billingFrequency() + * .productId() + * ``` + */ + @JvmStatic fun builder() = Builder() } - return other is RemoveOverride && - id == other.id && - additionalProperties == other.additionalProperties - } + /** A builder for [SubscriptionRate]. */ + class Builder internal constructor() { - private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + private var billingFrequency: JsonField? = null + private var productId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode(): Int = hashCode + @JvmSynthetic + internal fun from(subscriptionRate: SubscriptionRate) = apply { + billingFrequency = subscriptionRate.billingFrequency + productId = subscriptionRate.productId + additionalProperties = subscriptionRate.additionalProperties.toMutableMap() + } - override fun toString() = - "RemoveOverride{id=$id, additionalProperties=$additionalProperties}" - } + /** + * Frequency to bill subscription with. Together with product_id, must match + * existing rate on the rate card. + */ + fun billingFrequency(billingFrequency: BillingFrequency) = + billingFrequency(JsonField.of(billingFrequency)) - class UpdateCommit - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val commitId: JsonField, - private val accessSchedule: JsonField, - private val applicableProductIds: JsonField>, - private val applicableProductTags: JsonField>, - private val description: JsonField, - private val hierarchyConfiguration: JsonField, - private val invoiceSchedule: JsonField, - private val name: JsonField, - private val netsuiteSalesOrderId: JsonField, - private val priority: JsonField, - private val productId: JsonField, - private val rateType: JsonField, - private val rolloverFraction: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * Sets [Builder.billingFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.billingFrequency] with a well-typed + * [BillingFrequency] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun billingFrequency(billingFrequency: JsonField) = apply { + this.billingFrequency = billingFrequency + } - @JsonCreator - private constructor( - @JsonProperty("commit_id") - @ExcludeMissing - commitId: JsonField = JsonMissing.of(), - @JsonProperty("access_schedule") - @ExcludeMissing - accessSchedule: JsonField = JsonMissing.of(), + /** Must be subscription type product */ + fun productId(productId: String) = productId(JsonField.of(productId)) + + /** + * Sets [Builder.productId] to an arbitrary JSON value. + * + * You should usually call [Builder.productId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun productId(productId: JsonField) = apply { this.productId = productId } + + 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 [SubscriptionRate]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .billingFrequency() + * .productId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SubscriptionRate = + SubscriptionRate( + checkRequired("billingFrequency", billingFrequency), + checkRequired("productId", productId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SubscriptionRate = apply { + if (validated) { + return@apply + } + + billingFrequency().validate() + productId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (billingFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (if (productId.asKnown().isPresent) 1 else 0) + + /** + * Frequency to bill subscription with. Together with product_id, must match existing + * rate on the rate card. + */ + class BillingFrequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = BillingFrequency(JsonField.of(value)) + } + + /** An enum containing [BillingFrequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [BillingFrequency]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [BillingFrequency] 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 { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [BillingFrequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> + throw MetronomeInvalidDataException("Unknown BillingFrequency: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): BillingFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 BillingFrequency && 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 SubscriptionRate && + billingFrequency == other.billingFrequency && + productId == other.productId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(billingFrequency, productId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SubscriptionRate{billingFrequency=$billingFrequency, productId=$productId, additionalProperties=$additionalProperties}" + } + + /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ + class CustomFields + @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 [CustomFields]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFields]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(customFields: CustomFields) = apply { + additionalProperties = customFields.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 [CustomFields]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CustomFields = CustomFields(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): CustomFields = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 CustomFields && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "CustomFields{additionalProperties=$additionalProperties}" + } + + /** + * Determines how the subscription's quantity is controlled. Defaults to QUANTITY_ONLY. + * **QUANTITY_ONLY**: The subscription quantity is specified directly on the subscription. + * `initial_quantity` must be provided with this option. Compatible with recurring + * commits/credits that use POOLED allocation. **SEAT_BASED**: Use when you want to pass + * specific seat identifiers (e.g. add user_123) to increment and decrement a subscription + * quantity, rather than directly providing the quantity. You must use a **SEAT_BASED** + * subscription to use a linked recurring credit with an allocation per seat. `seat_config` + * must be provided with this option. + */ + class QuantityManagementMode + @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 SEAT_BASED = of("SEAT_BASED") + + @JvmField val QUANTITY_ONLY = of("QUANTITY_ONLY") + + @JvmStatic fun of(value: String) = QuantityManagementMode(JsonField.of(value)) + } + + /** An enum containing [QuantityManagementMode]'s known values. */ + enum class Known { + SEAT_BASED, + QUANTITY_ONLY, + } + + /** + * An enum containing [QuantityManagementMode]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [QuantityManagementMode] 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 { + SEAT_BASED, + QUANTITY_ONLY, + /** + * An enum member indicating that [QuantityManagementMode] 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) { + SEAT_BASED -> Value.SEAT_BASED + QUANTITY_ONLY -> Value.QUANTITY_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SEAT_BASED -> Known.SEAT_BASED + QUANTITY_ONLY -> Known.QUANTITY_ONLY + else -> + throw MetronomeInvalidDataException( + "Unknown QuantityManagementMode: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): QuantityManagementMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 QuantityManagementMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class SeatConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val initialSeatIds: JsonField>, + private val seatGroupKey: JsonField, + private val initialUnassignedSeats: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("initial_seat_ids") + @ExcludeMissing + initialSeatIds: JsonField> = JsonMissing.of(), + @JsonProperty("seat_group_key") + @ExcludeMissing + seatGroupKey: JsonField = JsonMissing.of(), + @JsonProperty("initial_unassigned_seats") + @ExcludeMissing + initialUnassignedSeats: JsonField = JsonMissing.of(), + ) : this(initialSeatIds, seatGroupKey, initialUnassignedSeats, mutableMapOf()) + + /** + * The initial assigned seats on this subscription. + * + * @throws MetronomeInvalidDataException 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 initialSeatIds(): List = initialSeatIds.getRequired("initial_seat_ids") + + /** + * The property name, sent on usage events, that identifies the seat ID associated with + * the usage event. For example, the property name might be seat_id or user_id. The + * property must be set as a group key on billable metrics and a presentation/pricing + * group key on contract products. This allows linked recurring credits with an + * allocation per seat to be consumed by only one seat's usage. + * + * @throws MetronomeInvalidDataException 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 seatGroupKey(): String = seatGroupKey.getRequired("seat_group_key") + + /** + * The initial amount of unassigned seats on this subscription. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun initialUnassignedSeats(): Optional = + initialUnassignedSeats.getOptional("initial_unassigned_seats") + + /** + * Returns the raw JSON value of [initialSeatIds]. + * + * Unlike [initialSeatIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("initial_seat_ids") + @ExcludeMissing + fun _initialSeatIds(): JsonField> = initialSeatIds + + /** + * Returns the raw JSON value of [seatGroupKey]. + * + * Unlike [seatGroupKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("seat_group_key") + @ExcludeMissing + fun _seatGroupKey(): JsonField = seatGroupKey + + /** + * Returns the raw JSON value of [initialUnassignedSeats]. + * + * Unlike [initialUnassignedSeats], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("initial_unassigned_seats") + @ExcludeMissing + fun _initialUnassignedSeats(): JsonField = initialUnassignedSeats + + @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 [SeatConfig]. + * + * The following fields are required: + * ```java + * .initialSeatIds() + * .seatGroupKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SeatConfig]. */ + class Builder internal constructor() { + + private var initialSeatIds: JsonField>? = null + private var seatGroupKey: JsonField? = null + private var initialUnassignedSeats: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(seatConfig: SeatConfig) = apply { + initialSeatIds = seatConfig.initialSeatIds.map { it.toMutableList() } + seatGroupKey = seatConfig.seatGroupKey + initialUnassignedSeats = seatConfig.initialUnassignedSeats + additionalProperties = seatConfig.additionalProperties.toMutableMap() + } + + /** The initial assigned seats on this subscription. */ + fun initialSeatIds(initialSeatIds: List) = + initialSeatIds(JsonField.of(initialSeatIds)) + + /** + * Sets [Builder.initialSeatIds] to an arbitrary JSON value. + * + * You should usually call [Builder.initialSeatIds] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun initialSeatIds(initialSeatIds: JsonField>) = apply { + this.initialSeatIds = initialSeatIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [initialSeatIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInitialSeatId(initialSeatId: String) = apply { + initialSeatIds = + (initialSeatIds ?: JsonField.of(mutableListOf())).also { + checkKnown("initialSeatIds", it).add(initialSeatId) + } + } + + /** + * The property name, sent on usage events, that identifies the seat ID associated + * with the usage event. For example, the property name might be seat_id or user_id. + * The property must be set as a group key on billable metrics and a + * presentation/pricing group key on contract products. This allows linked recurring + * credits with an allocation per seat to be consumed by only one seat's usage. + */ + fun seatGroupKey(seatGroupKey: String) = seatGroupKey(JsonField.of(seatGroupKey)) + + /** + * Sets [Builder.seatGroupKey] to an arbitrary JSON value. + * + * You should usually call [Builder.seatGroupKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun seatGroupKey(seatGroupKey: JsonField) = apply { + this.seatGroupKey = seatGroupKey + } + + /** The initial amount of unassigned seats on this subscription. */ + fun initialUnassignedSeats(initialUnassignedSeats: Double) = + initialUnassignedSeats(JsonField.of(initialUnassignedSeats)) + + /** + * Sets [Builder.initialUnassignedSeats] to an arbitrary JSON value. + * + * You should usually call [Builder.initialUnassignedSeats] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun initialUnassignedSeats(initialUnassignedSeats: JsonField) = apply { + this.initialUnassignedSeats = initialUnassignedSeats + } + + 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 [SeatConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .initialSeatIds() + * .seatGroupKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SeatConfig = + SeatConfig( + checkRequired("initialSeatIds", initialSeatIds).map { it.toImmutable() }, + checkRequired("seatGroupKey", seatGroupKey), + initialUnassignedSeats, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SeatConfig = apply { + if (validated) { + return@apply + } + + initialSeatIds() + seatGroupKey() + initialUnassignedSeats() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (initialSeatIds.asKnown().getOrNull()?.size ?: 0) + + (if (seatGroupKey.asKnown().isPresent) 1 else 0) + + (if (initialUnassignedSeats.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SeatConfig && + initialSeatIds == other.initialSeatIds && + seatGroupKey == other.seatGroupKey && + initialUnassignedSeats == other.initialUnassignedSeats && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + initialSeatIds, + seatGroupKey, + initialUnassignedSeats, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SeatConfig{initialSeatIds=$initialSeatIds, seatGroupKey=$seatGroupKey, initialUnassignedSeats=$initialUnassignedSeats, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddSubscription && + collectionSchedule == other.collectionSchedule && + proration == other.proration && + subscriptionRate == other.subscriptionRate && + customFields == other.customFields && + description == other.description && + endingBefore == other.endingBefore && + initialQuantity == other.initialQuantity && + name == other.name && + quantityManagementMode == other.quantityManagementMode && + seatConfig == other.seatConfig && + startingAt == other.startingAt && + temporaryId == other.temporaryId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + collectionSchedule, + proration, + subscriptionRate, + customFields, + description, + endingBefore, + initialQuantity, + name, + quantityManagementMode, + seatConfig, + startingAt, + temporaryId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddSubscription{collectionSchedule=$collectionSchedule, proration=$proration, subscriptionRate=$subscriptionRate, customFields=$customFields, description=$description, endingBefore=$endingBefore, initialQuantity=$initialQuantity, name=$name, quantityManagementMode=$quantityManagementMode, seatConfig=$seatConfig, startingAt=$startingAt, temporaryId=$temporaryId, additionalProperties=$additionalProperties}" + } + + class ArchiveCommit + @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 MetronomeInvalidDataException 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 [ArchiveCommit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ArchiveCommit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(archiveCommit: ArchiveCommit) = apply { + id = archiveCommit.id + additionalProperties = archiveCommit.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 [ArchiveCommit]. + * + * 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(): ArchiveCommit = + ArchiveCommit(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ArchiveCommit = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ArchiveCommit && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ArchiveCommit{id=$id, additionalProperties=$additionalProperties}" + } + + class ArchiveCredit + @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 MetronomeInvalidDataException 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 [ArchiveCredit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ArchiveCredit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(archiveCredit: ArchiveCredit) = apply { + id = archiveCredit.id + additionalProperties = archiveCredit.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 [ArchiveCredit]. + * + * 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(): ArchiveCredit = + ArchiveCredit(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ArchiveCredit = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ArchiveCredit && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ArchiveCredit{id=$id, additionalProperties=$additionalProperties}" + } + + class ArchiveScheduledCharge + @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 MetronomeInvalidDataException 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 [ArchiveScheduledCharge]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ArchiveScheduledCharge]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(archiveScheduledCharge: ArchiveScheduledCharge) = apply { + id = archiveScheduledCharge.id + additionalProperties = archiveScheduledCharge.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 [ArchiveScheduledCharge]. + * + * 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(): ArchiveScheduledCharge = + ArchiveScheduledCharge(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ArchiveScheduledCharge = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ArchiveScheduledCharge && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ArchiveScheduledCharge{id=$id, additionalProperties=$additionalProperties}" + } + + class RemoveOverride + @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 MetronomeInvalidDataException 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 [RemoveOverride]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveOverride]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(removeOverride: RemoveOverride) = apply { + id = removeOverride.id + additionalProperties = removeOverride.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 [RemoveOverride]. + * + * 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(): RemoveOverride = + RemoveOverride(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RemoveOverride = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RemoveOverride && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveOverride{id=$id, additionalProperties=$additionalProperties}" + } + + class UpdateCommit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val commitId: JsonField, + private val accessSchedule: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val description: JsonField, + private val hierarchyConfiguration: JsonField, + private val invoiceSchedule: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val priority: JsonField, + private val productId: JsonField, + private val rateType: JsonField, + private val rolloverFraction: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("commit_id") + @ExcludeMissing + commitId: JsonField = JsonMissing.of(), + @JsonProperty("access_schedule") + @ExcludeMissing + accessSchedule: JsonField = JsonMissing.of(), @JsonProperty("applicable_product_ids") @ExcludeMissing applicableProductIds: JsonField> = JsonMissing.of(), @@ -31459,18 +33064,499 @@ private constructor( additionalProperties = addScheduleItem.additionalProperties.toMutableMap() } - fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) + fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { this.quantity = quantity } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [AddScheduleItem]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .timestamp() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddScheduleItem = + AddScheduleItem( + checkRequired("timestamp", timestamp), + amount, + quantity, + unitPrice, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddScheduleItem = apply { + if (validated) { + return@apply + } + + timestamp() + amount() + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (timestamp.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddScheduleItem && + timestamp == other.timestamp && + amount == other.amount && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(timestamp, amount, quantity, unitPrice, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddScheduleItem{timestamp=$timestamp, amount=$amount, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + class RemoveScheduleItem + @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 MetronomeInvalidDataException 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 + * [RemoveScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(removeScheduleItem: RemoveScheduleItem) = apply { + id = removeScheduleItem.id + additionalProperties = + removeScheduleItem.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 [RemoveScheduleItem]. + * + * 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(): RemoveScheduleItem = + RemoveScheduleItem( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): RemoveScheduleItem = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RemoveScheduleItem && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveScheduleItem{id=$id, additionalProperties=$additionalProperties}" + } + + class UpdateScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val amount: JsonField, + private val quantity: JsonField, + private val timestamp: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(id, amount, quantity, timestamp, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun timestamp(): Optional = timestamp.getOptional("timestamp") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [UpdateScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var timestamp: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateScheduleItem: UpdateScheduleItem) = apply { + id = updateScheduleItem.id + amount = updateScheduleItem.amount + quantity = updateScheduleItem.quantity + timestamp = updateScheduleItem.timestamp + unitPrice = updateScheduleItem.unitPrice + additionalProperties = + updateScheduleItem.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) /** - * Sets [Builder.timestamp] to an arbitrary JSON value. + * Sets [Builder.id] to an arbitrary JSON value. * - * You should usually call [Builder.timestamp] with a well-typed - * [OffsetDateTime] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported 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 timestamp(timestamp: JsonField) = apply { - this.timestamp = timestamp - } + fun id(id: JsonField) = apply { this.id = id } fun amount(amount: Double) = amount(JsonField.of(amount)) @@ -31494,6 +33580,19 @@ private constructor( */ fun quantity(quantity: JsonField) = apply { this.quantity = quantity } + fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) /** @@ -31530,22 +33629,23 @@ private constructor( } /** - * Returns an immutable instance of [AddScheduleItem]. + * Returns an immutable instance of [UpdateScheduleItem]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java - * .timestamp() + * .id() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): AddScheduleItem = - AddScheduleItem( - checkRequired("timestamp", timestamp), + fun build(): UpdateScheduleItem = + UpdateScheduleItem( + checkRequired("id", id), amount, quantity, + timestamp, unitPrice, additionalProperties.toMutableMap(), ) @@ -31563,14 +33663,15 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't * match its expected type. */ - fun validate(): AddScheduleItem = apply { + fun validate(): UpdateScheduleItem = apply { if (validated) { return@apply } - timestamp() + id() amount() quantity() + timestamp() unitPrice() validated = true } @@ -31591,9 +33692,10 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (timestamp.asKnown().isPresent) 1 else 0) + + (if (id.asKnown().isPresent) 1 else 0) + (if (amount.asKnown().isPresent) 1 else 0) + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (timestamp.asKnown().isPresent) 1 else 0) + (if (unitPrice.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { @@ -31601,644 +33703,1139 @@ private constructor( return true } - return other is AddScheduleItem && - timestamp == other.timestamp && + return other is UpdateScheduleItem && + id == other.id && amount == other.amount && quantity == other.quantity && + timestamp == other.timestamp && unitPrice == other.unitPrice && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { - Objects.hash(timestamp, amount, quantity, unitPrice, additionalProperties) - } + private val hashCode: Int by lazy { + Objects.hash(id, amount, quantity, timestamp, unitPrice, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateScheduleItem{id=$id, amount=$amount, quantity=$quantity, timestamp=$timestamp, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InvoiceSchedule && + addScheduleItems == other.addScheduleItems && + removeScheduleItems == other.removeScheduleItems && + updateScheduleItems == other.updateScheduleItems && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InvoiceSchedule{addScheduleItems=$addScheduleItems, removeScheduleItems=$removeScheduleItems, updateScheduleItems=$updateScheduleItems, additionalProperties=$additionalProperties}" + } + + /** + * If provided, updates the commit to use the specified rate type for current and future + * invoices. Previously finalized invoices will need to be voided and regenerated to reflect + * the rate type change. + */ + class RateType @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 LIST_RATE = of("LIST_RATE") + + @JvmField val COMMIT_RATE = of("COMMIT_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + LIST_RATE, + COMMIT_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [RateType] 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 { + LIST_RATE, + COMMIT_RATE, + /** + * An enum member indicating that [RateType] 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) { + LIST_RATE -> Value.LIST_RATE + COMMIT_RATE -> Value.COMMIT_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + LIST_RATE -> Known.LIST_RATE + COMMIT_RATE -> Known.COMMIT_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && 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 UpdateCommit && + commitId == other.commitId && + accessSchedule == other.accessSchedule && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + description == other.description && + hierarchyConfiguration == other.hierarchyConfiguration && + invoiceSchedule == other.invoiceSchedule && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + priority == other.priority && + productId == other.productId && + rateType == other.rateType && + rolloverFraction == other.rolloverFraction && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + commitId, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + invoiceSchedule, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateCommit{commitId=$commitId, accessSchedule=$accessSchedule, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, productId=$productId, rateType=$rateType, rolloverFraction=$rolloverFraction, additionalProperties=$additionalProperties}" + } + + class UpdateCredit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditId: JsonField, + private val accessSchedule: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val description: JsonField, + private val hierarchyConfiguration: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val priority: JsonField, + private val productId: JsonField, + private val rateType: JsonField, + private val rolloverFraction: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_id") + @ExcludeMissing + creditId: JsonField = JsonMissing.of(), + @JsonProperty("access_schedule") + @ExcludeMissing + accessSchedule: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product_id") + @ExcludeMissing + productId: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + ) : this( + creditId, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException 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 creditId(): String = creditId.getRequired("credit_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun accessSchedule(): Optional = + accessSchedule.getOptional("access_schedule") + + /** + * Which products the credit applies to. If applicable_product_ids, applicable_product_tags + * or specifiers are not provided, the credit applies to all products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * Which tags the credit applies to. If applicable_product_ids, applicable_product_tags or + * specifiers are not provided, the credit applies to all products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Optional configuration for commit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * @throws MetronomeInvalidDataException 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 MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun priority(): Optional = priority.getOptional("priority") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun productId(): Optional = productId.getOptional("product_id") + + /** + * If provided, updates the credit to use the specified rate type for current and future + * invoices. Previously finalized invoices will need to be voided and regenerated to reflect + * the rate type change. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rateType(): Optional = rateType.getOptional("rate_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = rolloverFraction.getOptional("rollover_fraction") + + /** + * Returns the raw JSON value of [creditId]. + * + * Unlike [creditId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credit_id") @ExcludeMissing fun _creditId(): JsonField = creditId + + /** + * Returns the raw JSON value of [accessSchedule]. + * + * Unlike [accessSchedule], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("access_schedule") + @ExcludeMissing + fun _accessSchedule(): JsonField = accessSchedule + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("priority") @ExcludeMissing fun _priority(): JsonField = priority - override fun toString() = - "AddScheduleItem{timestamp=$timestamp, amount=$amount, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [productId]. + * + * Unlike [productId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("product_id") @ExcludeMissing fun _productId(): JsonField = productId - class RemoveScheduleItem - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val id: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rate_type") @ExcludeMissing fun _rateType(): JsonField = rateType - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() - ) : this(id, mutableMapOf()) + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction - /** - * @throws MetronomeInvalidDataException 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") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * 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 + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + companion object { - fun toBuilder() = Builder().from(this) + /** + * Returns a mutable builder for constructing an instance of [UpdateCredit]. + * + * The following fields are required: + * ```java + * .creditId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - companion object { + /** A builder for [UpdateCredit]. */ + class Builder internal constructor() { - /** - * Returns a mutable builder for constructing an instance of - * [RemoveScheduleItem]. - * - * The following fields are required: - * ```java - * .id() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + private var creditId: JsonField? = null + private var accessSchedule: JsonField = JsonMissing.of() + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var description: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var priority: JsonField = JsonMissing.of() + private var productId: JsonField = JsonMissing.of() + private var rateType: JsonField = JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - /** A builder for [RemoveScheduleItem]. */ - class Builder internal constructor() { + @JvmSynthetic + internal fun from(updateCredit: UpdateCredit) = apply { + creditId = updateCredit.creditId + accessSchedule = updateCredit.accessSchedule + applicableProductIds = updateCredit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + updateCredit.applicableProductTags.map { it.toMutableList() } + description = updateCredit.description + hierarchyConfiguration = updateCredit.hierarchyConfiguration + name = updateCredit.name + netsuiteSalesOrderId = updateCredit.netsuiteSalesOrderId + priority = updateCredit.priority + productId = updateCredit.productId + rateType = updateCredit.rateType + rolloverFraction = updateCredit.rolloverFraction + additionalProperties = updateCredit.additionalProperties.toMutableMap() + } - private var id: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + fun creditId(creditId: String) = creditId(JsonField.of(creditId)) - @JvmSynthetic - internal fun from(removeScheduleItem: RemoveScheduleItem) = apply { - id = removeScheduleItem.id - additionalProperties = - removeScheduleItem.additionalProperties.toMutableMap() - } + /** + * Sets [Builder.creditId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun creditId(creditId: JsonField) = apply { this.creditId = creditId } - fun id(id: String) = id(JsonField.of(id)) + fun accessSchedule(accessSchedule: AccessSchedule) = + accessSchedule(JsonField.of(accessSchedule)) - /** - * 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 } + /** + * Sets [Builder.accessSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.accessSchedule] with a well-typed [AccessSchedule] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun accessSchedule(accessSchedule: JsonField) = apply { + this.accessSchedule = accessSchedule + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * Which products the credit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the credit applies to all + * products. + */ + fun applicableProductIds(applicableProductIds: List?) = + applicableProductIds(JsonField.ofNullable(applicableProductIds)) - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Alias for calling [Builder.applicableProductIds] with + * `applicableProductIds.orElse(null)`. + */ + fun applicableProductIds(applicableProductIds: Optional>) = + applicableProductIds(applicableProductIds.getOrNull()) - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = apply { + this.applicableProductIds = applicableProductIds.map { it.toMutableList() } + } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) } + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Which tags the credit applies to. If applicable_product_ids, applicable_product_tags + * or specifiers are not provided, the credit applies to all products. + */ + fun applicableProductTags(applicableProductTags: List?) = + applicableProductTags(JsonField.ofNullable(applicableProductTags)) - /** - * Returns an immutable instance of [RemoveScheduleItem]. - * - * 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(): RemoveScheduleItem = - RemoveScheduleItem( - checkRequired("id", id), - additionalProperties.toMutableMap(), - ) - } + /** + * Alias for calling [Builder.applicableProductTags] with + * `applicableProductTags.orElse(null)`. + */ + fun applicableProductTags(applicableProductTags: Optional>) = + applicableProductTags(applicableProductTags.getOrNull()) - private var validated: Boolean = false + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = apply { + this.applicableProductTags = applicableProductTags.map { it.toMutableList() } + } - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): RemoveScheduleItem = apply { - if (validated) { - return@apply + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) } + } - id() - validated = true - } + fun description(description: String) = description(JsonField.of(description)) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } - /** - * 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) + /** Optional configuration for commit hierarchy access control */ + fun hierarchyConfiguration(hierarchyConfiguration: CommitHierarchyConfiguration) = + hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } - return other is RemoveScheduleItem && - id == other.id && - additionalProperties == other.additionalProperties - } + fun name(name: String) = name(JsonField.of(name)) - private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + /** + * 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 } - override fun hashCode(): Int = hashCode + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String?) = + netsuiteSalesOrderId(JsonField.ofNullable(netsuiteSalesOrderId)) - override fun toString() = - "RemoveScheduleItem{id=$id, additionalProperties=$additionalProperties}" + /** + * Alias for calling [Builder.netsuiteSalesOrderId] with + * `netsuiteSalesOrderId.orElse(null)`. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: Optional) = + netsuiteSalesOrderId(netsuiteSalesOrderId.getOrNull()) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId } - class UpdateScheduleItem - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val id: JsonField, - private val amount: JsonField, - private val quantity: JsonField, - private val timestamp: JsonField, - private val unitPrice: JsonField, - private val additionalProperties: MutableMap, - ) { + fun priority(priority: Double?) = priority(JsonField.ofNullable(priority)) - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("amount") - @ExcludeMissing - amount: JsonField = JsonMissing.of(), - @JsonProperty("quantity") - @ExcludeMissing - quantity: JsonField = JsonMissing.of(), - @JsonProperty("timestamp") - @ExcludeMissing - timestamp: JsonField = JsonMissing.of(), - @JsonProperty("unit_price") - @ExcludeMissing - unitPrice: JsonField = JsonMissing.of(), - ) : this(id, amount, quantity, timestamp, unitPrice, mutableMapOf()) + /** + * Alias for [Builder.priority]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun priority(priority: Double) = priority(priority as Double?) - /** - * @throws MetronomeInvalidDataException 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") + /** Alias for calling [Builder.priority] with `priority.orElse(null)`. */ + fun priority(priority: Optional) = priority(priority.getOrNull()) - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun amount(): Optional = amount.getOptional("amount") + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun quantity(): Optional = quantity.getOptional("quantity") + fun productId(productId: String) = productId(JsonField.of(productId)) - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun timestamp(): Optional = timestamp.getOptional("timestamp") + /** + * Sets [Builder.productId] to an arbitrary JSON value. + * + * You should usually call [Builder.productId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun productId(productId: JsonField) = apply { this.productId = productId } - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + /** + * If provided, updates the credit to use the specified rate type for current and future + * invoices. Previously finalized invoices will need to be voided and regenerated to + * reflect the rate type change. + */ + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) - /** - * 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 + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } - /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun rolloverFraction(rolloverFraction: Double?) = + rolloverFraction(JsonField.ofNullable(rolloverFraction)) - /** - * Returns the raw JSON value of [quantity]. - * - * Unlike [quantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("quantity") - @ExcludeMissing - fun _quantity(): JsonField = quantity + /** + * Alias for [Builder.rolloverFraction]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(rolloverFraction as Double?) + + /** + * Alias for calling [Builder.rolloverFraction] with `rolloverFraction.orElse(null)`. + */ + fun rolloverFraction(rolloverFraction: Optional) = + rolloverFraction(rolloverFraction.getOrNull()) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } - /** - * Returns the raw JSON value of [timestamp]. - * - * Unlike [timestamp], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("timestamp") - @ExcludeMissing - fun _timestamp(): JsonField = timestamp + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Returns the raw JSON value of [unitPrice]. - * - * Unlike [unitPrice], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("unit_price") - @ExcludeMissing - fun _unitPrice(): JsonField = unitPrice + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun toBuilder() = Builder().from(this) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - companion object { + /** + * Returns an immutable instance of [UpdateCredit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .creditId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UpdateCredit = + UpdateCredit( + checkRequired("creditId", creditId), + accessSchedule, + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + additionalProperties.toMutableMap(), + ) + } - /** - * Returns a mutable builder for constructing an instance of - * [UpdateScheduleItem]. - * - * The following fields are required: - * ```java - * .id() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + private var validated: Boolean = false - /** A builder for [UpdateScheduleItem]. */ - class Builder internal constructor() { + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): UpdateCredit = apply { + if (validated) { + return@apply + } - private var id: JsonField? = null - private var amount: JsonField = JsonMissing.of() - private var quantity: JsonField = JsonMissing.of() - private var timestamp: JsonField = JsonMissing.of() - private var unitPrice: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + creditId() + accessSchedule().ifPresent { it.validate() } + applicableProductIds() + applicableProductTags() + description() + hierarchyConfiguration().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + priority() + productId() + rateType().ifPresent { it.validate() } + rolloverFraction() + validated = true + } - @JvmSynthetic - internal fun from(updateScheduleItem: UpdateScheduleItem) = apply { - id = updateScheduleItem.id - amount = updateScheduleItem.amount - quantity = updateScheduleItem.quantity - timestamp = updateScheduleItem.timestamp - unitPrice = updateScheduleItem.unitPrice - additionalProperties = - updateScheduleItem.additionalProperties.toMutableMap() - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } - fun id(id: String) = id(JsonField.of(id)) + /** + * 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 (creditId.asKnown().isPresent) 1 else 0) + + (accessSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (if (productId.asKnown().isPresent) 1 else 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) - /** - * 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 } + class AccessSchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val addScheduleItems: JsonField>, + private val removeScheduleItems: JsonField>, + private val updateScheduleItems: JsonField>, + private val additionalProperties: MutableMap, + ) { - fun amount(amount: Double) = amount(JsonField.of(amount)) + @JsonCreator + private constructor( + @JsonProperty("add_schedule_items") + @ExcludeMissing + addScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("remove_schedule_items") + @ExcludeMissing + removeScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("update_schedule_items") + @ExcludeMissing + updateScheduleItems: JsonField> = JsonMissing.of(), + ) : this(addScheduleItems, removeScheduleItems, updateScheduleItems, mutableMapOf()) - /** - * Sets [Builder.amount] to an arbitrary JSON value. - * - * You should usually call [Builder.amount] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun amount(amount: JsonField) = apply { this.amount = amount } + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addScheduleItems(): Optional> = + addScheduleItems.getOptional("add_schedule_items") - fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun removeScheduleItems(): Optional> = + removeScheduleItems.getOptional("remove_schedule_items") - /** - * Sets [Builder.quantity] to an arbitrary JSON value. - * - * You should usually call [Builder.quantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun quantity(quantity: JsonField) = apply { this.quantity = quantity } + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateScheduleItems(): Optional> = + updateScheduleItems.getOptional("update_schedule_items") - fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) + /** + * Returns the raw JSON value of [addScheduleItems]. + * + * Unlike [addScheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_schedule_items") + @ExcludeMissing + fun _addScheduleItems(): JsonField> = addScheduleItems - /** - * Sets [Builder.timestamp] to an arbitrary JSON value. - * - * You should usually call [Builder.timestamp] with a well-typed - * [OffsetDateTime] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun timestamp(timestamp: JsonField) = apply { - this.timestamp = timestamp - } + /** + * Returns the raw JSON value of [removeScheduleItems]. + * + * Unlike [removeScheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("remove_schedule_items") + @ExcludeMissing + fun _removeScheduleItems(): JsonField> = removeScheduleItems - fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + /** + * Returns the raw JSON value of [updateScheduleItems]. + * + * Unlike [updateScheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_schedule_items") + @ExcludeMissing + fun _updateScheduleItems(): JsonField> = updateScheduleItems - /** - * Sets [Builder.unitPrice] to an arbitrary JSON value. - * - * You should usually call [Builder.unitPrice] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun unitPrice(unitPrice: JsonField) = apply { - this.unitPrice = unitPrice - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + companion object { - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + /** Returns a mutable builder for constructing an instance of [AccessSchedule]. */ + @JvmStatic fun builder() = Builder() + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** A builder for [AccessSchedule]. */ + class Builder internal constructor() { - /** - * Returns an immutable instance of [UpdateScheduleItem]. - * - * 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(): UpdateScheduleItem = - UpdateScheduleItem( - checkRequired("id", id), - amount, - quantity, - timestamp, - unitPrice, - additionalProperties.toMutableMap(), - ) + private var addScheduleItems: JsonField>? = null + private var removeScheduleItems: JsonField>? = null + private var updateScheduleItems: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(accessSchedule: AccessSchedule) = apply { + addScheduleItems = accessSchedule.addScheduleItems.map { it.toMutableList() } + removeScheduleItems = + accessSchedule.removeScheduleItems.map { it.toMutableList() } + updateScheduleItems = + accessSchedule.updateScheduleItems.map { it.toMutableList() } + additionalProperties = accessSchedule.additionalProperties.toMutableMap() } - private var validated: Boolean = false + fun addScheduleItems(addScheduleItems: List) = + addScheduleItems(JsonField.of(addScheduleItems)) /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. + * Sets [Builder.addScheduleItems] to an arbitrary JSON value. * - * @throws MetronomeInvalidDataException if any value type in this object doesn't - * match its expected type. + * You should usually call [Builder.addScheduleItems] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. */ - fun validate(): UpdateScheduleItem = apply { - if (validated) { - return@apply - } - - id() - amount() - quantity() - timestamp() - unitPrice() - validated = true + fun addScheduleItems(addScheduleItems: JsonField>) = apply { + this.addScheduleItems = addScheduleItems.map { it.toMutableList() } } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * Adds a single [AddScheduleItem] to [addScheduleItems]. * - * Used for best match union deserialization. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JvmSynthetic - internal fun validity(): Int = - (if (id.asKnown().isPresent) 1 else 0) + - (if (amount.asKnown().isPresent) 1 else 0) + - (if (quantity.asKnown().isPresent) 1 else 0) + - (if (timestamp.asKnown().isPresent) 1 else 0) + - (if (unitPrice.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is UpdateScheduleItem && - id == other.id && - amount == other.amount && - quantity == other.quantity && - timestamp == other.timestamp && - unitPrice == other.unitPrice && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(id, amount, quantity, timestamp, unitPrice, additionalProperties) + fun addAddScheduleItem(addScheduleItem: AddScheduleItem) = apply { + addScheduleItems = + (addScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("addScheduleItems", it).add(addScheduleItem) + } } - override fun hashCode(): Int = hashCode + fun removeScheduleItems(removeScheduleItems: List) = + removeScheduleItems(JsonField.of(removeScheduleItems)) - override fun toString() = - "UpdateScheduleItem{id=$id, amount=$amount, quantity=$quantity, timestamp=$timestamp, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" - } + /** + * Sets [Builder.removeScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.removeScheduleItems] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun removeScheduleItems(removeScheduleItems: JsonField>) = + apply { + this.removeScheduleItems = removeScheduleItems.map { it.toMutableList() } + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * Adds a single [RemoveScheduleItem] to [removeScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRemoveScheduleItem(removeScheduleItem: RemoveScheduleItem) = apply { + removeScheduleItems = + (removeScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("removeScheduleItems", it).add(removeScheduleItem) + } } - return other is InvoiceSchedule && - addScheduleItems == other.addScheduleItems && - removeScheduleItems == other.removeScheduleItems && - updateScheduleItems == other.updateScheduleItems && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash( - addScheduleItems, - removeScheduleItems, - updateScheduleItems, - additionalProperties, - ) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "InvoiceSchedule{addScheduleItems=$addScheduleItems, removeScheduleItems=$removeScheduleItems, updateScheduleItems=$updateScheduleItems, additionalProperties=$additionalProperties}" - } - - /** - * If provided, updates the commit to use the specified rate type for current and future - * invoices. Previously finalized invoices will need to be voided and regenerated to reflect - * the rate type change. - */ - class RateType @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 LIST_RATE = of("LIST_RATE") - - @JvmField val COMMIT_RATE = of("COMMIT_RATE") - - @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) - } + fun updateScheduleItems(updateScheduleItems: List) = + updateScheduleItems(JsonField.of(updateScheduleItems)) - /** An enum containing [RateType]'s known values. */ - enum class Known { - LIST_RATE, - COMMIT_RATE, - } + /** + * Sets [Builder.updateScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.updateScheduleItems] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun updateScheduleItems(updateScheduleItems: JsonField>) = + apply { + this.updateScheduleItems = updateScheduleItems.map { it.toMutableList() } + } - /** - * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [RateType] 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 { - LIST_RATE, - COMMIT_RATE, /** - * An enum member indicating that [RateType] was instantiated with an unknown value. + * Adds a single [UpdateScheduleItem] to [updateScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a non-list. */ - _UNKNOWN, - } + fun addUpdateScheduleItem(updateScheduleItem: UpdateScheduleItem) = apply { + updateScheduleItems = + (updateScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("updateScheduleItems", it).add(updateScheduleItem) + } + } - /** - * 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) { - LIST_RATE -> Value.LIST_RATE - COMMIT_RATE -> Value.COMMIT_RATE - else -> Value._UNKNOWN + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - /** - * 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 MetronomeInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - LIST_RATE -> Known.LIST_RATE - COMMIT_RATE -> Known.COMMIT_RATE - else -> throw MetronomeInvalidDataException("Unknown RateType: $value") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, 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 MetronomeInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - MetronomeInvalidDataException("Value is not a String") + 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 [AccessSchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AccessSchedule = + AccessSchedule( + (addScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (removeScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (updateScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + private var validated: Boolean = false /** @@ -32251,12 +34848,14 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't match * its expected type. */ - fun validate(): RateType = apply { + fun validate(): AccessSchedule = apply { if (validated) { return@apply } - known() + addScheduleItems().ifPresent { it.forEach { it.validate() } } + removeScheduleItems().ifPresent { it.forEach { it.validate() } } + updateScheduleItems().ifPresent { it.forEach { it.validate() } } validated = true } @@ -32274,963 +34873,863 @@ private constructor( * * 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 - } + @JvmSynthetic + internal fun validity(): Int = + (addScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (removeScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (updateScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) - return other is RateType && value == other.value - } + class AddScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { - override fun hashCode() = value.hashCode() + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(amount, endingBefore, startingAt, mutableMapOf()) - override fun toString() = value.toString() - } + /** + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * @throws MetronomeInvalidDataException 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 endingBefore(): OffsetDateTime = endingBefore.getRequired("ending_before") - return other is UpdateCommit && - commitId == other.commitId && - accessSchedule == other.accessSchedule && - applicableProductIds == other.applicableProductIds && - applicableProductTags == other.applicableProductTags && - description == other.description && - hierarchyConfiguration == other.hierarchyConfiguration && - invoiceSchedule == other.invoiceSchedule && - name == other.name && - netsuiteSalesOrderId == other.netsuiteSalesOrderId && - priority == other.priority && - productId == other.productId && - rateType == other.rateType && - rolloverFraction == other.rolloverFraction && - additionalProperties == other.additionalProperties - } + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") - private val hashCode: Int by lazy { - Objects.hash( - commitId, - accessSchedule, - applicableProductIds, - applicableProductTags, - description, - hierarchyConfiguration, - invoiceSchedule, - name, - netsuiteSalesOrderId, - priority, - productId, - rateType, - rolloverFraction, - additionalProperties, - ) - } + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore - override fun toString() = - "UpdateCommit{commitId=$commitId, accessSchedule=$accessSchedule, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, productId=$productId, rateType=$rateType, rolloverFraction=$rolloverFraction, additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt - class UpdateCredit - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val creditId: JsonField, - private val accessSchedule: JsonField, - private val applicableProductIds: JsonField>, - private val applicableProductTags: JsonField>, - private val description: JsonField, - private val hierarchyConfiguration: JsonField, - private val name: JsonField, - private val netsuiteSalesOrderId: JsonField, - private val priority: JsonField, - private val productId: JsonField, - private val rateType: JsonField, - private val rolloverFraction: JsonField, - private val additionalProperties: MutableMap, - ) { + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - @JsonCreator - private constructor( - @JsonProperty("credit_id") - @ExcludeMissing - creditId: JsonField = JsonMissing.of(), - @JsonProperty("access_schedule") - @ExcludeMissing - accessSchedule: JsonField = JsonMissing.of(), - @JsonProperty("applicable_product_ids") - @ExcludeMissing - applicableProductIds: JsonField> = JsonMissing.of(), - @JsonProperty("applicable_product_tags") - @ExcludeMissing - applicableProductTags: JsonField> = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - description: JsonField = JsonMissing.of(), - @JsonProperty("hierarchy_configuration") - @ExcludeMissing - hierarchyConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("netsuite_sales_order_id") - @ExcludeMissing - netsuiteSalesOrderId: JsonField = JsonMissing.of(), - @JsonProperty("priority") - @ExcludeMissing - priority: JsonField = JsonMissing.of(), - @JsonProperty("product_id") - @ExcludeMissing - productId: JsonField = JsonMissing.of(), - @JsonProperty("rate_type") - @ExcludeMissing - rateType: JsonField = JsonMissing.of(), - @JsonProperty("rollover_fraction") - @ExcludeMissing - rolloverFraction: JsonField = JsonMissing.of(), - ) : this( - creditId, - accessSchedule, - applicableProductIds, - applicableProductTags, - description, - hierarchyConfiguration, - name, - netsuiteSalesOrderId, - priority, - productId, - rateType, - rolloverFraction, - mutableMapOf(), - ) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /** - * @throws MetronomeInvalidDataException 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 creditId(): String = creditId.getRequired("credit_id") + fun toBuilder() = Builder().from(this) - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun accessSchedule(): Optional = - accessSchedule.getOptional("access_schedule") + companion object { - /** - * Which products the credit applies to. If applicable_product_ids, applicable_product_tags - * or specifiers are not provided, the credit applies to all products. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun applicableProductIds(): Optional> = - applicableProductIds.getOptional("applicable_product_ids") + /** + * Returns a mutable builder for constructing an instance of [AddScheduleItem]. + * + * The following fields are required: + * ```java + * .amount() + * .endingBefore() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * Which tags the credit applies to. If applicable_product_ids, applicable_product_tags or - * specifiers are not provided, the credit applies to all products. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun applicableProductTags(): Optional> = - applicableProductTags.getOptional("applicable_product_tags") + /** A builder for [AddScheduleItem]. */ + class Builder internal constructor() { - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = description.getOptional("description") + private var amount: JsonField? = null + private var endingBefore: JsonField? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - /** - * Optional configuration for commit hierarchy access control - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun hierarchyConfiguration(): Optional = - hierarchyConfiguration.getOptional("hierarchy_configuration") + @JvmSynthetic + internal fun from(addScheduleItem: AddScheduleItem) = apply { + amount = addScheduleItem.amount + endingBefore = addScheduleItem.endingBefore + startingAt = addScheduleItem.startingAt + additionalProperties = addScheduleItem.additionalProperties.toMutableMap() + } - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = name.getOptional("name") + fun amount(amount: Double) = amount(JsonField.of(amount)) - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun netsuiteSalesOrderId(): Optional = - netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun priority(): Optional = priority.getOptional("priority") + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun productId(): Optional = productId.getOptional("product_id") + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } - /** - * If provided, updates the credit to use the specified rate type for current and future - * invoices. Previously finalized invoices will need to be voided and regenerated to reflect - * the rate type change. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun rateType(): Optional = rateType.getOptional("rate_type") + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun rolloverFraction(): Optional = rolloverFraction.getOptional("rollover_fraction") + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } - /** - * Returns the raw JSON value of [creditId]. - * - * Unlike [creditId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("credit_id") @ExcludeMissing fun _creditId(): JsonField = creditId + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Returns the raw JSON value of [accessSchedule]. - * - * Unlike [accessSchedule], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("access_schedule") - @ExcludeMissing - fun _accessSchedule(): JsonField = accessSchedule + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** - * Returns the raw JSON value of [applicableProductIds]. - * - * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("applicable_product_ids") - @ExcludeMissing - fun _applicableProductIds(): JsonField> = applicableProductIds + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** - * Returns the raw JSON value of [applicableProductTags]. - * - * Unlike [applicableProductTags], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("applicable_product_tags") - @ExcludeMissing - fun _applicableProductTags(): JsonField> = applicableProductTags + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * Returns the raw JSON value of [hierarchyConfiguration]. - * - * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("hierarchy_configuration") - @ExcludeMissing - fun _hierarchyConfiguration(): JsonField = - hierarchyConfiguration + /** + * Returns an immutable instance of [AddScheduleItem]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .endingBefore() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddScheduleItem = + AddScheduleItem( + checkRequired("amount", amount), + checkRequired("endingBefore", endingBefore), + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } - /** - * 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 + private var validated: Boolean = false - /** - * Returns the raw JSON value of [netsuiteSalesOrderId]. - * - * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("netsuite_sales_order_id") - @ExcludeMissing - fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddScheduleItem = apply { + if (validated) { + return@apply + } - /** - * Returns the raw JSON value of [priority]. - * - * Unlike [priority], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("priority") @ExcludeMissing fun _priority(): JsonField = priority + amount() + endingBefore() + startingAt() + validated = true + } - /** - * Returns the raw JSON value of [productId]. - * - * Unlike [productId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("product_id") @ExcludeMissing fun _productId(): JsonField = productId + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } - /** - * Returns the raw JSON value of [rateType]. - * - * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("rate_type") @ExcludeMissing fun _rateType(): JsonField = rateType + /** + * 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 (amount.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) - /** - * Returns the raw JSON value of [rolloverFraction]. - * - * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("rollover_fraction") - @ExcludeMissing - fun _rolloverFraction(): JsonField = rolloverFraction + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + return other is AddScheduleItem && + amount == other.amount && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + private val hashCode: Int by lazy { + Objects.hash(amount, endingBefore, startingAt, additionalProperties) + } - fun toBuilder() = Builder().from(this) + override fun hashCode(): Int = hashCode - companion object { + override fun toString() = + "AddScheduleItem{amount=$amount, endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } - /** - * Returns a mutable builder for constructing an instance of [UpdateCredit]. - * - * The following fields are required: - * ```java - * .creditId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + class RemoveScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val additionalProperties: MutableMap, + ) { - /** A builder for [UpdateCredit]. */ - class Builder internal constructor() { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() + ) : this(id, mutableMapOf()) - private var creditId: JsonField? = null - private var accessSchedule: JsonField = JsonMissing.of() - private var applicableProductIds: JsonField>? = null - private var applicableProductTags: JsonField>? = null - private var description: JsonField = JsonMissing.of() - private var hierarchyConfiguration: JsonField = - JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var netsuiteSalesOrderId: JsonField = JsonMissing.of() - private var priority: JsonField = JsonMissing.of() - private var productId: JsonField = JsonMissing.of() - private var rateType: JsonField = JsonMissing.of() - private var rolloverFraction: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * @throws MetronomeInvalidDataException 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") - @JvmSynthetic - internal fun from(updateCredit: UpdateCredit) = apply { - creditId = updateCredit.creditId - accessSchedule = updateCredit.accessSchedule - applicableProductIds = updateCredit.applicableProductIds.map { it.toMutableList() } - applicableProductTags = - updateCredit.applicableProductTags.map { it.toMutableList() } - description = updateCredit.description - hierarchyConfiguration = updateCredit.hierarchyConfiguration - name = updateCredit.name - netsuiteSalesOrderId = updateCredit.netsuiteSalesOrderId - priority = updateCredit.priority - productId = updateCredit.productId - rateType = updateCredit.rateType - rolloverFraction = updateCredit.rolloverFraction - additionalProperties = updateCredit.additionalProperties.toMutableMap() - } + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - fun creditId(creditId: String) = creditId(JsonField.of(creditId)) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * Sets [Builder.creditId] to an arbitrary JSON value. - * - * You should usually call [Builder.creditId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun creditId(creditId: JsonField) = apply { this.creditId = creditId } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun accessSchedule(accessSchedule: AccessSchedule) = - accessSchedule(JsonField.of(accessSchedule)) + fun toBuilder() = Builder().from(this) - /** - * Sets [Builder.accessSchedule] to an arbitrary JSON value. - * - * You should usually call [Builder.accessSchedule] with a well-typed [AccessSchedule] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun accessSchedule(accessSchedule: JsonField) = apply { - this.accessSchedule = accessSchedule - } + companion object { - /** - * Which products the credit applies to. If applicable_product_ids, - * applicable_product_tags or specifiers are not provided, the credit applies to all - * products. - */ - fun applicableProductIds(applicableProductIds: List?) = - applicableProductIds(JsonField.ofNullable(applicableProductIds)) + /** + * Returns a mutable builder for constructing an instance of + * [RemoveScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * Alias for calling [Builder.applicableProductIds] with - * `applicableProductIds.orElse(null)`. - */ - fun applicableProductIds(applicableProductIds: Optional>) = - applicableProductIds(applicableProductIds.getOrNull()) + /** A builder for [RemoveScheduleItem]. */ + class Builder internal constructor() { - /** - * Sets [Builder.applicableProductIds] to an arbitrary JSON value. - * - * You should usually call [Builder.applicableProductIds] with a well-typed - * `List` value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun applicableProductIds(applicableProductIds: JsonField>) = apply { - this.applicableProductIds = applicableProductIds.map { it.toMutableList() } - } + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - /** - * Adds a single [String] to [applicableProductIds]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addApplicableProductId(applicableProductId: String) = apply { - applicableProductIds = - (applicableProductIds ?: JsonField.of(mutableListOf())).also { - checkKnown("applicableProductIds", it).add(applicableProductId) + @JvmSynthetic + internal fun from(removeScheduleItem: RemoveScheduleItem) = apply { + id = removeScheduleItem.id + additionalProperties = + removeScheduleItem.additionalProperties.toMutableMap() } - } - /** - * Which tags the credit applies to. If applicable_product_ids, applicable_product_tags - * or specifiers are not provided, the credit applies to all products. - */ - fun applicableProductTags(applicableProductTags: List?) = - applicableProductTags(JsonField.ofNullable(applicableProductTags)) - - /** - * Alias for calling [Builder.applicableProductTags] with - * `applicableProductTags.orElse(null)`. - */ - fun applicableProductTags(applicableProductTags: Optional>) = - applicableProductTags(applicableProductTags.getOrNull()) + fun id(id: String) = id(JsonField.of(id)) - /** - * Sets [Builder.applicableProductTags] to an arbitrary JSON value. - * - * You should usually call [Builder.applicableProductTags] with a well-typed - * `List` value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun applicableProductTags(applicableProductTags: JsonField>) = apply { - this.applicableProductTags = applicableProductTags.map { it.toMutableList() } - } + /** + * 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 } - /** - * Adds a single [String] to [applicableProductTags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addApplicableProductTag(applicableProductTag: String) = apply { - applicableProductTags = - (applicableProductTags ?: JsonField.of(mutableListOf())).also { - checkKnown("applicableProductTags", it).add(applicableProductTag) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - } - - fun description(description: String) = description(JsonField.of(description)) - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** Optional configuration for commit hierarchy access control */ - fun hierarchyConfiguration(hierarchyConfiguration: CommitHierarchyConfiguration) = - hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** - * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.hierarchyConfiguration] with a well-typed - * [CommitHierarchyConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun hierarchyConfiguration( - hierarchyConfiguration: JsonField - ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun name(name: String) = name(JsonField.of(name)) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * 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 } + /** + * Returns an immutable instance of [RemoveScheduleItem]. + * + * 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(): RemoveScheduleItem = + RemoveScheduleItem( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } - fun netsuiteSalesOrderId(netsuiteSalesOrderId: String?) = - netsuiteSalesOrderId(JsonField.ofNullable(netsuiteSalesOrderId)) + private var validated: Boolean = false - /** - * Alias for calling [Builder.netsuiteSalesOrderId] with - * `netsuiteSalesOrderId.orElse(null)`. - */ - fun netsuiteSalesOrderId(netsuiteSalesOrderId: Optional) = - netsuiteSalesOrderId(netsuiteSalesOrderId.getOrNull()) + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): RemoveScheduleItem = apply { + if (validated) { + return@apply + } - /** - * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. - * - * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { - this.netsuiteSalesOrderId = netsuiteSalesOrderId - } + id() + validated = true + } - fun priority(priority: Double?) = priority(JsonField.ofNullable(priority)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } - /** - * Alias for [Builder.priority]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun priority(priority: Double) = priority(priority as Double?) + /** + * 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) - /** Alias for calling [Builder.priority] with `priority.orElse(null)`. */ - fun priority(priority: Optional) = priority(priority.getOrNull()) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Sets [Builder.priority] to an arbitrary JSON value. - * - * You should usually call [Builder.priority] with a well-typed [Double] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun priority(priority: JsonField) = apply { this.priority = priority } + return other is RemoveScheduleItem && + id == other.id && + additionalProperties == other.additionalProperties + } - fun productId(productId: String) = productId(JsonField.of(productId)) + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - /** - * Sets [Builder.productId] to an arbitrary JSON value. - * - * You should usually call [Builder.productId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun productId(productId: JsonField) = apply { this.productId = productId } + override fun hashCode(): Int = hashCode - /** - * If provided, updates the credit to use the specified rate type for current and future - * invoices. Previously finalized invoices will need to be voided and regenerated to - * reflect the rate type change. - */ - fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + override fun toString() = + "RemoveScheduleItem{id=$id, additionalProperties=$additionalProperties}" + } - /** - * Sets [Builder.rateType] to an arbitrary JSON value. - * - * You should usually call [Builder.rateType] with a well-typed [RateType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + class UpdateScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val amount: JsonField, + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { - fun rolloverFraction(rolloverFraction: Double?) = - rolloverFraction(JsonField.ofNullable(rolloverFraction)) + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(id, amount, endingBefore, startingAt, mutableMapOf()) - /** - * Alias for [Builder.rolloverFraction]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun rolloverFraction(rolloverFraction: Double) = - rolloverFraction(rolloverFraction as Double?) + /** + * @throws MetronomeInvalidDataException 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") - /** - * Alias for calling [Builder.rolloverFraction] with `rolloverFraction.orElse(null)`. - */ - fun rolloverFraction(rolloverFraction: Optional) = - rolloverFraction(rolloverFraction.getOrNull()) + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") - /** - * Sets [Builder.rolloverFraction] to an arbitrary JSON value. - * - * You should usually call [Builder.rolloverFraction] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun rolloverFraction(rolloverFraction: JsonField) = apply { - this.rolloverFraction = rolloverFraction - } + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun startingAt(): Optional = startingAt.getOptional("starting_at") - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt - /** - * Returns an immutable instance of [UpdateCredit]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .creditId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): UpdateCredit = - UpdateCredit( - checkRequired("creditId", creditId), - accessSchedule, - (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, - (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, - description, - hierarchyConfiguration, - name, - netsuiteSalesOrderId, - priority, - productId, - rateType, - rolloverFraction, - additionalProperties.toMutableMap(), - ) - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): UpdateCredit = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - creditId() - accessSchedule().ifPresent { it.validate() } - applicableProductIds() - applicableProductTags() - description() - hierarchyConfiguration().ifPresent { it.validate() } - name() - netsuiteSalesOrderId() - priority() - productId() - rateType().ifPresent { it.validate() } - rolloverFraction() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of + * [UpdateScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 (creditId.asKnown().isPresent) 1 else 0) + - (accessSchedule.asKnown().getOrNull()?.validity() ?: 0) + - (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + - (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + - (if (description.asKnown().isPresent) 1 else 0) + - (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + - (if (priority.asKnown().isPresent) 1 else 0) + - (if (productId.asKnown().isPresent) 1 else 0) + - (rateType.asKnown().getOrNull()?.validity() ?: 0) + - (if (rolloverFraction.asKnown().isPresent) 1 else 0) + /** A builder for [UpdateScheduleItem]. */ + class Builder internal constructor() { - class AccessSchedule - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val addScheduleItems: JsonField>, - private val removeScheduleItems: JsonField>, - private val updateScheduleItems: JsonField>, - private val additionalProperties: MutableMap, - ) { + private var id: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var startingAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - @JsonCreator - private constructor( - @JsonProperty("add_schedule_items") - @ExcludeMissing - addScheduleItems: JsonField> = JsonMissing.of(), - @JsonProperty("remove_schedule_items") - @ExcludeMissing - removeScheduleItems: JsonField> = JsonMissing.of(), - @JsonProperty("update_schedule_items") - @ExcludeMissing - updateScheduleItems: JsonField> = JsonMissing.of(), - ) : this(addScheduleItems, removeScheduleItems, updateScheduleItems, mutableMapOf()) + @JvmSynthetic + internal fun from(updateScheduleItem: UpdateScheduleItem) = apply { + id = updateScheduleItem.id + amount = updateScheduleItem.amount + endingBefore = updateScheduleItem.endingBefore + startingAt = updateScheduleItem.startingAt + additionalProperties = + updateScheduleItem.additionalProperties.toMutableMap() + } - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun addScheduleItems(): Optional> = - addScheduleItems.getOptional("add_schedule_items") + fun id(id: String) = id(JsonField.of(id)) - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun removeScheduleItems(): Optional> = - removeScheduleItems.getOptional("remove_schedule_items") + /** + * 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 } - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun updateScheduleItems(): Optional> = - updateScheduleItems.getOptional("update_schedule_items") + fun amount(amount: Double) = amount(JsonField.of(amount)) - /** - * Returns the raw JSON value of [addScheduleItems]. - * - * Unlike [addScheduleItems], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("add_schedule_items") - @ExcludeMissing - fun _addScheduleItems(): JsonField> = addScheduleItems + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } - /** - * Returns the raw JSON value of [removeScheduleItems]. - * - * Unlike [removeScheduleItems], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("remove_schedule_items") - @ExcludeMissing - fun _removeScheduleItems(): JsonField> = removeScheduleItems + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) - /** - * Returns the raw JSON value of [updateScheduleItems]. - * - * Unlike [updateScheduleItems], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("update_schedule_items") - @ExcludeMissing - fun _updateScheduleItems(): JsonField> = updateScheduleItems + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } - fun toBuilder() = Builder().from(this) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - companion object { + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** Returns a mutable builder for constructing an instance of [AccessSchedule]. */ - @JvmStatic fun builder() = Builder() - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** A builder for [AccessSchedule]. */ - class Builder internal constructor() { + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - private var addScheduleItems: JsonField>? = null - private var removeScheduleItems: JsonField>? = null - private var updateScheduleItems: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - @JvmSynthetic - internal fun from(accessSchedule: AccessSchedule) = apply { - addScheduleItems = accessSchedule.addScheduleItems.map { it.toMutableList() } - removeScheduleItems = - accessSchedule.removeScheduleItems.map { it.toMutableList() } - updateScheduleItems = - accessSchedule.updateScheduleItems.map { it.toMutableList() } - additionalProperties = accessSchedule.additionalProperties.toMutableMap() + /** + * Returns an immutable instance of [UpdateScheduleItem]. + * + * 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(): UpdateScheduleItem = + UpdateScheduleItem( + checkRequired("id", id), + amount, + endingBefore, + startingAt, + additionalProperties.toMutableMap(), + ) } - fun addScheduleItems(addScheduleItems: List) = - addScheduleItems(JsonField.of(addScheduleItems)) + private var validated: Boolean = false /** - * Sets [Builder.addScheduleItems] to an arbitrary JSON value. + * Validates that the types of all values in this object match their expected types + * recursively. * - * You should usually call [Builder.addScheduleItems] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun addScheduleItems(addScheduleItems: JsonField>) = apply { - this.addScheduleItems = addScheduleItems.map { it.toMutableList() } - } - - /** - * Adds a single [AddScheduleItem] to [addScheduleItems]. + * This method is _not_ forwards compatible with new types from the API for existing + * fields. * - * @throws IllegalStateException if the field was previously set to a non-list. + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. */ - fun addAddScheduleItem(addScheduleItem: AddScheduleItem) = apply { - addScheduleItems = - (addScheduleItems ?: JsonField.of(mutableListOf())).also { - checkKnown("addScheduleItems", it).add(addScheduleItem) - } + fun validate(): UpdateScheduleItem = apply { + if (validated) { + return@apply + } + + id() + amount() + endingBefore() + startingAt() + validated = true } - fun removeScheduleItems(removeScheduleItems: List) = - removeScheduleItems(JsonField.of(removeScheduleItems)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } /** - * Sets [Builder.removeScheduleItems] to an arbitrary JSON value. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * You should usually call [Builder.removeScheduleItems] with a well-typed - * `List` value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. + * Used for best match union deserialization. */ - fun removeScheduleItems(removeScheduleItems: JsonField>) = - apply { - this.removeScheduleItems = removeScheduleItems.map { it.toMutableList() } + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - /** - * Adds a single [RemoveScheduleItem] to [removeScheduleItems]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addRemoveScheduleItem(removeScheduleItem: RemoveScheduleItem) = apply { - removeScheduleItems = - (removeScheduleItems ?: JsonField.of(mutableListOf())).also { - checkKnown("removeScheduleItems", it).add(removeScheduleItem) - } + return other is UpdateScheduleItem && + id == other.id && + amount == other.amount && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties } - fun updateScheduleItems(updateScheduleItems: List) = - updateScheduleItems(JsonField.of(updateScheduleItems)) + private val hashCode: Int by lazy { + Objects.hash(id, amount, endingBefore, startingAt, additionalProperties) + } - /** - * Sets [Builder.updateScheduleItems] to an arbitrary JSON value. - * - * You should usually call [Builder.updateScheduleItems] with a well-typed - * `List` value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun updateScheduleItems(updateScheduleItems: JsonField>) = - apply { - this.updateScheduleItems = updateScheduleItems.map { it.toMutableList() } - } + override fun hashCode(): Int = hashCode - /** - * Adds a single [UpdateScheduleItem] to [updateScheduleItems]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addUpdateScheduleItem(updateScheduleItem: UpdateScheduleItem) = apply { - updateScheduleItems = - (updateScheduleItems ?: JsonField.of(mutableListOf())).also { - checkKnown("updateScheduleItems", it).add(updateScheduleItem) - } + override fun toString() = + "UpdateScheduleItem{id=$id, amount=$amount, endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + return other is AccessSchedule && + addScheduleItems == other.addScheduleItems && + removeScheduleItems == other.removeScheduleItems && + updateScheduleItems == other.updateScheduleItems && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessSchedule{addScheduleItems=$addScheduleItems, removeScheduleItems=$removeScheduleItems, updateScheduleItems=$updateScheduleItems, additionalProperties=$additionalProperties}" + } + + /** + * If provided, updates the credit to use the specified rate type for current and future + * invoices. Previously finalized invoices will need to be voided and regenerated to reflect + * the rate type change. + */ + class RateType @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 { - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + @JvmField val LIST_RATE = of("LIST_RATE") - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + @JvmField val COMMIT_RATE = of("COMMIT_RATE") - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** An enum containing [RateType]'s known values. */ + enum class Known { + LIST_RATE, + COMMIT_RATE, + } + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [RateType] 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 { + LIST_RATE, + COMMIT_RATE, /** - * Returns an immutable instance of [AccessSchedule]. - * - * Further updates to this [Builder] will not mutate the returned instance. + * An enum member indicating that [RateType] was instantiated with an unknown value. */ - fun build(): AccessSchedule = - AccessSchedule( - (addScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, - (removeScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, - (updateScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) + _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) { + LIST_RATE -> Value.LIST_RATE + COMMIT_RATE -> Value.COMMIT_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + LIST_RATE -> Known.LIST_RATE + COMMIT_RATE -> Known.COMMIT_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + private var validated: Boolean = false /** @@ -33243,14 +35742,12 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't match * its expected type. */ - fun validate(): AccessSchedule = apply { + fun validate(): RateType = apply { if (validated) { return@apply } - addScheduleItems().ifPresent { it.forEach { it.validate() } } - removeScheduleItems().ifPresent { it.forEach { it.validate() } } - updateScheduleItems().ifPresent { it.forEach { it.validate() } } + known() validated = true } @@ -33268,863 +35765,1012 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic - internal fun validity(): Int = - (addScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (removeScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } - ?: 0) + - (updateScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } - ?: 0) + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - class AddScheduleItem - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val amount: JsonField, - private val endingBefore: JsonField, - private val startingAt: JsonField, - private val additionalProperties: MutableMap, - ) { + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - @JsonCreator - private constructor( - @JsonProperty("amount") - @ExcludeMissing - amount: JsonField = JsonMissing.of(), - @JsonProperty("ending_before") - @ExcludeMissing - endingBefore: JsonField = JsonMissing.of(), - @JsonProperty("starting_at") - @ExcludeMissing - startingAt: JsonField = JsonMissing.of(), - ) : this(amount, endingBefore, startingAt, mutableMapOf()) + return other is RateType && value == other.value + } - /** - * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + override fun hashCode() = value.hashCode() - /** - * @throws MetronomeInvalidDataException 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 endingBefore(): OffsetDateTime = endingBefore.getRequired("ending_before") + override fun toString() = value.toString() + } - /** - * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + return other is UpdateCredit && + creditId == other.creditId && + accessSchedule == other.accessSchedule && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + description == other.description && + hierarchyConfiguration == other.hierarchyConfiguration && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + priority == other.priority && + productId == other.productId && + rateType == other.rateType && + rolloverFraction == other.rolloverFraction && + additionalProperties == other.additionalProperties + } - /** - * Returns the raw JSON value of [endingBefore]. - * - * Unlike [endingBefore], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("ending_before") - @ExcludeMissing - fun _endingBefore(): JsonField = endingBefore + private val hashCode: Int by lazy { + Objects.hash( + creditId, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + additionalProperties, + ) + } - /** - * Returns the raw JSON value of [startingAt]. - * - * Unlike [startingAt], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("starting_at") - @ExcludeMissing - fun _startingAt(): JsonField = startingAt + override fun hashCode(): Int = hashCode - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + override fun toString() = + "UpdateCredit{creditId=$creditId, accessSchedule=$accessSchedule, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, description=$description, hierarchyConfiguration=$hierarchyConfiguration, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, productId=$productId, rateType=$rateType, rolloverFraction=$rolloverFraction, additionalProperties=$additionalProperties}" + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + class UpdatePrepaidBalanceThresholdConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val commit: JsonField, + private val customCreditTypeId: JsonField, + private val discountConfiguration: JsonField, + private val isEnabled: JsonField, + private val paymentGateConfig: JsonField, + private val rechargeToAmount: JsonField, + private val thresholdAmount: JsonField, + private val thresholdBalanceSpecifiers: JsonField>, + private val additionalProperties: MutableMap, + ) { - fun toBuilder() = Builder().from(this) + @JsonCreator + private constructor( + @JsonProperty("commit") @ExcludeMissing commit: JsonField = JsonMissing.of(), + @JsonProperty("custom_credit_type_id") + @ExcludeMissing + customCreditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("discount_configuration") + @ExcludeMissing + discountConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("is_enabled") + @ExcludeMissing + isEnabled: JsonField = JsonMissing.of(), + @JsonProperty("payment_gate_config") + @ExcludeMissing + paymentGateConfig: JsonField = JsonMissing.of(), + @JsonProperty("recharge_to_amount") + @ExcludeMissing + rechargeToAmount: JsonField = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + thresholdBalanceSpecifiers: JsonField> = + JsonMissing.of(), + ) : this( + commit, + customCreditTypeId, + discountConfiguration, + isEnabled, + paymentGateConfig, + rechargeToAmount, + thresholdAmount, + thresholdBalanceSpecifiers, + mutableMapOf(), + ) - companion object { + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun commit(): Optional = commit.getOptional("commit") - /** - * Returns a mutable builder for constructing an instance of [AddScheduleItem]. - * - * The following fields are required: - * ```java - * .amount() - * .endingBefore() - * .startingAt() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + /** + * If provided, the threshold, recharge-to amount, and the resulting threshold commit amount + * will be in terms of this credit type instead of the fiat currency. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun customCreditTypeId(): Optional = + customCreditTypeId.getOptional("custom_credit_type_id") - /** A builder for [AddScheduleItem]. */ - class Builder internal constructor() { + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun discountConfiguration(): Optional = + discountConfiguration.getOptional("discount_configuration") + + /** + * When set to false, the contract will not be evaluated against the threshold_amount. + * Toggling to true will result an immediate evaluation, regardless of prior state. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun isEnabled(): Optional = isEnabled.getOptional("is_enabled") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun paymentGateConfig(): Optional = + paymentGateConfig.getOptional("payment_gate_config") + + /** + * Specify the amount the balance should be recharged to. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rechargeToAmount(): Optional = + rechargeToAmount.getOptional("recharge_to_amount") + + /** + * Specify the threshold amount for the contract. Each time the contract's balance lowers to + * this amount, a threshold charge will be initiated. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun thresholdAmount(): Optional = thresholdAmount.getOptional("threshold_amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun thresholdBalanceSpecifiers(): Optional> = + thresholdBalanceSpecifiers.getOptional("threshold_balance_specifiers") + + /** + * Returns the raw JSON value of [commit]. + * + * Unlike [commit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("commit") @ExcludeMissing fun _commit(): JsonField = commit + + /** + * Returns the raw JSON value of [customCreditTypeId]. + * + * Unlike [customCreditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("custom_credit_type_id") + @ExcludeMissing + fun _customCreditTypeId(): JsonField = customCreditTypeId + + /** + * Returns the raw JSON value of [discountConfiguration]. + * + * Unlike [discountConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("discount_configuration") + @ExcludeMissing + fun _discountConfiguration(): JsonField = discountConfiguration + + /** + * Returns the raw JSON value of [isEnabled]. + * + * Unlike [isEnabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_enabled") @ExcludeMissing fun _isEnabled(): JsonField = isEnabled + + /** + * Returns the raw JSON value of [paymentGateConfig]. + * + * Unlike [paymentGateConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_gate_config") + @ExcludeMissing + fun _paymentGateConfig(): JsonField = paymentGateConfig + + /** + * Returns the raw JSON value of [rechargeToAmount]. + * + * Unlike [rechargeToAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("recharge_to_amount") + @ExcludeMissing + fun _rechargeToAmount(): JsonField = rechargeToAmount + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + /** + * Returns the raw JSON value of [thresholdBalanceSpecifiers]. + * + * Unlike [thresholdBalanceSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + fun _thresholdBalanceSpecifiers(): JsonField> = + thresholdBalanceSpecifiers + + @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 + * [UpdatePrepaidBalanceThresholdConfiguration]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdatePrepaidBalanceThresholdConfiguration]. */ + class Builder internal constructor() { + + private var commit: JsonField = JsonMissing.of() + private var customCreditTypeId: JsonField = JsonMissing.of() + private var discountConfiguration: JsonField = JsonMissing.of() + private var isEnabled: JsonField = JsonMissing.of() + private var paymentGateConfig: JsonField = JsonMissing.of() + private var rechargeToAmount: JsonField = JsonMissing.of() + private var thresholdAmount: JsonField = JsonMissing.of() + private var thresholdBalanceSpecifiers: + JsonField>? = + null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + updatePrepaidBalanceThresholdConfiguration: + UpdatePrepaidBalanceThresholdConfiguration + ) = apply { + commit = updatePrepaidBalanceThresholdConfiguration.commit + customCreditTypeId = updatePrepaidBalanceThresholdConfiguration.customCreditTypeId + discountConfiguration = + updatePrepaidBalanceThresholdConfiguration.discountConfiguration + isEnabled = updatePrepaidBalanceThresholdConfiguration.isEnabled + paymentGateConfig = updatePrepaidBalanceThresholdConfiguration.paymentGateConfig + rechargeToAmount = updatePrepaidBalanceThresholdConfiguration.rechargeToAmount + thresholdAmount = updatePrepaidBalanceThresholdConfiguration.thresholdAmount + thresholdBalanceSpecifiers = + updatePrepaidBalanceThresholdConfiguration.thresholdBalanceSpecifiers.map { + it.toMutableList() + } + additionalProperties = + updatePrepaidBalanceThresholdConfiguration.additionalProperties.toMutableMap() + } + + fun commit(commit: Commit) = commit(JsonField.of(commit)) + + /** + * Sets [Builder.commit] to an arbitrary JSON value. + * + * You should usually call [Builder.commit] with a well-typed [Commit] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun commit(commit: JsonField) = apply { this.commit = commit } + + /** + * If provided, the threshold, recharge-to amount, and the resulting threshold commit + * amount will be in terms of this credit type instead of the fiat currency. + */ + fun customCreditTypeId(customCreditTypeId: String?) = + customCreditTypeId(JsonField.ofNullable(customCreditTypeId)) + + /** + * Alias for calling [Builder.customCreditTypeId] with + * `customCreditTypeId.orElse(null)`. + */ + fun customCreditTypeId(customCreditTypeId: Optional) = + customCreditTypeId(customCreditTypeId.getOrNull()) + + /** + * Sets [Builder.customCreditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.customCreditTypeId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun customCreditTypeId(customCreditTypeId: JsonField) = apply { + this.customCreditTypeId = customCreditTypeId + } - private var amount: JsonField? = null - private var endingBefore: JsonField? = null - private var startingAt: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + fun discountConfiguration(discountConfiguration: DiscountConfiguration?) = + discountConfiguration(JsonField.ofNullable(discountConfiguration)) - @JvmSynthetic - internal fun from(addScheduleItem: AddScheduleItem) = apply { - amount = addScheduleItem.amount - endingBefore = addScheduleItem.endingBefore - startingAt = addScheduleItem.startingAt - additionalProperties = addScheduleItem.additionalProperties.toMutableMap() - } + /** + * Alias for calling [Builder.discountConfiguration] with + * `discountConfiguration.orElse(null)`. + */ + fun discountConfiguration(discountConfiguration: Optional) = + discountConfiguration(discountConfiguration.getOrNull()) - fun amount(amount: Double) = amount(JsonField.of(amount)) + /** + * Sets [Builder.discountConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.discountConfiguration] with a well-typed + * [DiscountConfiguration] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun discountConfiguration(discountConfiguration: JsonField) = + apply { + this.discountConfiguration = discountConfiguration + } - /** - * Sets [Builder.amount] to an arbitrary JSON value. - * - * You should usually call [Builder.amount] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun amount(amount: JsonField) = apply { this.amount = amount } + /** + * When set to false, the contract will not be evaluated against the threshold_amount. + * Toggling to true will result an immediate evaluation, regardless of prior state. + */ + fun isEnabled(isEnabled: Boolean) = isEnabled(JsonField.of(isEnabled)) - fun endingBefore(endingBefore: OffsetDateTime) = - endingBefore(JsonField.of(endingBefore)) + /** + * Sets [Builder.isEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.isEnabled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isEnabled(isEnabled: JsonField) = apply { this.isEnabled = isEnabled } - /** - * Sets [Builder.endingBefore] to an arbitrary JSON value. - * - * You should usually call [Builder.endingBefore] with a well-typed - * [OffsetDateTime] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun endingBefore(endingBefore: JsonField) = apply { - this.endingBefore = endingBefore - } + fun paymentGateConfig(paymentGateConfig: PaymentGateConfigV2) = + paymentGateConfig(JsonField.of(paymentGateConfig)) - fun startingAt(startingAt: OffsetDateTime) = - startingAt(JsonField.of(startingAt)) + /** + * Sets [Builder.paymentGateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentGateConfig] with a well-typed + * [PaymentGateConfigV2] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun paymentGateConfig(paymentGateConfig: JsonField) = apply { + this.paymentGateConfig = paymentGateConfig + } - /** - * Sets [Builder.startingAt] to an arbitrary JSON value. - * - * You should usually call [Builder.startingAt] with a well-typed - * [OffsetDateTime] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun startingAt(startingAt: JsonField) = apply { - this.startingAt = startingAt - } + /** Specify the amount the balance should be recharged to. */ + fun rechargeToAmount(rechargeToAmount: Double) = + rechargeToAmount(JsonField.of(rechargeToAmount)) - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * Sets [Builder.rechargeToAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.rechargeToAmount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rechargeToAmount(rechargeToAmount: JsonField) = apply { + this.rechargeToAmount = rechargeToAmount + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Specify the threshold amount for the contract. Each time the contract's balance + * lowers to this amount, a threshold charge will be initiated. + */ + fun thresholdAmount(thresholdAmount: Double) = + thresholdAmount(JsonField.of(thresholdAmount)) - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: List? + ) = thresholdBalanceSpecifiers(JsonField.ofNullable(thresholdBalanceSpecifiers)) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Alias for calling [Builder.thresholdBalanceSpecifiers] with + * `thresholdBalanceSpecifiers.orElse(null)`. + */ + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: Optional> + ) = thresholdBalanceSpecifiers(thresholdBalanceSpecifiers.getOrNull()) - /** - * Returns an immutable instance of [AddScheduleItem]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .endingBefore() - * .startingAt() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): AddScheduleItem = - AddScheduleItem( - checkRequired("amount", amount), - checkRequired("endingBefore", endingBefore), - checkRequired("startingAt", startingAt), - additionalProperties.toMutableMap(), - ) + /** + * Sets [Builder.thresholdBalanceSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdBalanceSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: JsonField> + ) = apply { + this.thresholdBalanceSpecifiers = + thresholdBalanceSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ThresholdBalanceSpecifier] to [thresholdBalanceSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addThresholdBalanceSpecifier(thresholdBalanceSpecifier: ThresholdBalanceSpecifier) = + apply { + thresholdBalanceSpecifiers = + (thresholdBalanceSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("thresholdBalanceSpecifiers", it) + .add(thresholdBalanceSpecifier) + } } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): AddScheduleItem = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - amount() - endingBefore() - startingAt() - validated = true - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - /** - * 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 (amount.asKnown().isPresent) 1 else 0) + - (if (endingBefore.asKnown().isPresent) 1 else 0) + - (if (startingAt.asKnown().isPresent) 1 else 0) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns an immutable instance of [UpdatePrepaidBalanceThresholdConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): UpdatePrepaidBalanceThresholdConfiguration = + UpdatePrepaidBalanceThresholdConfiguration( + commit, + customCreditTypeId, + discountConfiguration, + isEnabled, + paymentGateConfig, + rechargeToAmount, + thresholdAmount, + (thresholdBalanceSpecifiers ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } - return other is AddScheduleItem && - amount == other.amount && - endingBefore == other.endingBefore && - startingAt == other.startingAt && - additionalProperties == other.additionalProperties - } + private var validated: Boolean = false - private val hashCode: Int by lazy { - Objects.hash(amount, endingBefore, startingAt, additionalProperties) - } + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): UpdatePrepaidBalanceThresholdConfiguration = apply { + if (validated) { + return@apply + } - override fun hashCode(): Int = hashCode + commit().ifPresent { it.validate() } + customCreditTypeId() + discountConfiguration().ifPresent { it.validate() } + isEnabled() + paymentGateConfig().ifPresent { it.validate() } + rechargeToAmount() + thresholdAmount() + thresholdBalanceSpecifiers().ifPresent { it.forEach { it.validate() } } + validated = true + } - override fun toString() = - "AddScheduleItem{amount=$amount, endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false } - class RemoveScheduleItem - @JsonCreator(mode = JsonCreator.Mode.DISABLED) + /** + * 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 = + (commit.asKnown().getOrNull()?.validity() ?: 0) + + (if (customCreditTypeId.asKnown().isPresent) 1 else 0) + + (discountConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (isEnabled.asKnown().isPresent) 1 else 0) + + (paymentGateConfig.asKnown().getOrNull()?.validity() ?: 0) + + (if (rechargeToAmount.asKnown().isPresent) 1 else 0) + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + (thresholdBalanceSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + class Commit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val description: JsonField, + private val name: JsonField, + private val priority: JsonField, + private val productId: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val specifiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator private constructor( - private val id: JsonField, - private val additionalProperties: MutableMap, - ) { + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product_id") + @ExcludeMissing + productId: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + ) : this( + description, + name, + priority, + productId, + applicableProductIds, + applicableProductTags, + specifiers, + mutableMapOf(), + ) - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() - ) : this(id, mutableMapOf()) + fun toUpdateBaseThresholdCommit(): UpdateBaseThresholdCommit = + UpdateBaseThresholdCommit.builder() + .description(description) + .name(name) + .priority(priority) + .productId(productId) + .build() - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or - * is unexpectedly missing or null (e.g. if the server responded with an - * unexpected value). - */ - fun id(): String = id.getRequired("id") + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") - /** - * 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 + /** + * Specify the name of the line item for the threshold charge. If left blank, it will + * default to the commit product name. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * The priority of the commit, used to determine drawdown order. Lower priority commits + * are consumed first. Defaults to 100 if not specified. On updates, set to null to + * clear a previously configured priority. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun priority(): Optional = priority.getOptional("priority") - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * The commit product that will be used to generate the line item for commit payment. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun productId(): Optional = productId.getOptional("product_id") - fun toBuilder() = Builder().from(this) + /** + * Which products the threshold commit applies to. If both applicable_product_ids and + * applicable_product_tags are not provided, the commit applies to all products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") - companion object { + /** + * Which tags the threshold commit applies to. If both applicable_product_ids and + * applicable_product_tags are not provided, the commit applies to all products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") - /** - * Returns a mutable builder for constructing an instance of - * [RemoveScheduleItem]. - * - * The following fields are required: - * ```java - * .id() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. This field cannot be + * used together with `applicable_product_ids` or `applicable_product_tags`. Instead, to + * target usage by product or product tag, pass those values in the body of + * `specifiers`. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") - /** A builder for [RemoveScheduleItem]. */ - class Builder internal constructor() { + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - private var id: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + /** + * 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 - @JvmSynthetic - internal fun from(removeScheduleItem: RemoveScheduleItem) = apply { - id = removeScheduleItem.id - additionalProperties = - removeScheduleItem.additionalProperties.toMutableMap() - } + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") @ExcludeMissing fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [productId]. + * + * Unlike [productId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product_id") + @ExcludeMissing + fun _productId(): JsonField = productId + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags - fun id(id: String) = id(JsonField.of(id)) + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers - /** - * 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 } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + companion object { - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + /** Returns a mutable builder for constructing an instance of [Commit]. */ + @JvmStatic fun builder() = Builder() + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** A builder for [Commit]. */ + class Builder internal constructor() { - /** - * Returns an immutable instance of [RemoveScheduleItem]. - * - * 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(): RemoveScheduleItem = - RemoveScheduleItem( - checkRequired("id", id), - additionalProperties.toMutableMap(), - ) + private var description: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var priority: JsonField = JsonMissing.of() + private var productId: JsonField = JsonMissing.of() + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var specifiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(commit: Commit) = apply { + description = commit.description + name = commit.name + priority = commit.priority + productId = commit.productId + applicableProductIds = commit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = commit.applicableProductTags.map { it.toMutableList() } + specifiers = commit.specifiers.map { it.toMutableList() } + additionalProperties = commit.additionalProperties.toMutableMap() } - private var validated: Boolean = false + fun description(description: String) = description(JsonField.of(description)) /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws MetronomeInvalidDataException if any value type in this object doesn't - * match its expected type. + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - fun validate(): RemoveScheduleItem = apply { - if (validated) { - return@apply - } - - id() - validated = true + fun description(description: JsonField) = apply { + this.description = description } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + /** + * Specify the name of the line item for the threshold charge. If left blank, it + * will default to the commit product name. + */ + fun name(name: String) = name(JsonField.of(name)) /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * Sets [Builder.name] to an arbitrary JSON value. * - * Used for best match union deserialization. + * 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. */ - @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 RemoveScheduleItem && - id == other.id && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "RemoveScheduleItem{id=$id, additionalProperties=$additionalProperties}" - } - - class UpdateScheduleItem - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val id: JsonField, - private val amount: JsonField, - private val endingBefore: JsonField, - private val startingAt: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("amount") - @ExcludeMissing - amount: JsonField = JsonMissing.of(), - @JsonProperty("ending_before") - @ExcludeMissing - endingBefore: JsonField = JsonMissing.of(), - @JsonProperty("starting_at") - @ExcludeMissing - startingAt: JsonField = JsonMissing.of(), - ) : this(id, amount, endingBefore, startingAt, mutableMapOf()) + fun name(name: JsonField) = apply { this.name = name } /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or - * is unexpectedly missing or null (e.g. if the server responded with an - * unexpected value). + * The priority of the commit, used to determine drawdown order. Lower priority + * commits are consumed first. Defaults to 100 if not specified. On updates, set to + * null to clear a previously configured priority. */ - fun id(): String = id.getRequired("id") + fun priority(priority: Double?) = priority(JsonField.ofNullable(priority)) /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). + * Alias for [Builder.priority]. + * + * This unboxed primitive overload exists for backwards compatibility. */ - fun amount(): Optional = amount.getOptional("amount") + fun priority(priority: Double) = priority(priority as Double?) + + /** Alias for calling [Builder.priority] with `priority.orElse(null)`. */ + fun priority(priority: Optional) = priority(priority.getOrNull()) /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - fun endingBefore(): Optional = - endingBefore.getOptional("ending_before") + fun priority(priority: JsonField) = apply { this.priority = priority } /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). + * The commit product that will be used to generate the line item for commit + * payment. */ - fun startingAt(): Optional = startingAt.getOptional("starting_at") + fun productId(productId: String) = productId(JsonField.of(productId)) /** - * Returns the raw JSON value of [id]. + * Sets [Builder.productId] to an arbitrary JSON value. * - * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.productId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + fun productId(productId: JsonField) = apply { this.productId = productId } /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected - * type. + * Which products the threshold commit applies to. If both applicable_product_ids + * and applicable_product_tags are not provided, the commit applies to all products. */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun applicableProductIds(applicableProductIds: List?) = + applicableProductIds(JsonField.ofNullable(applicableProductIds)) /** - * Returns the raw JSON value of [endingBefore]. - * - * Unlike [endingBefore], this method doesn't throw if the JSON field has an - * unexpected type. + * Alias for calling [Builder.applicableProductIds] with + * `applicableProductIds.orElse(null)`. */ - @JsonProperty("ending_before") - @ExcludeMissing - fun _endingBefore(): JsonField = endingBefore + fun applicableProductIds(applicableProductIds: Optional>) = + applicableProductIds(applicableProductIds.getOrNull()) /** - * Returns the raw JSON value of [startingAt]. + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. * - * Unlike [startingAt], this method doesn't throw if the JSON field has an - * unexpected type. + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. */ - @JsonProperty("starting_at") - @ExcludeMissing - fun _startingAt(): JsonField = startingAt - - @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 - * [UpdateScheduleItem]. - * - * The following fields are required: - * ```java - * .id() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [UpdateScheduleItem]. */ - class Builder internal constructor() { - - private var id: JsonField? = null - private var amount: JsonField = JsonMissing.of() - private var endingBefore: JsonField = JsonMissing.of() - private var startingAt: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(updateScheduleItem: UpdateScheduleItem) = apply { - id = updateScheduleItem.id - amount = updateScheduleItem.amount - endingBefore = updateScheduleItem.endingBefore - startingAt = updateScheduleItem.startingAt - additionalProperties = - updateScheduleItem.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 amount(amount: Double) = amount(JsonField.of(amount)) - - /** - * Sets [Builder.amount] to an arbitrary JSON value. - * - * You should usually call [Builder.amount] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun amount(amount: JsonField) = apply { this.amount = amount } - - fun endingBefore(endingBefore: OffsetDateTime) = - endingBefore(JsonField.of(endingBefore)) - - /** - * Sets [Builder.endingBefore] to an arbitrary JSON value. - * - * You should usually call [Builder.endingBefore] with a well-typed - * [OffsetDateTime] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun endingBefore(endingBefore: JsonField) = apply { - this.endingBefore = endingBefore - } - - fun startingAt(startingAt: OffsetDateTime) = - startingAt(JsonField.of(startingAt)) - - /** - * Sets [Builder.startingAt] to an arbitrary JSON value. - * - * You should usually call [Builder.startingAt] with a well-typed - * [OffsetDateTime] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun startingAt(startingAt: JsonField) = apply { - this.startingAt = startingAt - } - - 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 [UpdateScheduleItem]. - * - * 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(): UpdateScheduleItem = - UpdateScheduleItem( - checkRequired("id", id), - amount, - endingBefore, - startingAt, - additionalProperties.toMutableMap(), - ) + fun applicableProductIds(applicableProductIds: JsonField>) = apply { + this.applicableProductIds = applicableProductIds.map { it.toMutableList() } } - private var validated: Boolean = false - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. + * Adds a single [String] to [applicableProductIds]. * - * @throws MetronomeInvalidDataException if any value type in this object doesn't - * match its expected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun validate(): UpdateScheduleItem = apply { - if (validated) { - return@apply - } - - id() - amount() - endingBefore() - startingAt() - validated = true + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. + * Which tags the threshold commit applies to. If both applicable_product_ids and + * applicable_product_tags are not provided, the commit applies to all products. */ - @JvmSynthetic - internal fun validity(): Int = - (if (id.asKnown().isPresent) 1 else 0) + - (if (amount.asKnown().isPresent) 1 else 0) + - (if (endingBefore.asKnown().isPresent) 1 else 0) + - (if (startingAt.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is UpdateScheduleItem && - id == other.id && - amount == other.amount && - endingBefore == other.endingBefore && - startingAt == other.startingAt && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(id, amount, endingBefore, startingAt, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "UpdateScheduleItem{id=$id, amount=$amount, endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is AccessSchedule && - addScheduleItems == other.addScheduleItems && - removeScheduleItems == other.removeScheduleItems && - updateScheduleItems == other.updateScheduleItems && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash( - addScheduleItems, - removeScheduleItems, - updateScheduleItems, - additionalProperties, - ) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "AccessSchedule{addScheduleItems=$addScheduleItems, removeScheduleItems=$removeScheduleItems, updateScheduleItems=$updateScheduleItems, additionalProperties=$additionalProperties}" - } - - /** - * If provided, updates the credit to use the specified rate type for current and future - * invoices. Previously finalized invoices will need to be voided and regenerated to reflect - * the rate type change. - */ - class RateType @JsonCreator private constructor(private val value: JsonField) : - Enum { + fun applicableProductTags(applicableProductTags: List?) = + applicableProductTags(JsonField.ofNullable(applicableProductTags)) - /** - * 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 + /** + * Alias for calling [Builder.applicableProductTags] with + * `applicableProductTags.orElse(null)`. + */ + fun applicableProductTags(applicableProductTags: Optional>) = + applicableProductTags(applicableProductTags.getOrNull()) - companion object { + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = apply { + this.applicableProductTags = applicableProductTags.map { it.toMutableList() } + } - @JvmField val LIST_RATE = of("LIST_RATE") + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } - @JvmField val COMMIT_RATE = of("COMMIT_RATE") + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. This field cannot be + * used together with `applicable_product_ids` or `applicable_product_tags`. + * Instead, to target usage by product or product tag, pass those values in the body + * of `specifiers`. + */ + fun specifiers(specifiers: List?) = + specifiers(JsonField.ofNullable(specifiers)) - @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) - } + /** Alias for calling [Builder.specifiers] with `specifiers.orElse(null)`. */ + fun specifiers(specifiers: Optional>) = + specifiers(specifiers.getOrNull()) - /** An enum containing [RateType]'s known values. */ - enum class Known { - LIST_RATE, - COMMIT_RATE, - } + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } - /** - * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [RateType] 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 { - LIST_RATE, - COMMIT_RATE, /** - * An enum member indicating that [RateType] was instantiated with an unknown value. + * Adds a single [CommitSpecifierInput] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. */ - _UNKNOWN, - } + fun addSpecifier(specifier: CommitSpecifierInput) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } - /** - * 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) { - LIST_RATE -> Value.LIST_RATE - COMMIT_RATE -> Value.COMMIT_RATE - else -> Value._UNKNOWN + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - /** - * 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 MetronomeInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - LIST_RATE -> Known.LIST_RATE - COMMIT_RATE -> Known.COMMIT_RATE - else -> throw MetronomeInvalidDataException("Unknown RateType: $value") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, 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 MetronomeInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - MetronomeInvalidDataException("Value is not a String") + 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 [Commit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Commit = + Commit( + description, + name, + priority, + productId, + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + private var validated: Boolean = false /** @@ -34137,12 +36783,18 @@ private constructor( * @throws MetronomeInvalidDataException if any value type in this object doesn't match * its expected type. */ - fun validate(): RateType = apply { + fun validate(): Commit = apply { if (validated) { return@apply } - known() + description() + name() + priority() + productId() + applicableProductIds() + applicableProductTags() + specifiers().ifPresent { it.forEach { it.validate() } } validated = true } @@ -34160,673 +36812,536 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + @JvmSynthetic + internal fun validity(): Int = + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (if (productId.asKnown().isPresent) 1 else 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is RateType && value == other.value + return other is Commit && + description == other.description && + name == other.name && + priority == other.priority && + productId == other.productId && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + specifiers == other.specifiers && + additionalProperties == other.additionalProperties } - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + private val hashCode: Int by lazy { + Objects.hash( + description, + name, + priority, + productId, + applicableProductIds, + applicableProductTags, + specifiers, + additionalProperties, + ) } - return other is UpdateCredit && - creditId == other.creditId && - accessSchedule == other.accessSchedule && - applicableProductIds == other.applicableProductIds && - applicableProductTags == other.applicableProductTags && - description == other.description && - hierarchyConfiguration == other.hierarchyConfiguration && - name == other.name && - netsuiteSalesOrderId == other.netsuiteSalesOrderId && - priority == other.priority && - productId == other.productId && - rateType == other.rateType && - rolloverFraction == other.rolloverFraction && - additionalProperties == other.additionalProperties - } + override fun hashCode(): Int = hashCode - private val hashCode: Int by lazy { - Objects.hash( - creditId, - accessSchedule, - applicableProductIds, - applicableProductTags, - description, - hierarchyConfiguration, - name, - netsuiteSalesOrderId, - priority, - productId, - rateType, - rolloverFraction, - additionalProperties, - ) + override fun toString() = + "Commit{description=$description, name=$name, priority=$priority, productId=$productId, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, specifiers=$specifiers, additionalProperties=$additionalProperties}" } - override fun hashCode(): Int = hashCode - - override fun toString() = - "UpdateCredit{creditId=$creditId, accessSchedule=$accessSchedule, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, description=$description, hierarchyConfiguration=$hierarchyConfiguration, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, productId=$productId, rateType=$rateType, rolloverFraction=$rolloverFraction, additionalProperties=$additionalProperties}" - } + class DiscountConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cap: JsonField, + private val paymentFraction: JsonField, + private val additionalProperties: MutableMap, + ) { - class UpdatePrepaidBalanceThresholdConfiguration - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val commit: JsonField, - private val customCreditTypeId: JsonField, - private val discountConfiguration: JsonField, - private val isEnabled: JsonField, - private val paymentGateConfig: JsonField, - private val rechargeToAmount: JsonField, - private val thresholdAmount: JsonField, - private val additionalProperties: MutableMap, - ) { + @JsonCreator + private constructor( + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), + @JsonProperty("payment_fraction") + @ExcludeMissing + paymentFraction: JsonField = JsonMissing.of(), + ) : this(cap, paymentFraction, mutableMapOf()) - @JsonCreator - private constructor( - @JsonProperty("commit") @ExcludeMissing commit: JsonField = JsonMissing.of(), - @JsonProperty("custom_credit_type_id") - @ExcludeMissing - customCreditTypeId: JsonField = JsonMissing.of(), - @JsonProperty("discount_configuration") - @ExcludeMissing - discountConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("is_enabled") - @ExcludeMissing - isEnabled: JsonField = JsonMissing.of(), - @JsonProperty("payment_gate_config") - @ExcludeMissing - paymentGateConfig: JsonField = JsonMissing.of(), - @JsonProperty("recharge_to_amount") - @ExcludeMissing - rechargeToAmount: JsonField = JsonMissing.of(), - @JsonProperty("threshold_amount") - @ExcludeMissing - thresholdAmount: JsonField = JsonMissing.of(), - ) : this( - commit, - customCreditTypeId, - discountConfiguration, - isEnabled, - paymentGateConfig, - rechargeToAmount, - thresholdAmount, - mutableMapOf(), - ) + /** + * Update the discount cap. Set to null to remove an existing cap. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun commit(): Optional = commit.getOptional("commit") + /** + * The fraction of the original amount that the customer pays after applying the + * discount. Set to null to remove the discount fraction. For example, 0.85 means the + * customer pays 85% of the original amount (a 15% discount). + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun paymentFraction(): Optional = + paymentFraction.getOptional("payment_fraction") - /** - * If provided, the threshold, recharge-to amount, and the resulting threshold commit amount - * will be in terms of this credit type instead of the fiat currency. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun customCreditTypeId(): Optional = - customCreditTypeId.getOptional("custom_credit_type_id") + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun discountConfiguration(): Optional = - discountConfiguration.getOptional("discount_configuration") + /** + * Returns the raw JSON value of [paymentFraction]. + * + * Unlike [paymentFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_fraction") + @ExcludeMissing + fun _paymentFraction(): JsonField = paymentFraction - /** - * When set to false, the contract will not be evaluated against the threshold_amount. - * Toggling to true will result an immediate evaluation, regardless of prior state. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun isEnabled(): Optional = isEnabled.getOptional("is_enabled") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun paymentGateConfig(): Optional = - paymentGateConfig.getOptional("payment_gate_config") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /** - * Specify the amount the balance should be recharged to. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun rechargeToAmount(): Optional = - rechargeToAmount.getOptional("recharge_to_amount") + fun toBuilder() = Builder().from(this) - /** - * Specify the threshold amount for the contract. Each time the contract's balance lowers to - * this amount, a threshold charge will be initiated. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun thresholdAmount(): Optional = thresholdAmount.getOptional("threshold_amount") + companion object { - /** - * Returns the raw JSON value of [commit]. - * - * Unlike [commit], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("commit") @ExcludeMissing fun _commit(): JsonField = commit + /** + * Returns a mutable builder for constructing an instance of + * [DiscountConfiguration]. + */ + @JvmStatic fun builder() = Builder() + } - /** - * Returns the raw JSON value of [customCreditTypeId]. - * - * Unlike [customCreditTypeId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("custom_credit_type_id") - @ExcludeMissing - fun _customCreditTypeId(): JsonField = customCreditTypeId + /** A builder for [DiscountConfiguration]. */ + class Builder internal constructor() { - /** - * Returns the raw JSON value of [discountConfiguration]. - * - * Unlike [discountConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("discount_configuration") - @ExcludeMissing - fun _discountConfiguration(): JsonField = discountConfiguration + private var cap: JsonField = JsonMissing.of() + private var paymentFraction: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - /** - * Returns the raw JSON value of [isEnabled]. - * - * Unlike [isEnabled], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("is_enabled") @ExcludeMissing fun _isEnabled(): JsonField = isEnabled + @JvmSynthetic + internal fun from(discountConfiguration: DiscountConfiguration) = apply { + cap = discountConfiguration.cap + paymentFraction = discountConfiguration.paymentFraction + additionalProperties = discountConfiguration.additionalProperties.toMutableMap() + } - /** - * Returns the raw JSON value of [paymentGateConfig]. - * - * Unlike [paymentGateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("payment_gate_config") - @ExcludeMissing - fun _paymentGateConfig(): JsonField = paymentGateConfig + /** Update the discount cap. Set to null to remove an existing cap. */ + fun cap(cap: Cap?) = cap(JsonField.ofNullable(cap)) - /** - * Returns the raw JSON value of [rechargeToAmount]. - * - * Unlike [rechargeToAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("recharge_to_amount") - @ExcludeMissing - fun _rechargeToAmount(): JsonField = rechargeToAmount + /** Alias for calling [Builder.cap] with `cap.orElse(null)`. */ + fun cap(cap: Optional) = cap(cap.getOrNull()) - /** - * Returns the raw JSON value of [thresholdAmount]. - * - * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("threshold_amount") - @ExcludeMissing - fun _thresholdAmount(): JsonField = thresholdAmount + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * The fraction of the original amount that the customer pays after applying the + * discount. Set to null to remove the discount fraction. For example, 0.85 means + * the customer pays 85% of the original amount (a 15% discount). + */ + fun paymentFraction(paymentFraction: Double?) = + paymentFraction(JsonField.ofNullable(paymentFraction)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for [Builder.paymentFraction]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun paymentFraction(paymentFraction: Double) = + paymentFraction(paymentFraction as Double?) - fun toBuilder() = Builder().from(this) + /** + * Alias for calling [Builder.paymentFraction] with `paymentFraction.orElse(null)`. + */ + fun paymentFraction(paymentFraction: Optional) = + paymentFraction(paymentFraction.getOrNull()) - companion object { + /** + * Sets [Builder.paymentFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun paymentFraction(paymentFraction: JsonField) = apply { + this.paymentFraction = paymentFraction + } - /** - * Returns a mutable builder for constructing an instance of - * [UpdatePrepaidBalanceThresholdConfiguration]. - */ - @JvmStatic fun builder() = Builder() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** A builder for [UpdatePrepaidBalanceThresholdConfiguration]. */ - class Builder internal constructor() { + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - private var commit: JsonField = JsonMissing.of() - private var customCreditTypeId: JsonField = JsonMissing.of() - private var discountConfiguration: JsonField = JsonMissing.of() - private var isEnabled: JsonField = JsonMissing.of() - private var paymentGateConfig: JsonField = JsonMissing.of() - private var rechargeToAmount: JsonField = JsonMissing.of() - private var thresholdAmount: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - @JvmSynthetic - internal fun from( - updatePrepaidBalanceThresholdConfiguration: - UpdatePrepaidBalanceThresholdConfiguration - ) = apply { - commit = updatePrepaidBalanceThresholdConfiguration.commit - customCreditTypeId = updatePrepaidBalanceThresholdConfiguration.customCreditTypeId - discountConfiguration = - updatePrepaidBalanceThresholdConfiguration.discountConfiguration - isEnabled = updatePrepaidBalanceThresholdConfiguration.isEnabled - paymentGateConfig = updatePrepaidBalanceThresholdConfiguration.paymentGateConfig - rechargeToAmount = updatePrepaidBalanceThresholdConfiguration.rechargeToAmount - thresholdAmount = updatePrepaidBalanceThresholdConfiguration.thresholdAmount - additionalProperties = - updatePrepaidBalanceThresholdConfiguration.additionalProperties.toMutableMap() + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DiscountConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DiscountConfiguration = + DiscountConfiguration(cap, paymentFraction, additionalProperties.toMutableMap()) } - fun commit(commit: Commit) = commit(JsonField.of(commit)) + private var validated: Boolean = false /** - * Sets [Builder.commit] to an arbitrary JSON value. + * Validates that the types of all values in this object match their expected types + * recursively. * - * You should usually call [Builder.commit] with a well-typed [Commit] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. */ - fun commit(commit: JsonField) = apply { this.commit = commit } + fun validate(): DiscountConfiguration = apply { + if (validated) { + return@apply + } - /** - * If provided, the threshold, recharge-to amount, and the resulting threshold commit - * amount will be in terms of this credit type instead of the fiat currency. - */ - fun customCreditTypeId(customCreditTypeId: String?) = - customCreditTypeId(JsonField.ofNullable(customCreditTypeId)) + cap().ifPresent { it.validate() } + paymentFraction() + validated = true + } - /** - * Alias for calling [Builder.customCreditTypeId] with - * `customCreditTypeId.orElse(null)`. - */ - fun customCreditTypeId(customCreditTypeId: Optional) = - customCreditTypeId(customCreditTypeId.getOrNull()) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } /** - * Sets [Builder.customCreditTypeId] to an arbitrary JSON value. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * You should usually call [Builder.customCreditTypeId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Used for best match union deserialization. */ - fun customCreditTypeId(customCreditTypeId: JsonField) = apply { - this.customCreditTypeId = customCreditTypeId - } + @JvmSynthetic + internal fun validity(): Int = + (cap.asKnown().getOrNull()?.validity() ?: 0) + + (if (paymentFraction.asKnown().isPresent) 1 else 0) - fun discountConfiguration(discountConfiguration: DiscountConfiguration?) = - discountConfiguration(JsonField.ofNullable(discountConfiguration)) + /** Update the discount cap. Set to null to remove an existing cap. */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * Alias for calling [Builder.discountConfiguration] with - * `discountConfiguration.orElse(null)`. - */ - fun discountConfiguration(discountConfiguration: Optional) = - discountConfiguration(discountConfiguration.getOrNull()) + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) - /** - * Sets [Builder.discountConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.discountConfiguration] with a well-typed - * [DiscountConfiguration] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun discountConfiguration(discountConfiguration: JsonField) = - apply { - this.discountConfiguration = discountConfiguration - } + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") - /** - * When set to false, the contract will not be evaluated against the threshold_amount. - * Toggling to true will result an immediate evaluation, regardless of prior state. - */ - fun isEnabled(isEnabled: Boolean) = isEnabled(JsonField.of(isEnabled)) + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = + spendTrackerAlias.getRequired("spend_tracker_alias") - /** - * Sets [Builder.isEnabled] to an arbitrary JSON value. - * - * You should usually call [Builder.isEnabled] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun isEnabled(isEnabled: JsonField) = apply { this.isEnabled = isEnabled } + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount - fun paymentGateConfig(paymentGateConfig: PaymentGateConfigV2) = - paymentGateConfig(JsonField.of(paymentGateConfig)) + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias - /** - * Sets [Builder.paymentGateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.paymentGateConfig] with a well-typed - * [PaymentGateConfigV2] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun paymentGateConfig(paymentGateConfig: JsonField) = apply { - this.paymentGateConfig = paymentGateConfig - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** Specify the amount the balance should be recharged to. */ - fun rechargeToAmount(rechargeToAmount: Double) = - rechargeToAmount(JsonField.of(rechargeToAmount)) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /** - * Sets [Builder.rechargeToAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.rechargeToAmount] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun rechargeToAmount(rechargeToAmount: JsonField) = apply { - this.rechargeToAmount = rechargeToAmount - } + fun toBuilder() = Builder().from(this) - /** - * Specify the threshold amount for the contract. Each time the contract's balance - * lowers to this amount, a threshold charge will be initiated. - */ - fun thresholdAmount(thresholdAmount: Double) = - thresholdAmount(JsonField.of(thresholdAmount)) + companion object { - /** - * Sets [Builder.thresholdAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.thresholdAmount] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun thresholdAmount(thresholdAmount: JsonField) = apply { - this.thresholdAmount = thresholdAmount - } + /** + * Returns a mutable builder for constructing an instance of [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** A builder for [Cap]. */ + class Builder internal constructor() { - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** Accumulated spend ceiling above which the discount stops applying. */ + fun amount(amount: Double) = amount(JsonField.of(amount)) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } - /** - * Returns an immutable instance of [UpdatePrepaidBalanceThresholdConfiguration]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): UpdatePrepaidBalanceThresholdConfiguration = - UpdatePrepaidBalanceThresholdConfiguration( - commit, - customCreditTypeId, - discountConfiguration, - isEnabled, - paymentGateConfig, - rechargeToAmount, - thresholdAmount, - additionalProperties.toMutableMap(), - ) - } + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) - private var validated: Boolean = false + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match its - * expected type. - */ - fun validate(): UpdatePrepaidBalanceThresholdConfiguration = apply { - if (validated) { - return@apply - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - commit().ifPresent { it.validate() } - customCreditTypeId() - discountConfiguration().ifPresent { it.validate() } - isEnabled() - paymentGateConfig().ifPresent { it.validate() } - rechargeToAmount() - thresholdAmount() - validated = true - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** - * 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 = - (commit.asKnown().getOrNull()?.validity() ?: 0) + - (if (customCreditTypeId.asKnown().isPresent) 1 else 0) + - (discountConfiguration.asKnown().getOrNull()?.validity() ?: 0) + - (if (isEnabled.asKnown().isPresent) 1 else 0) + - (paymentGateConfig.asKnown().getOrNull()?.validity() ?: 0) + - (if (rechargeToAmount.asKnown().isPresent) 1 else 0) + - (if (thresholdAmount.asKnown().isPresent) 1 else 0) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - class Commit - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val description: JsonField, - private val name: JsonField, - private val priority: JsonField, - private val productId: JsonField, - private val applicableProductIds: JsonField>, - private val applicableProductTags: JsonField>, - private val specifiers: JsonField>, - private val additionalProperties: MutableMap, - ) { + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - @JsonCreator - private constructor( - @JsonProperty("description") - @ExcludeMissing - description: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("priority") - @ExcludeMissing - priority: JsonField = JsonMissing.of(), - @JsonProperty("product_id") - @ExcludeMissing - productId: JsonField = JsonMissing.of(), - @JsonProperty("applicable_product_ids") - @ExcludeMissing - applicableProductIds: JsonField> = JsonMissing.of(), - @JsonProperty("applicable_product_tags") - @ExcludeMissing - applicableProductTags: JsonField> = JsonMissing.of(), - @JsonProperty("specifiers") - @ExcludeMissing - specifiers: JsonField> = JsonMissing.of(), - ) : this( - description, - name, - priority, - productId, - applicableProductIds, - applicableProductTags, - specifiers, - mutableMapOf(), - ) + /** + * Returns an immutable instance of [Cap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } - fun toUpdateBaseThresholdCommit(): UpdateBaseThresholdCommit = - UpdateBaseThresholdCommit.builder() - .description(description) - .name(name) - .priority(priority) - .productId(productId) - .build() + private var validated: Boolean = false - /** - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun description(): Optional = description.getOptional("description") + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } - /** - * Specify the name of the line item for the threshold charge. If left blank, it will - * default to the commit product name. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun name(): Optional = name.getOptional("name") + amount() + spendTrackerAlias() + validated = true + } - /** - * The priority of the commit, used to determine drawdown order. Lower priority commits - * are consumed first. Defaults to 100 if not specified. On updates, set to null to - * clear a previously configured priority. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun priority(): Optional = priority.getOptional("priority") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } - /** - * The commit product that will be used to generate the line item for commit payment. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun productId(): Optional = productId.getOptional("product_id") + /** + * 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) - /** - * Which products the threshold commit applies to. If both applicable_product_ids and - * applicable_product_tags are not provided, the commit applies to all products. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun applicableProductIds(): Optional> = - applicableProductIds.getOptional("applicable_product_ids") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Which tags the threshold commit applies to. If both applicable_product_ids and - * applicable_product_tags are not provided, the commit applies to all products. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun applicableProductTags(): Optional> = - applicableProductTags.getOptional("applicable_product_tags") + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } - /** - * List of filters that determine what kind of customer usage draws down a commit or - * credit. A customer's usage needs to meet the condition of at least one of the - * specifiers to contribute to a commit's or credit's drawdown. This field cannot be - * used together with `applicable_product_ids` or `applicable_product_tags`. Instead, to - * target usage by product or product tag, pass those values in the body of - * `specifiers`. - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun specifiers(): Optional> = - specifiers.getOptional("specifiers") + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DiscountConfiguration && + cap == other.cap && + paymentFraction == other.paymentFraction && + additionalProperties == other.additionalProperties + } - /** - * 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 + private val hashCode: Int by lazy { + Objects.hash(cap, paymentFraction, additionalProperties) + } - /** - * Returns the raw JSON value of [priority]. - * - * Unlike [priority], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("priority") @ExcludeMissing fun _priority(): JsonField = priority + override fun hashCode(): Int = hashCode - /** - * Returns the raw JSON value of [productId]. - * - * Unlike [productId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("product_id") - @ExcludeMissing - fun _productId(): JsonField = productId + override fun toString() = + "DiscountConfiguration{cap=$cap, paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + } - /** - * Returns the raw JSON value of [applicableProductIds]. - * - * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("applicable_product_ids") - @ExcludeMissing - fun _applicableProductIds(): JsonField> = applicableProductIds + class ThresholdBalanceSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val exclude: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("exclude") + @ExcludeMissing + exclude: JsonField> = JsonMissing.of() + ) : this(exclude, mutableMapOf()) /** - * Returns the raw JSON value of [applicableProductTags]. - * - * Unlike [applicableProductTags], this method doesn't throw if the JSON field has an - * unexpected type. + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - @JsonProperty("applicable_product_tags") - @ExcludeMissing - fun _applicableProductTags(): JsonField> = applicableProductTags + fun exclude(): List = exclude.getRequired("exclude") /** - * Returns the raw JSON value of [specifiers]. + * Returns the raw JSON value of [exclude]. * - * Unlike [specifiers], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [exclude], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("specifiers") + @JsonProperty("exclude") @ExcludeMissing - fun _specifiers(): JsonField> = specifiers + fun _exclude(): JsonField> = exclude @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -34842,529 +37357,762 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Commit]. */ + /** + * Returns a mutable builder for constructing an instance of + * [ThresholdBalanceSpecifier]. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + */ @JvmStatic fun builder() = Builder() } - /** A builder for [Commit]. */ + /** A builder for [ThresholdBalanceSpecifier]. */ class Builder internal constructor() { - private var description: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var priority: JsonField = JsonMissing.of() - private var productId: JsonField = JsonMissing.of() - private var applicableProductIds: JsonField>? = null - private var applicableProductTags: JsonField>? = null - private var specifiers: JsonField>? = null + private var exclude: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(commit: Commit) = apply { - description = commit.description - name = commit.name - priority = commit.priority - productId = commit.productId - applicableProductIds = commit.applicableProductIds.map { it.toMutableList() } - applicableProductTags = commit.applicableProductTags.map { it.toMutableList() } - specifiers = commit.specifiers.map { it.toMutableList() } - additionalProperties = commit.additionalProperties.toMutableMap() + internal fun from(thresholdBalanceSpecifier: ThresholdBalanceSpecifier) = apply { + exclude = thresholdBalanceSpecifier.exclude.map { it.toMutableList() } + additionalProperties = + thresholdBalanceSpecifier.additionalProperties.toMutableMap() } - fun description(description: String) = description(JsonField.of(description)) + fun exclude(exclude: List) = exclude(JsonField.of(exclude)) /** - * Sets [Builder.description] to an arbitrary JSON value. + * Sets [Builder.exclude] to an arbitrary JSON value. * - * You should usually call [Builder.description] with a well-typed [String] value + * You should usually call [Builder.exclude] with a well-typed `List` value * instead. This method is primarily for setting the field to an undocumented or not * yet supported value. */ - fun description(description: JsonField) = apply { - this.description = description + fun exclude(exclude: JsonField>) = apply { + this.exclude = exclude.map { it.toMutableList() } } /** - * Specify the name of the line item for the threshold charge. If left blank, it - * will default to the commit product name. - */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. + * Adds a single [Exclude] to [Builder.exclude]. * - * You should usually call [Builder.name] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun name(name: JsonField) = apply { this.name = name } + fun addExclude(exclude: Exclude) = apply { + this.exclude = + (this.exclude ?: JsonField.of(mutableListOf())).also { + checkKnown("exclude", it).add(exclude) + } + } - /** - * The priority of the commit, used to determine drawdown order. Lower priority - * commits are consumed first. Defaults to 100 if not specified. On updates, set to - * null to clear a previously configured priority. - */ - fun priority(priority: Double?) = priority(JsonField.ofNullable(priority)) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Alias for [Builder.priority]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun priority(priority: Double) = priority(priority as Double?) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** Alias for calling [Builder.priority] with `priority.orElse(null)`. */ - fun priority(priority: Optional) = priority(priority.getOrNull()) + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** - * Sets [Builder.priority] to an arbitrary JSON value. - * - * You should usually call [Builder.priority] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun priority(priority: JsonField) = apply { this.priority = priority } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** - * The commit product that will be used to generate the line item for commit - * payment. - */ - fun productId(productId: String) = productId(JsonField.of(productId)) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } /** - * Sets [Builder.productId] to an arbitrary JSON value. + * Returns an immutable instance of [ThresholdBalanceSpecifier]. * - * You should usually call [Builder.productId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun productId(productId: JsonField) = apply { this.productId = productId } - - /** - * Which products the threshold commit applies to. If both applicable_product_ids - * and applicable_product_tags are not provided, the commit applies to all products. + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun applicableProductIds(applicableProductIds: List?) = - applicableProductIds(JsonField.ofNullable(applicableProductIds)) + fun build(): ThresholdBalanceSpecifier = + ThresholdBalanceSpecifier( + checkRequired("exclude", exclude).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } - /** - * Alias for calling [Builder.applicableProductIds] with - * `applicableProductIds.orElse(null)`. - */ - fun applicableProductIds(applicableProductIds: Optional>) = - applicableProductIds(applicableProductIds.getOrNull()) + private var validated: Boolean = false - /** - * Sets [Builder.applicableProductIds] to an arbitrary JSON value. - * - * You should usually call [Builder.applicableProductIds] with a well-typed - * `List` value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun applicableProductIds(applicableProductIds: JsonField>) = apply { - this.applicableProductIds = applicableProductIds.map { it.toMutableList() } + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ThresholdBalanceSpecifier = apply { + if (validated) { + return@apply } - /** - * Adds a single [String] to [applicableProductIds]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addApplicableProductId(applicableProductId: String) = apply { - applicableProductIds = - (applicableProductIds ?: JsonField.of(mutableListOf())).also { - checkKnown("applicableProductIds", it).add(applicableProductId) - } + exclude().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false } - /** - * Which tags the threshold commit applies to. If both applicable_product_ids and - * applicable_product_tags are not provided, the commit applies to all products. - */ - fun applicableProductTags(applicableProductTags: List?) = - applicableProductTags(JsonField.ofNullable(applicableProductTags)) + /** + * 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 = + (exclude.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Exclude + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val customFieldFilters: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("custom_field_filters") + @ExcludeMissing + customFieldFilters: JsonField> = JsonMissing.of() + ) : this(customFieldFilters, mutableMapOf()) /** - * Alias for calling [Builder.applicableProductTags] with - * `applicableProductTags.orElse(null)`. + * @throws MetronomeInvalidDataException 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 applicableProductTags(applicableProductTags: Optional>) = - applicableProductTags(applicableProductTags.getOrNull()) + fun customFieldFilters(): List = + customFieldFilters.getRequired("custom_field_filters") /** - * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * Returns the raw JSON value of [customFieldFilters]. * - * You should usually call [Builder.applicableProductTags] with a well-typed - * `List` value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. + * Unlike [customFieldFilters], this method doesn't throw if the JSON field has an + * unexpected type. */ - fun applicableProductTags(applicableProductTags: JsonField>) = apply { - this.applicableProductTags = applicableProductTags.map { it.toMutableList() } + @JsonProperty("custom_field_filters") + @ExcludeMissing + fun _customFieldFilters(): JsonField> = customFieldFilters + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - /** - * Adds a single [String] to [applicableProductTags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addApplicableProductTag(applicableProductTag: String) = apply { - applicableProductTags = - (applicableProductTags ?: JsonField.of(mutableListOf())).also { - checkKnown("applicableProductTags", it).add(applicableProductTag) - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Exclude]. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + */ + @JvmStatic fun builder() = Builder() } - /** - * List of filters that determine what kind of customer usage draws down a commit or - * credit. A customer's usage needs to meet the condition of at least one of the - * specifiers to contribute to a commit's or credit's drawdown. This field cannot be - * used together with `applicable_product_ids` or `applicable_product_tags`. - * Instead, to target usage by product or product tag, pass those values in the body - * of `specifiers`. - */ - fun specifiers(specifiers: List?) = - specifiers(JsonField.ofNullable(specifiers)) + /** A builder for [Exclude]. */ + class Builder internal constructor() { - /** Alias for calling [Builder.specifiers] with `specifiers.orElse(null)`. */ - fun specifiers(specifiers: Optional>) = - specifiers(specifiers.getOrNull()) + private var customFieldFilters: JsonField>? = + null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(exclude: Exclude) = apply { + customFieldFilters = exclude.customFieldFilters.map { it.toMutableList() } + additionalProperties = exclude.additionalProperties.toMutableMap() + } + + fun customFieldFilters(customFieldFilters: List) = + customFieldFilters(JsonField.of(customFieldFilters)) + + /** + * Sets [Builder.customFieldFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.customFieldFilters] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun customFieldFilters(customFieldFilters: JsonField>) = + apply { + this.customFieldFilters = customFieldFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CustomFieldFilter] to [customFieldFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCustomFieldFilter(customFieldFilter: CustomFieldFilter) = apply { + customFieldFilters = + (customFieldFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("customFieldFilters", it).add(customFieldFilter) + } + } + + 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 [Exclude]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Exclude = + Exclude( + checkRequired("customFieldFilters", customFieldFilters).map { + it.toImmutable() + }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false /** - * Sets [Builder.specifiers] to an arbitrary JSON value. + * Validates that the types of all values in this object match their expected types + * recursively. * - * You should usually call [Builder.specifiers] with a well-typed - * `List` value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. */ - fun specifiers(specifiers: JsonField>) = apply { - this.specifiers = specifiers.map { it.toMutableList() } + fun validate(): Exclude = apply { + if (validated) { + return@apply + } + + customFieldFilters().forEach { it.validate() } + validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + /** - * Adds a single [CommitSpecifierInput] to [specifiers]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Used for best match union deserialization. */ - fun addSpecifier(specifier: CommitSpecifierInput) = apply { - specifiers = - (specifiers ?: JsonField.of(mutableListOf())).also { - checkKnown("specifiers", it).add(specifier) - } - } + @JvmSynthetic + internal fun validity(): Int = + (customFieldFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + class CustomFieldFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val entity: JsonField, + private val key: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @JsonProperty("entity") + @ExcludeMissing + entity: JsonField = JsonMissing.of(), + @JsonProperty("key") + @ExcludeMissing + key: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(entity, key, value, mutableMapOf()) - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) + /** + * @throws MetronomeInvalidDataException 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 entity(): Entity = entity.getRequired("entity") + + /** + * @throws MetronomeInvalidDataException 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 key(): String = key.getRequired("key") + + /** + * @throws MetronomeInvalidDataException 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 [entity]. + * + * Unlike [entity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("entity") + @ExcludeMissing + fun _entity(): JsonField = entity + + /** + * Returns the raw JSON value of [key]. + * + * Unlike [key], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("key") @ExcludeMissing fun _key(): JsonField = key + + /** + * 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) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun toBuilder() = Builder().from(this) - /** - * Returns an immutable instance of [Commit]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Commit = - Commit( - description, - name, - priority, - productId, - (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, - (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, - (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CustomFieldFilter]. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFieldFilter]. */ + class Builder internal constructor() { + + private var entity: JsonField? = null + private var key: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customFieldFilter: CustomFieldFilter) = apply { + entity = customFieldFilter.entity + key = customFieldFilter.key + value = customFieldFilter.value + additionalProperties = + customFieldFilter.additionalProperties.toMutableMap() + } + + fun entity(entity: Entity) = entity(JsonField.of(entity)) + + /** + * Sets [Builder.entity] to an arbitrary JSON value. + * + * You should usually call [Builder.entity] with a well-typed [Entity] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun entity(entity: JsonField) = apply { this.entity = entity } + + fun key(key: String) = key(JsonField.of(key)) + + /** + * Sets [Builder.key] to an arbitrary JSON value. + * + * You should usually call [Builder.key] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun key(key: JsonField) = apply { this.key = key } + + 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 [CustomFieldFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomFieldFilter = + CustomFieldFilter( + checkRequired("entity", entity), + checkRequired("key", key), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } - private var validated: Boolean = false + private var validated: Boolean = false - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): Commit = apply { - if (validated) { - return@apply - } + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomFieldFilter = apply { + if (validated) { + return@apply + } - description() - name() - priority() - productId() - applicableProductIds() - applicableProductTags() - specifiers().ifPresent { it.forEach { it.validate() } } - validated = true - } + entity().validate() + key() + value() + validated = true + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (description.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (if (priority.asKnown().isPresent) 1 else 0) + - (if (productId.asKnown().isPresent) 1 else 0) + - (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + - (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + - (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + /** + * 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 = + (entity.asKnown().getOrNull()?.validity() ?: 0) + + (if (key.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + class Entity + @JsonCreator + private constructor(private val value: JsonField) : Enum { - return other is Commit && - description == other.description && - name == other.name && - priority == other.priority && - productId == other.productId && - applicableProductIds == other.applicableProductIds && - applicableProductTags == other.applicableProductTags && - specifiers == other.specifiers && - additionalProperties == other.additionalProperties - } + /** + * 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 - private val hashCode: Int by lazy { - Objects.hash( - description, - name, - priority, - productId, - applicableProductIds, - applicableProductTags, - specifiers, - additionalProperties, - ) - } + companion object { - override fun hashCode(): Int = hashCode + @JvmField val COMMIT = of("Commit") - override fun toString() = - "Commit{description=$description, name=$name, priority=$priority, productId=$productId, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, specifiers=$specifiers, additionalProperties=$additionalProperties}" - } + @JvmField val CONTRACT_CREDIT = of("ContractCredit") - class DiscountConfiguration - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val paymentFraction: JsonField, - private val additionalProperties: MutableMap, - ) { + @JvmField val CONTRACT_CREDIT_OR_COMMIT = of("ContractCreditOrCommit") - @JsonCreator - private constructor( - @JsonProperty("payment_fraction") - @ExcludeMissing - paymentFraction: JsonField = JsonMissing.of() - ) : this(paymentFraction, mutableMapOf()) + @JvmStatic fun of(value: String) = Entity(JsonField.of(value)) + } - /** - * The fraction of the original amount that the customer pays after applying the - * discount. Set to null to remove the discount fraction. For example, 0.85 means the - * customer pays 85% of the original amount (a 15% discount). - * - * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun paymentFraction(): Optional = - paymentFraction.getOptional("payment_fraction") + /** An enum containing [Entity]'s known values. */ + enum class Known { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + } - /** - * Returns the raw JSON value of [paymentFraction]. - * - * Unlike [paymentFraction], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("payment_fraction") - @ExcludeMissing - fun _paymentFraction(): JsonField = paymentFraction + /** + * An enum containing [Entity]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Entity] 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 { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + /** + * An enum member indicating that [Entity] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * 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) { + COMMIT -> Value.COMMIT + CONTRACT_CREDIT -> Value.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Value.CONTRACT_CREDIT_OR_COMMIT + else -> Value._UNKNOWN + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + COMMIT -> Known.COMMIT + CONTRACT_CREDIT -> Known.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Known.CONTRACT_CREDIT_OR_COMMIT + else -> + throw MetronomeInvalidDataException("Unknown Entity: $value") + } - fun toBuilder() = Builder().from(this) + /** + * 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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } - companion object { + private var validated: Boolean = false - /** - * Returns a mutable builder for constructing an instance of - * [DiscountConfiguration]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Entity = apply { + if (validated) { + return@apply + } - /** A builder for [DiscountConfiguration]. */ - class Builder internal constructor() { + known() + validated = true + } - private var paymentFraction: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } - @JvmSynthetic - internal fun from(discountConfiguration: DiscountConfiguration) = apply { - paymentFraction = discountConfiguration.paymentFraction - additionalProperties = discountConfiguration.additionalProperties.toMutableMap() - } + /** + * 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 - /** - * The fraction of the original amount that the customer pays after applying the - * discount. Set to null to remove the discount fraction. For example, 0.85 means - * the customer pays 85% of the original amount (a 15% discount). - */ - fun paymentFraction(paymentFraction: Double?) = - paymentFraction(JsonField.ofNullable(paymentFraction)) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Alias for [Builder.paymentFraction]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun paymentFraction(paymentFraction: Double) = - paymentFraction(paymentFraction as Double?) + return other is Entity && value == other.value + } - /** - * Alias for calling [Builder.paymentFraction] with `paymentFraction.orElse(null)`. - */ - fun paymentFraction(paymentFraction: Optional) = - paymentFraction(paymentFraction.getOrNull()) + override fun hashCode() = value.hashCode() - /** - * Sets [Builder.paymentFraction] to an arbitrary JSON value. - * - * You should usually call [Builder.paymentFraction] with a well-typed [Double] - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun paymentFraction(paymentFraction: JsonField) = apply { - this.paymentFraction = paymentFraction - } + override fun toString() = value.toString() + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + return other is CustomFieldFilter && + entity == other.entity && + key == other.key && + value == other.value && + additionalProperties == other.additionalProperties + } - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) + private val hashCode: Int by lazy { + Objects.hash(entity, key, value, additionalProperties) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + override fun hashCode(): Int = hashCode - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) + override fun toString() = + "CustomFieldFilter{entity=$entity, key=$key, value=$value, additionalProperties=$additionalProperties}" } - /** - * Returns an immutable instance of [DiscountConfiguration]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): DiscountConfiguration = - DiscountConfiguration(paymentFraction, additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): DiscountConfiguration = apply { - if (validated) { - return@apply + return other is Exclude && + customFieldFilters == other.customFieldFilters && + additionalProperties == other.additionalProperties } - paymentFraction() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false + private val hashCode: Int by lazy { + Objects.hash(customFieldFilters, additionalProperties) } - /** - * 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 (paymentFraction.asKnown().isPresent) 1 else 0) + override fun hashCode(): Int = hashCode + + override fun toString() = + "Exclude{customFieldFilters=$customFieldFilters, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is DiscountConfiguration && - paymentFraction == other.paymentFraction && + return other is ThresholdBalanceSpecifier && + exclude == other.exclude && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { - Objects.hash(paymentFraction, additionalProperties) - } + private val hashCode: Int by lazy { Objects.hash(exclude, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "DiscountConfiguration{paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + "ThresholdBalanceSpecifier{exclude=$exclude, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -35380,6 +38128,7 @@ private constructor( paymentGateConfig == other.paymentGateConfig && rechargeToAmount == other.rechargeToAmount && thresholdAmount == other.thresholdAmount && + thresholdBalanceSpecifiers == other.thresholdBalanceSpecifiers && additionalProperties == other.additionalProperties } @@ -35392,6 +38141,7 @@ private constructor( paymentGateConfig, rechargeToAmount, thresholdAmount, + thresholdBalanceSpecifiers, additionalProperties, ) } @@ -35399,7 +38149,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "UpdatePrepaidBalanceThresholdConfiguration{commit=$commit, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" + "UpdatePrepaidBalanceThresholdConfiguration{commit=$commit, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, thresholdBalanceSpecifiers=$thresholdBalanceSpecifiers, additionalProperties=$additionalProperties}" } class UpdateRecurringCommit @@ -38626,16 +41376,26 @@ private constructor( class DiscountConfiguration @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val cap: JsonField, private val paymentFraction: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), @JsonProperty("payment_fraction") @ExcludeMissing - paymentFraction: JsonField = JsonMissing.of() - ) : this(paymentFraction, mutableMapOf()) + paymentFraction: JsonField = JsonMissing.of(), + ) : this(cap, paymentFraction, mutableMapOf()) + + /** + * Update the discount cap. Set to null to remove an existing cap. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") /** * The fraction of the original amount that the customer pays after applying the @@ -38648,6 +41408,13 @@ private constructor( fun paymentFraction(): Optional = paymentFraction.getOptional("payment_fraction") + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + /** * Returns the raw JSON value of [paymentFraction]. * @@ -38682,15 +41449,32 @@ private constructor( /** A builder for [DiscountConfiguration]. */ class Builder internal constructor() { + private var cap: JsonField = JsonMissing.of() private var paymentFraction: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(discountConfiguration: DiscountConfiguration) = apply { + cap = discountConfiguration.cap paymentFraction = discountConfiguration.paymentFraction additionalProperties = discountConfiguration.additionalProperties.toMutableMap() } + /** Update the discount cap. Set to null to remove an existing cap. */ + fun cap(cap: Cap?) = cap(JsonField.ofNullable(cap)) + + /** Alias for calling [Builder.cap] with `cap.orElse(null)`. */ + fun cap(cap: Optional) = cap(cap.getOrNull()) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + /** * The fraction of the original amount that the customer pays after applying the * discount. Set to null to remove the discount fraction. For example, 0.85 means @@ -38752,7 +41536,7 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): DiscountConfiguration = - DiscountConfiguration(paymentFraction, additionalProperties.toMutableMap()) + DiscountConfiguration(cap, paymentFraction, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -38772,6 +41556,7 @@ private constructor( return@apply } + cap().ifPresent { it.validate() } paymentFraction() validated = true } @@ -38791,7 +41576,237 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = (if (paymentFraction.asKnown().isPresent) 1 else 0) + internal fun validity(): Int = + (cap.asKnown().getOrNull()?.validity() ?: 0) + + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + /** Update the discount cap. Set to null to remove an existing cap. */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = + spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** Accumulated spend ceiling above which the discount stops applying. */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -38799,18 +41814,19 @@ private constructor( } return other is DiscountConfiguration && + cap == other.cap && paymentFraction == other.paymentFraction && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(paymentFraction, additionalProperties) + Objects.hash(cap, paymentFraction, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "DiscountConfiguration{paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + "DiscountConfiguration{cap=$cap, paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractEditResponse.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractEditResponse.kt index 6b705242..05107970 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractEditResponse.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractEditResponse.kt @@ -6,41 +6,59 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.metronome.api.core.Enum import com.metronome.api.core.ExcludeMissing import com.metronome.api.core.JsonField import com.metronome.api.core.JsonMissing import com.metronome.api.core.JsonValue +import com.metronome.api.core.checkKnown import com.metronome.api.core.checkRequired +import com.metronome.api.core.toImmutable import com.metronome.api.errors.MetronomeInvalidDataException -import com.metronome.api.models.Id +import com.metronome.api.models.CommitHierarchyConfiguration +import com.metronome.api.models.CommitSpecifier +import com.metronome.api.models.CommitSpecifierInput +import com.metronome.api.models.CreditTypeData +import com.metronome.api.models.Discount +import com.metronome.api.models.OverrideTier +import com.metronome.api.models.PaymentGateConfigV2 +import com.metronome.api.models.PrepaidBalanceThresholdConfigurationV2 +import com.metronome.api.models.ProService +import com.metronome.api.models.RecurringCommitSubscriptionConfig +import com.metronome.api.models.ScheduleDuration +import com.metronome.api.models.SchedulePointInTime +import com.metronome.api.models.SpendThresholdConfigurationV2 +import com.metronome.api.models.UpdateBaseThresholdCommit +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class ContractEditResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val data: JsonField, + private val data: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of() + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of() ) : this(data, mutableMapOf()) /** * @throws MetronomeInvalidDataException 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 data(): Id = data.getRequired("data") + fun data(): Data = data.getRequired("data") /** * 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 + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -70,7 +88,7 @@ private constructor( /** A builder for [ContractEditResponse]. */ class Builder internal constructor() { - private var data: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -79,15 +97,15 @@ private constructor( additionalProperties = contractEditResponse.additionalProperties.toMutableMap() } - fun data(data: Id) = data(JsonField.of(data)) + fun data(data: Data) = data(JsonField.of(data)) /** * Sets [Builder.data] to an arbitrary JSON value. * - * You should usually call [Builder.data] with a well-typed [Id] value instead. This method - * is primarily for setting the field to an undocumented or not yet supported 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 data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -158,6 +176,36018 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = (data.asKnown().getOrNull()?.validity() ?: 0) + class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val edit: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("edit") @ExcludeMissing edit: JsonField = JsonMissing.of(), + ) : this(id, edit, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun edit(): Optional = edit.getOptional("edit") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [edit]. + * + * Unlike [edit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("edit") @ExcludeMissing fun _edit(): JsonField = edit + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Data]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var edit: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + id = data.id + edit = data.edit + additionalProperties = data.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun edit(edit: Edit) = edit(JsonField.of(edit)) + + /** + * Sets [Builder.edit] to an arbitrary JSON value. + * + * You should usually call [Builder.edit] with a well-typed [Edit] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun edit(edit: JsonField) = apply { this.edit = edit } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Data = + Data(checkRequired("id", id), edit, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Data = apply { + if (validated) { + return@apply + } + + id() + edit().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + (edit.asKnown().getOrNull()?.validity() ?: 0) + + class Edit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val addCommits: JsonField>, + private val addCredits: JsonField>, + private val addDiscounts: JsonField>, + private val addOverrides: JsonField>, + private val addPrepaidBalanceThresholdConfiguration: + JsonField, + private val addProServices: JsonField>, + private val addRecurringCommits: JsonField>, + private val addRecurringCredits: JsonField>, + private val addResellerRoyalties: JsonField>, + private val addScheduledCharges: JsonField>, + private val addSpendThresholdConfiguration: JsonField, + private val addSubscriptions: JsonField>, + private val addUsageFilters: JsonField>, + private val archiveCommits: JsonField>, + private val archiveCredits: JsonField>, + private val archiveScheduledCharges: JsonField>, + private val removeOverrides: JsonField>, + private val timestamp: JsonField, + private val uniquenessKey: JsonField, + private val updateCommits: JsonField>, + private val updateContractEndDate: JsonField, + private val updateContractName: JsonField, + private val updateCredits: JsonField>, + private val updateDiscounts: JsonField>, + private val updatePrepaidBalanceThresholdConfiguration: + JsonField, + private val updateRecurringCommits: JsonField>, + private val updateRecurringCredits: JsonField>, + private val updateRefundInvoices: JsonField>, + private val updateScheduledCharges: JsonField>, + private val updateSpendThresholdConfiguration: + JsonField, + private val updateSubscriptions: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("add_commits") + @ExcludeMissing + addCommits: JsonField> = JsonMissing.of(), + @JsonProperty("add_credits") + @ExcludeMissing + addCredits: JsonField> = JsonMissing.of(), + @JsonProperty("add_discounts") + @ExcludeMissing + addDiscounts: JsonField> = JsonMissing.of(), + @JsonProperty("add_overrides") + @ExcludeMissing + addOverrides: JsonField> = JsonMissing.of(), + @JsonProperty("add_prepaid_balance_threshold_configuration") + @ExcludeMissing + addPrepaidBalanceThresholdConfiguration: + JsonField = + JsonMissing.of(), + @JsonProperty("add_pro_services") + @ExcludeMissing + addProServices: JsonField> = JsonMissing.of(), + @JsonProperty("add_recurring_commits") + @ExcludeMissing + addRecurringCommits: JsonField> = JsonMissing.of(), + @JsonProperty("add_recurring_credits") + @ExcludeMissing + addRecurringCredits: JsonField> = JsonMissing.of(), + @JsonProperty("add_reseller_royalties") + @ExcludeMissing + addResellerRoyalties: JsonField> = JsonMissing.of(), + @JsonProperty("add_scheduled_charges") + @ExcludeMissing + addScheduledCharges: JsonField> = JsonMissing.of(), + @JsonProperty("add_spend_threshold_configuration") + @ExcludeMissing + addSpendThresholdConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("add_subscriptions") + @ExcludeMissing + addSubscriptions: JsonField> = JsonMissing.of(), + @JsonProperty("add_usage_filters") + @ExcludeMissing + addUsageFilters: JsonField> = JsonMissing.of(), + @JsonProperty("archive_commits") + @ExcludeMissing + archiveCommits: JsonField> = JsonMissing.of(), + @JsonProperty("archive_credits") + @ExcludeMissing + archiveCredits: JsonField> = JsonMissing.of(), + @JsonProperty("archive_scheduled_charges") + @ExcludeMissing + archiveScheduledCharges: JsonField> = JsonMissing.of(), + @JsonProperty("remove_overrides") + @ExcludeMissing + removeOverrides: JsonField> = JsonMissing.of(), + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("uniqueness_key") + @ExcludeMissing + uniquenessKey: JsonField = JsonMissing.of(), + @JsonProperty("update_commits") + @ExcludeMissing + updateCommits: JsonField> = JsonMissing.of(), + @JsonProperty("update_contract_end_date") + @ExcludeMissing + updateContractEndDate: JsonField = JsonMissing.of(), + @JsonProperty("update_contract_name") + @ExcludeMissing + updateContractName: JsonField = JsonMissing.of(), + @JsonProperty("update_credits") + @ExcludeMissing + updateCredits: JsonField> = JsonMissing.of(), + @JsonProperty("update_discounts") + @ExcludeMissing + updateDiscounts: JsonField> = JsonMissing.of(), + @JsonProperty("update_prepaid_balance_threshold_configuration") + @ExcludeMissing + updatePrepaidBalanceThresholdConfiguration: + JsonField = + JsonMissing.of(), + @JsonProperty("update_recurring_commits") + @ExcludeMissing + updateRecurringCommits: JsonField> = JsonMissing.of(), + @JsonProperty("update_recurring_credits") + @ExcludeMissing + updateRecurringCredits: JsonField> = JsonMissing.of(), + @JsonProperty("update_refund_invoices") + @ExcludeMissing + updateRefundInvoices: JsonField> = JsonMissing.of(), + @JsonProperty("update_scheduled_charges") + @ExcludeMissing + updateScheduledCharges: JsonField> = JsonMissing.of(), + @JsonProperty("update_spend_threshold_configuration") + @ExcludeMissing + updateSpendThresholdConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("update_subscriptions") + @ExcludeMissing + updateSubscriptions: JsonField> = JsonMissing.of(), + ) : this( + id, + addCommits, + addCredits, + addDiscounts, + addOverrides, + addPrepaidBalanceThresholdConfiguration, + addProServices, + addRecurringCommits, + addRecurringCredits, + addResellerRoyalties, + addScheduledCharges, + addSpendThresholdConfiguration, + addSubscriptions, + addUsageFilters, + archiveCommits, + archiveCredits, + archiveScheduledCharges, + removeOverrides, + timestamp, + uniquenessKey, + updateCommits, + updateContractEndDate, + updateContractName, + updateCredits, + updateDiscounts, + updatePrepaidBalanceThresholdConfiguration, + updateRecurringCommits, + updateRecurringCredits, + updateRefundInvoices, + updateScheduledCharges, + updateSpendThresholdConfiguration, + updateSubscriptions, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addCommits(): Optional> = addCommits.getOptional("add_commits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addCredits(): Optional> = addCredits.getOptional("add_credits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addDiscounts(): Optional> = addDiscounts.getOptional("add_discounts") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addOverrides(): Optional> = + addOverrides.getOptional("add_overrides") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addPrepaidBalanceThresholdConfiguration(): + Optional = + addPrepaidBalanceThresholdConfiguration.getOptional( + "add_prepaid_balance_threshold_configuration" + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addProServices(): Optional> = + addProServices.getOptional("add_pro_services") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addRecurringCommits(): Optional> = + addRecurringCommits.getOptional("add_recurring_commits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addRecurringCredits(): Optional> = + addRecurringCredits.getOptional("add_recurring_credits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addResellerRoyalties(): Optional> = + addResellerRoyalties.getOptional("add_reseller_royalties") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addScheduledCharges(): Optional> = + addScheduledCharges.getOptional("add_scheduled_charges") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addSpendThresholdConfiguration(): Optional = + addSpendThresholdConfiguration.getOptional("add_spend_threshold_configuration") + + /** + * List of subscriptions on the contract. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addSubscriptions(): Optional> = + addSubscriptions.getOptional("add_subscriptions") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun addUsageFilters(): Optional> = + addUsageFilters.getOptional("add_usage_filters") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun archiveCommits(): Optional> = + archiveCommits.getOptional("archive_commits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun archiveCredits(): Optional> = + archiveCredits.getOptional("archive_credits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun archiveScheduledCharges(): Optional> = + archiveScheduledCharges.getOptional("archive_scheduled_charges") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun removeOverrides(): Optional> = + removeOverrides.getOptional("remove_overrides") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun timestamp(): Optional = timestamp.getOptional("timestamp") + + /** + * Prevents the creation of duplicates. If a request to create a record is made with a + * previously used uniqueness key, a new record will not be created and the request will + * fail with a 409 error. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun uniquenessKey(): Optional = uniquenessKey.getOptional("uniqueness_key") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateCommits(): Optional> = + updateCommits.getOptional("update_commits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateContractEndDate(): Optional = + updateContractEndDate.getOptional("update_contract_end_date") + + /** + * Value to update the contract name to. If not provided, the contract name will remain + * unchanged. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateContractName(): Optional = + updateContractName.getOptional("update_contract_name") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateCredits(): Optional> = + updateCredits.getOptional("update_credits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateDiscounts(): Optional> = + updateDiscounts.getOptional("update_discounts") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updatePrepaidBalanceThresholdConfiguration(): + Optional = + updatePrepaidBalanceThresholdConfiguration.getOptional( + "update_prepaid_balance_threshold_configuration" + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateRecurringCommits(): Optional> = + updateRecurringCommits.getOptional("update_recurring_commits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateRecurringCredits(): Optional> = + updateRecurringCredits.getOptional("update_recurring_credits") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateRefundInvoices(): Optional> = + updateRefundInvoices.getOptional("update_refund_invoices") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateScheduledCharges(): Optional> = + updateScheduledCharges.getOptional("update_scheduled_charges") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateSpendThresholdConfiguration(): Optional = + updateSpendThresholdConfiguration.getOptional( + "update_spend_threshold_configuration" + ) + + /** + * Optional list of subscriptions to update. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun updateSubscriptions(): Optional> = + updateSubscriptions.getOptional("update_subscriptions") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [addCommits]. + * + * Unlike [addCommits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("add_commits") + @ExcludeMissing + fun _addCommits(): JsonField> = addCommits + + /** + * Returns the raw JSON value of [addCredits]. + * + * Unlike [addCredits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("add_credits") + @ExcludeMissing + fun _addCredits(): JsonField> = addCredits + + /** + * Returns the raw JSON value of [addDiscounts]. + * + * Unlike [addDiscounts], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("add_discounts") + @ExcludeMissing + fun _addDiscounts(): JsonField> = addDiscounts + + /** + * Returns the raw JSON value of [addOverrides]. + * + * Unlike [addOverrides], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("add_overrides") + @ExcludeMissing + fun _addOverrides(): JsonField> = addOverrides + + /** + * Returns the raw JSON value of [addPrepaidBalanceThresholdConfiguration]. + * + * Unlike [addPrepaidBalanceThresholdConfiguration], this method doesn't throw if the + * JSON field has an unexpected type. + */ + @JsonProperty("add_prepaid_balance_threshold_configuration") + @ExcludeMissing + fun _addPrepaidBalanceThresholdConfiguration(): + JsonField = + addPrepaidBalanceThresholdConfiguration + + /** + * Returns the raw JSON value of [addProServices]. + * + * Unlike [addProServices], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_pro_services") + @ExcludeMissing + fun _addProServices(): JsonField> = addProServices + + /** + * Returns the raw JSON value of [addRecurringCommits]. + * + * Unlike [addRecurringCommits], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_recurring_commits") + @ExcludeMissing + fun _addRecurringCommits(): JsonField> = addRecurringCommits + + /** + * Returns the raw JSON value of [addRecurringCredits]. + * + * Unlike [addRecurringCredits], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_recurring_credits") + @ExcludeMissing + fun _addRecurringCredits(): JsonField> = addRecurringCredits + + /** + * Returns the raw JSON value of [addResellerRoyalties]. + * + * Unlike [addResellerRoyalties], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_reseller_royalties") + @ExcludeMissing + fun _addResellerRoyalties(): JsonField> = addResellerRoyalties + + /** + * Returns the raw JSON value of [addScheduledCharges]. + * + * Unlike [addScheduledCharges], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_scheduled_charges") + @ExcludeMissing + fun _addScheduledCharges(): JsonField> = addScheduledCharges + + /** + * Returns the raw JSON value of [addSpendThresholdConfiguration]. + * + * Unlike [addSpendThresholdConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("add_spend_threshold_configuration") + @ExcludeMissing + fun _addSpendThresholdConfiguration(): JsonField = + addSpendThresholdConfiguration + + /** + * Returns the raw JSON value of [addSubscriptions]. + * + * Unlike [addSubscriptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_subscriptions") + @ExcludeMissing + fun _addSubscriptions(): JsonField> = addSubscriptions + + /** + * Returns the raw JSON value of [addUsageFilters]. + * + * Unlike [addUsageFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_usage_filters") + @ExcludeMissing + fun _addUsageFilters(): JsonField> = addUsageFilters + + /** + * Returns the raw JSON value of [archiveCommits]. + * + * Unlike [archiveCommits], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("archive_commits") + @ExcludeMissing + fun _archiveCommits(): JsonField> = archiveCommits + + /** + * Returns the raw JSON value of [archiveCredits]. + * + * Unlike [archiveCredits], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("archive_credits") + @ExcludeMissing + fun _archiveCredits(): JsonField> = archiveCredits + + /** + * Returns the raw JSON value of [archiveScheduledCharges]. + * + * Unlike [archiveScheduledCharges], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("archive_scheduled_charges") + @ExcludeMissing + fun _archiveScheduledCharges(): JsonField> = + archiveScheduledCharges + + /** + * Returns the raw JSON value of [removeOverrides]. + * + * Unlike [removeOverrides], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("remove_overrides") + @ExcludeMissing + fun _removeOverrides(): JsonField> = removeOverrides + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [uniquenessKey]. + * + * Unlike [uniquenessKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("uniqueness_key") + @ExcludeMissing + fun _uniquenessKey(): JsonField = uniquenessKey + + /** + * Returns the raw JSON value of [updateCommits]. + * + * Unlike [updateCommits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("update_commits") + @ExcludeMissing + fun _updateCommits(): JsonField> = updateCommits + + /** + * Returns the raw JSON value of [updateContractEndDate]. + * + * Unlike [updateContractEndDate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_contract_end_date") + @ExcludeMissing + fun _updateContractEndDate(): JsonField = updateContractEndDate + + /** + * Returns the raw JSON value of [updateContractName]. + * + * Unlike [updateContractName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_contract_name") + @ExcludeMissing + fun _updateContractName(): JsonField = updateContractName + + /** + * Returns the raw JSON value of [updateCredits]. + * + * Unlike [updateCredits], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("update_credits") + @ExcludeMissing + fun _updateCredits(): JsonField> = updateCredits + + /** + * Returns the raw JSON value of [updateDiscounts]. + * + * Unlike [updateDiscounts], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_discounts") + @ExcludeMissing + fun _updateDiscounts(): JsonField> = updateDiscounts + + /** + * Returns the raw JSON value of [updatePrepaidBalanceThresholdConfiguration]. + * + * Unlike [updatePrepaidBalanceThresholdConfiguration], this method doesn't throw if the + * JSON field has an unexpected type. + */ + @JsonProperty("update_prepaid_balance_threshold_configuration") + @ExcludeMissing + fun _updatePrepaidBalanceThresholdConfiguration(): + JsonField = + updatePrepaidBalanceThresholdConfiguration + + /** + * Returns the raw JSON value of [updateRecurringCommits]. + * + * Unlike [updateRecurringCommits], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_recurring_commits") + @ExcludeMissing + fun _updateRecurringCommits(): JsonField> = + updateRecurringCommits + + /** + * Returns the raw JSON value of [updateRecurringCredits]. + * + * Unlike [updateRecurringCredits], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_recurring_credits") + @ExcludeMissing + fun _updateRecurringCredits(): JsonField> = + updateRecurringCredits + + /** + * Returns the raw JSON value of [updateRefundInvoices]. + * + * Unlike [updateRefundInvoices], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_refund_invoices") + @ExcludeMissing + fun _updateRefundInvoices(): JsonField> = updateRefundInvoices + + /** + * Returns the raw JSON value of [updateScheduledCharges]. + * + * Unlike [updateScheduledCharges], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_scheduled_charges") + @ExcludeMissing + fun _updateScheduledCharges(): JsonField> = + updateScheduledCharges + + /** + * Returns the raw JSON value of [updateSpendThresholdConfiguration]. + * + * Unlike [updateSpendThresholdConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("update_spend_threshold_configuration") + @ExcludeMissing + fun _updateSpendThresholdConfiguration(): JsonField = + updateSpendThresholdConfiguration + + /** + * Returns the raw JSON value of [updateSubscriptions]. + * + * Unlike [updateSubscriptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("update_subscriptions") + @ExcludeMissing + fun _updateSubscriptions(): JsonField> = updateSubscriptions + + @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 [Edit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Edit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var addCommits: JsonField>? = null + private var addCredits: JsonField>? = null + private var addDiscounts: JsonField>? = null + private var addOverrides: JsonField>? = null + private var addPrepaidBalanceThresholdConfiguration: + JsonField = + JsonMissing.of() + private var addProServices: JsonField>? = null + private var addRecurringCommits: JsonField>? = null + private var addRecurringCredits: JsonField>? = null + private var addResellerRoyalties: JsonField>? = null + private var addScheduledCharges: JsonField>? = null + private var addSpendThresholdConfiguration: + JsonField = + JsonMissing.of() + private var addSubscriptions: JsonField>? = null + private var addUsageFilters: JsonField>? = null + private var archiveCommits: JsonField>? = null + private var archiveCredits: JsonField>? = null + private var archiveScheduledCharges: + JsonField>? = + null + private var removeOverrides: JsonField>? = null + private var timestamp: JsonField = JsonMissing.of() + private var uniquenessKey: JsonField = JsonMissing.of() + private var updateCommits: JsonField>? = null + private var updateContractEndDate: JsonField = JsonMissing.of() + private var updateContractName: JsonField = JsonMissing.of() + private var updateCredits: JsonField>? = null + private var updateDiscounts: JsonField>? = null + private var updatePrepaidBalanceThresholdConfiguration: + JsonField = + JsonMissing.of() + private var updateRecurringCommits: JsonField>? = + null + private var updateRecurringCredits: JsonField>? = + null + private var updateRefundInvoices: JsonField>? = + null + private var updateScheduledCharges: JsonField>? = + null + private var updateSpendThresholdConfiguration: + JsonField = + JsonMissing.of() + private var updateSubscriptions: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(edit: Edit) = apply { + id = edit.id + addCommits = edit.addCommits.map { it.toMutableList() } + addCredits = edit.addCredits.map { it.toMutableList() } + addDiscounts = edit.addDiscounts.map { it.toMutableList() } + addOverrides = edit.addOverrides.map { it.toMutableList() } + addPrepaidBalanceThresholdConfiguration = + edit.addPrepaidBalanceThresholdConfiguration + addProServices = edit.addProServices.map { it.toMutableList() } + addRecurringCommits = edit.addRecurringCommits.map { it.toMutableList() } + addRecurringCredits = edit.addRecurringCredits.map { it.toMutableList() } + addResellerRoyalties = edit.addResellerRoyalties.map { it.toMutableList() } + addScheduledCharges = edit.addScheduledCharges.map { it.toMutableList() } + addSpendThresholdConfiguration = edit.addSpendThresholdConfiguration + addSubscriptions = edit.addSubscriptions.map { it.toMutableList() } + addUsageFilters = edit.addUsageFilters.map { it.toMutableList() } + archiveCommits = edit.archiveCommits.map { it.toMutableList() } + archiveCredits = edit.archiveCredits.map { it.toMutableList() } + archiveScheduledCharges = + edit.archiveScheduledCharges.map { it.toMutableList() } + removeOverrides = edit.removeOverrides.map { it.toMutableList() } + timestamp = edit.timestamp + uniquenessKey = edit.uniquenessKey + updateCommits = edit.updateCommits.map { it.toMutableList() } + updateContractEndDate = edit.updateContractEndDate + updateContractName = edit.updateContractName + updateCredits = edit.updateCredits.map { it.toMutableList() } + updateDiscounts = edit.updateDiscounts.map { it.toMutableList() } + updatePrepaidBalanceThresholdConfiguration = + edit.updatePrepaidBalanceThresholdConfiguration + updateRecurringCommits = edit.updateRecurringCommits.map { it.toMutableList() } + updateRecurringCredits = edit.updateRecurringCredits.map { it.toMutableList() } + updateRefundInvoices = edit.updateRefundInvoices.map { it.toMutableList() } + updateScheduledCharges = edit.updateScheduledCharges.map { it.toMutableList() } + updateSpendThresholdConfiguration = edit.updateSpendThresholdConfiguration + updateSubscriptions = edit.updateSubscriptions.map { it.toMutableList() } + additionalProperties = edit.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 addCommits(addCommits: List) = addCommits(JsonField.of(addCommits)) + + /** + * Sets [Builder.addCommits] to an arbitrary JSON value. + * + * You should usually call [Builder.addCommits] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun addCommits(addCommits: JsonField>) = apply { + this.addCommits = addCommits.map { it.toMutableList() } + } + + /** + * Adds a single [AddCommit] to [addCommits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddCommit(addCommit: AddCommit) = apply { + addCommits = + (addCommits ?: JsonField.of(mutableListOf())).also { + checkKnown("addCommits", it).add(addCommit) + } + } + + fun addCredits(addCredits: List) = addCredits(JsonField.of(addCredits)) + + /** + * Sets [Builder.addCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.addCredits] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun addCredits(addCredits: JsonField>) = apply { + this.addCredits = addCredits.map { it.toMutableList() } + } + + /** + * Adds a single [AddCredit] to [addCredits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddCredit(addCredit: AddCredit) = apply { + addCredits = + (addCredits ?: JsonField.of(mutableListOf())).also { + checkKnown("addCredits", it).add(addCredit) + } + } + + fun addDiscounts(addDiscounts: List) = + addDiscounts(JsonField.of(addDiscounts)) + + /** + * Sets [Builder.addDiscounts] to an arbitrary JSON value. + * + * You should usually call [Builder.addDiscounts] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun addDiscounts(addDiscounts: JsonField>) = apply { + this.addDiscounts = addDiscounts.map { it.toMutableList() } + } + + /** + * Adds a single [Discount] to [addDiscounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddDiscount(addDiscount: Discount) = apply { + addDiscounts = + (addDiscounts ?: JsonField.of(mutableListOf())).also { + checkKnown("addDiscounts", it).add(addDiscount) + } + } + + fun addOverrides(addOverrides: List) = + addOverrides(JsonField.of(addOverrides)) + + /** + * Sets [Builder.addOverrides] to an arbitrary JSON value. + * + * You should usually call [Builder.addOverrides] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun addOverrides(addOverrides: JsonField>) = apply { + this.addOverrides = addOverrides.map { it.toMutableList() } + } + + /** + * Adds a single [AddOverride] to [addOverrides]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddOverride(addOverride: AddOverride) = apply { + addOverrides = + (addOverrides ?: JsonField.of(mutableListOf())).also { + checkKnown("addOverrides", it).add(addOverride) + } + } + + fun addPrepaidBalanceThresholdConfiguration( + addPrepaidBalanceThresholdConfiguration: PrepaidBalanceThresholdConfigurationV2 + ) = + addPrepaidBalanceThresholdConfiguration( + JsonField.of(addPrepaidBalanceThresholdConfiguration) + ) + + /** + * Sets [Builder.addPrepaidBalanceThresholdConfiguration] to an arbitrary JSON + * value. + * + * You should usually call [Builder.addPrepaidBalanceThresholdConfiguration] with a + * well-typed [PrepaidBalanceThresholdConfigurationV2] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun addPrepaidBalanceThresholdConfiguration( + addPrepaidBalanceThresholdConfiguration: + JsonField + ) = apply { + this.addPrepaidBalanceThresholdConfiguration = + addPrepaidBalanceThresholdConfiguration + } + + fun addProServices(addProServices: List) = + addProServices(JsonField.of(addProServices)) + + /** + * Sets [Builder.addProServices] to an arbitrary JSON value. + * + * You should usually call [Builder.addProServices] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun addProServices(addProServices: JsonField>) = apply { + this.addProServices = addProServices.map { it.toMutableList() } + } + + /** + * Adds a single [ProService] to [addProServices]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddProService(addProService: ProService) = apply { + addProServices = + (addProServices ?: JsonField.of(mutableListOf())).also { + checkKnown("addProServices", it).add(addProService) + } + } + + fun addRecurringCommits(addRecurringCommits: List) = + addRecurringCommits(JsonField.of(addRecurringCommits)) + + /** + * Sets [Builder.addRecurringCommits] to an arbitrary JSON value. + * + * You should usually call [Builder.addRecurringCommits] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun addRecurringCommits(addRecurringCommits: JsonField>) = + apply { + this.addRecurringCommits = addRecurringCommits.map { it.toMutableList() } + } + + /** + * Adds a single [AddRecurringCommit] to [addRecurringCommits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddRecurringCommit(addRecurringCommit: AddRecurringCommit) = apply { + addRecurringCommits = + (addRecurringCommits ?: JsonField.of(mutableListOf())).also { + checkKnown("addRecurringCommits", it).add(addRecurringCommit) + } + } + + fun addRecurringCredits(addRecurringCredits: List) = + addRecurringCredits(JsonField.of(addRecurringCredits)) + + /** + * Sets [Builder.addRecurringCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.addRecurringCredits] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun addRecurringCredits(addRecurringCredits: JsonField>) = + apply { + this.addRecurringCredits = addRecurringCredits.map { it.toMutableList() } + } + + /** + * Adds a single [AddRecurringCredit] to [addRecurringCredits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddRecurringCredit(addRecurringCredit: AddRecurringCredit) = apply { + addRecurringCredits = + (addRecurringCredits ?: JsonField.of(mutableListOf())).also { + checkKnown("addRecurringCredits", it).add(addRecurringCredit) + } + } + + fun addResellerRoyalties(addResellerRoyalties: List) = + addResellerRoyalties(JsonField.of(addResellerRoyalties)) + + /** + * Sets [Builder.addResellerRoyalties] to an arbitrary JSON value. + * + * You should usually call [Builder.addResellerRoyalties] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun addResellerRoyalties( + addResellerRoyalties: JsonField> + ) = apply { + this.addResellerRoyalties = addResellerRoyalties.map { it.toMutableList() } + } + + /** + * Adds a single [AddResellerRoyalty] to [addResellerRoyalties]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddResellerRoyalty(addResellerRoyalty: AddResellerRoyalty) = apply { + addResellerRoyalties = + (addResellerRoyalties ?: JsonField.of(mutableListOf())).also { + checkKnown("addResellerRoyalties", it).add(addResellerRoyalty) + } + } + + fun addScheduledCharges(addScheduledCharges: List) = + addScheduledCharges(JsonField.of(addScheduledCharges)) + + /** + * Sets [Builder.addScheduledCharges] to an arbitrary JSON value. + * + * You should usually call [Builder.addScheduledCharges] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun addScheduledCharges(addScheduledCharges: JsonField>) = + apply { + this.addScheduledCharges = addScheduledCharges.map { it.toMutableList() } + } + + /** + * Adds a single [AddScheduledCharge] to [addScheduledCharges]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddScheduledCharge(addScheduledCharge: AddScheduledCharge) = apply { + addScheduledCharges = + (addScheduledCharges ?: JsonField.of(mutableListOf())).also { + checkKnown("addScheduledCharges", it).add(addScheduledCharge) + } + } + + fun addSpendThresholdConfiguration( + addSpendThresholdConfiguration: SpendThresholdConfigurationV2 + ) = addSpendThresholdConfiguration(JsonField.of(addSpendThresholdConfiguration)) + + /** + * Sets [Builder.addSpendThresholdConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.addSpendThresholdConfiguration] with a + * well-typed [SpendThresholdConfigurationV2] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun addSpendThresholdConfiguration( + addSpendThresholdConfiguration: JsonField + ) = apply { this.addSpendThresholdConfiguration = addSpendThresholdConfiguration } + + /** List of subscriptions on the contract. */ + fun addSubscriptions(addSubscriptions: List) = + addSubscriptions(JsonField.of(addSubscriptions)) + + /** + * Sets [Builder.addSubscriptions] to an arbitrary JSON value. + * + * You should usually call [Builder.addSubscriptions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun addSubscriptions(addSubscriptions: JsonField>) = apply { + this.addSubscriptions = addSubscriptions.map { it.toMutableList() } + } + + /** + * Adds a single [AddSubscription] to [addSubscriptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddSubscription(addSubscription: AddSubscription) = apply { + addSubscriptions = + (addSubscriptions ?: JsonField.of(mutableListOf())).also { + checkKnown("addSubscriptions", it).add(addSubscription) + } + } + + fun addUsageFilters(addUsageFilters: List) = + addUsageFilters(JsonField.of(addUsageFilters)) + + /** + * Sets [Builder.addUsageFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.addUsageFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun addUsageFilters(addUsageFilters: JsonField>) = apply { + this.addUsageFilters = addUsageFilters.map { it.toMutableList() } + } + + /** + * Adds a single [AddUsageFilter] to [addUsageFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddUsageFilter(addUsageFilter: AddUsageFilter) = apply { + addUsageFilters = + (addUsageFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("addUsageFilters", it).add(addUsageFilter) + } + } + + fun archiveCommits(archiveCommits: List) = + archiveCommits(JsonField.of(archiveCommits)) + + /** + * Sets [Builder.archiveCommits] to an arbitrary JSON value. + * + * You should usually call [Builder.archiveCommits] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun archiveCommits(archiveCommits: JsonField>) = apply { + this.archiveCommits = archiveCommits.map { it.toMutableList() } + } + + /** + * Adds a single [ArchiveCommit] to [archiveCommits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addArchiveCommit(archiveCommit: ArchiveCommit) = apply { + archiveCommits = + (archiveCommits ?: JsonField.of(mutableListOf())).also { + checkKnown("archiveCommits", it).add(archiveCommit) + } + } + + fun archiveCredits(archiveCredits: List) = + archiveCredits(JsonField.of(archiveCredits)) + + /** + * Sets [Builder.archiveCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.archiveCredits] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun archiveCredits(archiveCredits: JsonField>) = apply { + this.archiveCredits = archiveCredits.map { it.toMutableList() } + } + + /** + * Adds a single [ArchiveCredit] to [archiveCredits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addArchiveCredit(archiveCredit: ArchiveCredit) = apply { + archiveCredits = + (archiveCredits ?: JsonField.of(mutableListOf())).also { + checkKnown("archiveCredits", it).add(archiveCredit) + } + } + + fun archiveScheduledCharges(archiveScheduledCharges: List) = + archiveScheduledCharges(JsonField.of(archiveScheduledCharges)) + + /** + * Sets [Builder.archiveScheduledCharges] to an arbitrary JSON value. + * + * You should usually call [Builder.archiveScheduledCharges] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun archiveScheduledCharges( + archiveScheduledCharges: JsonField> + ) = apply { + this.archiveScheduledCharges = + archiveScheduledCharges.map { it.toMutableList() } + } + + /** + * Adds a single [ArchiveScheduledCharge] to [archiveScheduledCharges]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addArchiveScheduledCharge(archiveScheduledCharge: ArchiveScheduledCharge) = + apply { + archiveScheduledCharges = + (archiveScheduledCharges ?: JsonField.of(mutableListOf())).also { + checkKnown("archiveScheduledCharges", it) + .add(archiveScheduledCharge) + } + } + + fun removeOverrides(removeOverrides: List) = + removeOverrides(JsonField.of(removeOverrides)) + + /** + * Sets [Builder.removeOverrides] to an arbitrary JSON value. + * + * You should usually call [Builder.removeOverrides] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun removeOverrides(removeOverrides: JsonField>) = apply { + this.removeOverrides = removeOverrides.map { it.toMutableList() } + } + + /** + * Adds a single [RemoveOverride] to [removeOverrides]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRemoveOverride(removeOverride: RemoveOverride) = apply { + removeOverrides = + (removeOverrides ?: JsonField.of(mutableListOf())).also { + checkKnown("removeOverrides", it).add(removeOverride) + } + } + + fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + /** + * Prevents the creation of duplicates. If a request to create a record is made with + * a previously used uniqueness key, a new record will not be created and the + * request will fail with a 409 error. + */ + fun uniquenessKey(uniquenessKey: String) = + uniquenessKey(JsonField.of(uniquenessKey)) + + /** + * Sets [Builder.uniquenessKey] to an arbitrary JSON value. + * + * You should usually call [Builder.uniquenessKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun uniquenessKey(uniquenessKey: JsonField) = apply { + this.uniquenessKey = uniquenessKey + } + + fun updateCommits(updateCommits: List) = + updateCommits(JsonField.of(updateCommits)) + + /** + * Sets [Builder.updateCommits] to an arbitrary JSON value. + * + * You should usually call [Builder.updateCommits] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun updateCommits(updateCommits: JsonField>) = apply { + this.updateCommits = updateCommits.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateCommit] to [updateCommits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUpdateCommit(updateCommit: UpdateCommit) = apply { + updateCommits = + (updateCommits ?: JsonField.of(mutableListOf())).also { + checkKnown("updateCommits", it).add(updateCommit) + } + } + + fun updateContractEndDate(updateContractEndDate: OffsetDateTime) = + updateContractEndDate(JsonField.of(updateContractEndDate)) + + /** + * Sets [Builder.updateContractEndDate] to an arbitrary JSON value. + * + * You should usually call [Builder.updateContractEndDate] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun updateContractEndDate(updateContractEndDate: JsonField) = + apply { + this.updateContractEndDate = updateContractEndDate + } + + /** + * Value to update the contract name to. If not provided, the contract name will + * remain unchanged. + */ + fun updateContractName(updateContractName: String?) = + updateContractName(JsonField.ofNullable(updateContractName)) + + /** + * Alias for calling [Builder.updateContractName] with + * `updateContractName.orElse(null)`. + */ + fun updateContractName(updateContractName: Optional) = + updateContractName(updateContractName.getOrNull()) + + /** + * Sets [Builder.updateContractName] to an arbitrary JSON value. + * + * You should usually call [Builder.updateContractName] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun updateContractName(updateContractName: JsonField) = apply { + this.updateContractName = updateContractName + } + + fun updateCredits(updateCredits: List) = + updateCredits(JsonField.of(updateCredits)) + + /** + * Sets [Builder.updateCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.updateCredits] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun updateCredits(updateCredits: JsonField>) = apply { + this.updateCredits = updateCredits.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateCredit] to [updateCredits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUpdateCredit(updateCredit: UpdateCredit) = apply { + updateCredits = + (updateCredits ?: JsonField.of(mutableListOf())).also { + checkKnown("updateCredits", it).add(updateCredit) + } + } + + fun updateDiscounts(updateDiscounts: List) = + updateDiscounts(JsonField.of(updateDiscounts)) + + /** + * Sets [Builder.updateDiscounts] to an arbitrary JSON value. + * + * You should usually call [Builder.updateDiscounts] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun updateDiscounts(updateDiscounts: JsonField>) = apply { + this.updateDiscounts = updateDiscounts.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateDiscount] to [updateDiscounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUpdateDiscount(updateDiscount: UpdateDiscount) = apply { + updateDiscounts = + (updateDiscounts ?: JsonField.of(mutableListOf())).also { + checkKnown("updateDiscounts", it).add(updateDiscount) + } + } + + fun updatePrepaidBalanceThresholdConfiguration( + updatePrepaidBalanceThresholdConfiguration: + UpdatePrepaidBalanceThresholdConfiguration + ) = + updatePrepaidBalanceThresholdConfiguration( + JsonField.of(updatePrepaidBalanceThresholdConfiguration) + ) + + /** + * Sets [Builder.updatePrepaidBalanceThresholdConfiguration] to an arbitrary JSON + * value. + * + * You should usually call [Builder.updatePrepaidBalanceThresholdConfiguration] with + * a well-typed [UpdatePrepaidBalanceThresholdConfiguration] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun updatePrepaidBalanceThresholdConfiguration( + updatePrepaidBalanceThresholdConfiguration: + JsonField + ) = apply { + this.updatePrepaidBalanceThresholdConfiguration = + updatePrepaidBalanceThresholdConfiguration + } + + fun updateRecurringCommits(updateRecurringCommits: List) = + updateRecurringCommits(JsonField.of(updateRecurringCommits)) + + /** + * Sets [Builder.updateRecurringCommits] to an arbitrary JSON value. + * + * You should usually call [Builder.updateRecurringCommits] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun updateRecurringCommits( + updateRecurringCommits: JsonField> + ) = apply { + this.updateRecurringCommits = updateRecurringCommits.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateRecurringCommit] to [updateRecurringCommits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUpdateRecurringCommit(updateRecurringCommit: UpdateRecurringCommit) = apply { + updateRecurringCommits = + (updateRecurringCommits ?: JsonField.of(mutableListOf())).also { + checkKnown("updateRecurringCommits", it).add(updateRecurringCommit) + } + } + + fun updateRecurringCredits(updateRecurringCredits: List) = + updateRecurringCredits(JsonField.of(updateRecurringCredits)) + + /** + * Sets [Builder.updateRecurringCredits] to an arbitrary JSON value. + * + * You should usually call [Builder.updateRecurringCredits] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun updateRecurringCredits( + updateRecurringCredits: JsonField> + ) = apply { + this.updateRecurringCredits = updateRecurringCredits.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateRecurringCredit] to [updateRecurringCredits]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUpdateRecurringCredit(updateRecurringCredit: UpdateRecurringCredit) = apply { + updateRecurringCredits = + (updateRecurringCredits ?: JsonField.of(mutableListOf())).also { + checkKnown("updateRecurringCredits", it).add(updateRecurringCredit) + } + } + + fun updateRefundInvoices(updateRefundInvoices: List) = + updateRefundInvoices(JsonField.of(updateRefundInvoices)) + + /** + * Sets [Builder.updateRefundInvoices] to an arbitrary JSON value. + * + * You should usually call [Builder.updateRefundInvoices] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun updateRefundInvoices( + updateRefundInvoices: JsonField> + ) = apply { + this.updateRefundInvoices = updateRefundInvoices.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateRefundInvoice] to [updateRefundInvoices]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUpdateRefundInvoice(updateRefundInvoice: UpdateRefundInvoice) = apply { + updateRefundInvoices = + (updateRefundInvoices ?: JsonField.of(mutableListOf())).also { + checkKnown("updateRefundInvoices", it).add(updateRefundInvoice) + } + } + + fun updateScheduledCharges(updateScheduledCharges: List) = + updateScheduledCharges(JsonField.of(updateScheduledCharges)) + + /** + * Sets [Builder.updateScheduledCharges] to an arbitrary JSON value. + * + * You should usually call [Builder.updateScheduledCharges] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun updateScheduledCharges( + updateScheduledCharges: JsonField> + ) = apply { + this.updateScheduledCharges = updateScheduledCharges.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateScheduledCharge] to [updateScheduledCharges]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUpdateScheduledCharge(updateScheduledCharge: UpdateScheduledCharge) = apply { + updateScheduledCharges = + (updateScheduledCharges ?: JsonField.of(mutableListOf())).also { + checkKnown("updateScheduledCharges", it).add(updateScheduledCharge) + } + } + + fun updateSpendThresholdConfiguration( + updateSpendThresholdConfiguration: UpdateSpendThresholdConfiguration + ) = + updateSpendThresholdConfiguration( + JsonField.of(updateSpendThresholdConfiguration) + ) + + /** + * Sets [Builder.updateSpendThresholdConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.updateSpendThresholdConfiguration] with a + * well-typed [UpdateSpendThresholdConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun updateSpendThresholdConfiguration( + updateSpendThresholdConfiguration: JsonField + ) = apply { + this.updateSpendThresholdConfiguration = updateSpendThresholdConfiguration + } + + /** Optional list of subscriptions to update. */ + fun updateSubscriptions(updateSubscriptions: List) = + updateSubscriptions(JsonField.of(updateSubscriptions)) + + /** + * Sets [Builder.updateSubscriptions] to an arbitrary JSON value. + * + * You should usually call [Builder.updateSubscriptions] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun updateSubscriptions(updateSubscriptions: JsonField>) = + apply { + this.updateSubscriptions = updateSubscriptions.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateSubscription] to [updateSubscriptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUpdateSubscription(updateSubscription: UpdateSubscription) = apply { + updateSubscriptions = + (updateSubscriptions ?: JsonField.of(mutableListOf())).also { + checkKnown("updateSubscriptions", it).add(updateSubscription) + } + } + + 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 [Edit]. + * + * 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(): Edit = + Edit( + checkRequired("id", id), + (addCommits ?: JsonMissing.of()).map { it.toImmutable() }, + (addCredits ?: JsonMissing.of()).map { it.toImmutable() }, + (addDiscounts ?: JsonMissing.of()).map { it.toImmutable() }, + (addOverrides ?: JsonMissing.of()).map { it.toImmutable() }, + addPrepaidBalanceThresholdConfiguration, + (addProServices ?: JsonMissing.of()).map { it.toImmutable() }, + (addRecurringCommits ?: JsonMissing.of()).map { it.toImmutable() }, + (addRecurringCredits ?: JsonMissing.of()).map { it.toImmutable() }, + (addResellerRoyalties ?: JsonMissing.of()).map { it.toImmutable() }, + (addScheduledCharges ?: JsonMissing.of()).map { it.toImmutable() }, + addSpendThresholdConfiguration, + (addSubscriptions ?: JsonMissing.of()).map { it.toImmutable() }, + (addUsageFilters ?: JsonMissing.of()).map { it.toImmutable() }, + (archiveCommits ?: JsonMissing.of()).map { it.toImmutable() }, + (archiveCredits ?: JsonMissing.of()).map { it.toImmutable() }, + (archiveScheduledCharges ?: JsonMissing.of()).map { it.toImmutable() }, + (removeOverrides ?: JsonMissing.of()).map { it.toImmutable() }, + timestamp, + uniquenessKey, + (updateCommits ?: JsonMissing.of()).map { it.toImmutable() }, + updateContractEndDate, + updateContractName, + (updateCredits ?: JsonMissing.of()).map { it.toImmutable() }, + (updateDiscounts ?: JsonMissing.of()).map { it.toImmutable() }, + updatePrepaidBalanceThresholdConfiguration, + (updateRecurringCommits ?: JsonMissing.of()).map { it.toImmutable() }, + (updateRecurringCredits ?: JsonMissing.of()).map { it.toImmutable() }, + (updateRefundInvoices ?: JsonMissing.of()).map { it.toImmutable() }, + (updateScheduledCharges ?: JsonMissing.of()).map { it.toImmutable() }, + updateSpendThresholdConfiguration, + (updateSubscriptions ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Edit = apply { + if (validated) { + return@apply + } + + id() + addCommits().ifPresent { it.forEach { it.validate() } } + addCredits().ifPresent { it.forEach { it.validate() } } + addDiscounts().ifPresent { it.forEach { it.validate() } } + addOverrides().ifPresent { it.forEach { it.validate() } } + addPrepaidBalanceThresholdConfiguration().ifPresent { it.validate() } + addProServices().ifPresent { it.forEach { it.validate() } } + addRecurringCommits().ifPresent { it.forEach { it.validate() } } + addRecurringCredits().ifPresent { it.forEach { it.validate() } } + addResellerRoyalties().ifPresent { it.forEach { it.validate() } } + addScheduledCharges().ifPresent { it.forEach { it.validate() } } + addSpendThresholdConfiguration().ifPresent { it.validate() } + addSubscriptions().ifPresent { it.forEach { it.validate() } } + addUsageFilters().ifPresent { it.forEach { it.validate() } } + archiveCommits().ifPresent { it.forEach { it.validate() } } + archiveCredits().ifPresent { it.forEach { it.validate() } } + archiveScheduledCharges().ifPresent { it.forEach { it.validate() } } + removeOverrides().ifPresent { it.forEach { it.validate() } } + timestamp() + uniquenessKey() + updateCommits().ifPresent { it.forEach { it.validate() } } + updateContractEndDate() + updateContractName() + updateCredits().ifPresent { it.forEach { it.validate() } } + updateDiscounts().ifPresent { it.forEach { it.validate() } } + updatePrepaidBalanceThresholdConfiguration().ifPresent { it.validate() } + updateRecurringCommits().ifPresent { it.forEach { it.validate() } } + updateRecurringCredits().ifPresent { it.forEach { it.validate() } } + updateRefundInvoices().ifPresent { it.forEach { it.validate() } } + updateScheduledCharges().ifPresent { it.forEach { it.validate() } } + updateSpendThresholdConfiguration().ifPresent { it.validate() } + updateSubscriptions().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (addCommits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (addCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (addDiscounts.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (addOverrides.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (addPrepaidBalanceThresholdConfiguration.asKnown().getOrNull()?.validity() + ?: 0) + + (addProServices.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (addRecurringCommits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (addRecurringCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (addResellerRoyalties.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (addScheduledCharges.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (addSpendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (addSubscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (addUsageFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (archiveCommits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (archiveCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (archiveScheduledCharges.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (removeOverrides.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (timestamp.asKnown().isPresent) 1 else 0) + + (if (uniquenessKey.asKnown().isPresent) 1 else 0) + + (updateCommits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (updateContractEndDate.asKnown().isPresent) 1 else 0) + + (if (updateContractName.asKnown().isPresent) 1 else 0) + + (updateCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (updateDiscounts.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (updatePrepaidBalanceThresholdConfiguration.asKnown().getOrNull()?.validity() + ?: 0) + + (updateRecurringCommits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (updateRecurringCredits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (updateRefundInvoices.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (updateScheduledCharges.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (updateSpendThresholdConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (updateSubscriptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + class AddCommit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val product: JsonField, + private val type: JsonField, + private val accessSchedule: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val description: JsonField, + private val hierarchyConfiguration: JsonField, + private val invoiceSchedule: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val priority: JsonField, + private val rateType: JsonField, + private val rolloverFraction: JsonField, + private val salesforceOpportunityId: JsonField, + private val specifiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("access_schedule") + @ExcludeMissing + accessSchedule: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("invoice_schedule") + @ExcludeMissing + invoiceSchedule: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + @JsonProperty("salesforce_opportunity_id") + @ExcludeMissing + salesforceOpportunityId: JsonField = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + ) : this( + id, + product, + type, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + invoiceSchedule, + name, + netsuiteSalesOrderId, + priority, + rateType, + rolloverFraction, + salesforceOpportunityId, + specifiers, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException 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 product(): Product = product.getRequired("product") + + /** + * @throws MetronomeInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * The schedule that the customer will gain access to the credits purposed with this + * commit. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun accessSchedule(): Optional = + accessSchedule.getOptional("access_schedule") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Optional configuration for commit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * The schedule that the customer will be invoiced for this commit. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun invoiceSchedule(): Optional = + invoiceSchedule.getOptional("invoice_schedule") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * This field's availability is dependent on your client's configuration. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * If multiple credits or commits are applicable, the one with the lower priority + * will apply first. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun priority(): Optional = priority.getOptional("priority") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rateType(): Optional = rateType.getOptional("rate_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = + rolloverFraction.getOptional("rollover_fraction") + + /** + * This field's availability is dependent on your client's configuration. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun salesforceOpportunityId(): Optional = + salesforceOpportunityId.getOptional("salesforce_opportunity_id") + + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. This field cannot be + * used together with `applicable_product_ids` or `applicable_product_tags`. + * Instead, to target usage by product or product tag, pass those values in the body + * of `specifiers`. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [accessSchedule]. + * + * Unlike [accessSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_schedule") + @ExcludeMissing + fun _accessSchedule(): JsonField = accessSchedule + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * Returns the raw JSON value of [invoiceSchedule]. + * + * Unlike [invoiceSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_schedule") + @ExcludeMissing + fun _invoiceSchedule(): JsonField = invoiceSchedule + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction + + /** + * Returns the raw JSON value of [salesforceOpportunityId]. + * + * Unlike [salesforceOpportunityId], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("salesforce_opportunity_id") + @ExcludeMissing + fun _salesforceOpportunityId(): JsonField = salesforceOpportunityId + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + @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 [AddCommit]. + * + * The following fields are required: + * ```java + * .id() + * .product() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddCommit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var product: JsonField? = null + private var type: JsonField? = null + private var accessSchedule: JsonField = JsonMissing.of() + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var description: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var invoiceSchedule: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var priority: JsonField = JsonMissing.of() + private var rateType: JsonField = JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var salesforceOpportunityId: JsonField = JsonMissing.of() + private var specifiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addCommit: AddCommit) = apply { + id = addCommit.id + product = addCommit.product + type = addCommit.type + accessSchedule = addCommit.accessSchedule + applicableProductIds = + addCommit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + addCommit.applicableProductTags.map { it.toMutableList() } + description = addCommit.description + hierarchyConfiguration = addCommit.hierarchyConfiguration + invoiceSchedule = addCommit.invoiceSchedule + name = addCommit.name + netsuiteSalesOrderId = addCommit.netsuiteSalesOrderId + priority = addCommit.priority + rateType = addCommit.rateType + rolloverFraction = addCommit.rolloverFraction + salesforceOpportunityId = addCommit.salesforceOpportunityId + specifiers = addCommit.specifiers.map { it.toMutableList() } + additionalProperties = addCommit.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 product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + /** + * The schedule that the customer will gain access to the credits purposed with + * this commit. + */ + fun accessSchedule(accessSchedule: ScheduleDuration) = + accessSchedule(JsonField.of(accessSchedule)) + + /** + * Sets [Builder.accessSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.accessSchedule] with a well-typed + * [ScheduleDuration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun accessSchedule(accessSchedule: JsonField) = apply { + this.accessSchedule = accessSchedule + } + + fun applicableProductIds(applicableProductIds: List) = + applicableProductIds(JsonField.of(applicableProductIds)) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + fun applicableProductTags(applicableProductTags: List) = + applicableProductTags(JsonField.of(applicableProductTags)) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** Optional configuration for commit hierarchy access control */ + fun hierarchyConfiguration( + hierarchyConfiguration: CommitHierarchyConfiguration + ) = hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + /** The schedule that the customer will be invoiced for this commit. */ + fun invoiceSchedule(invoiceSchedule: InvoiceSchedule) = + invoiceSchedule(JsonField.of(invoiceSchedule)) + + /** + * Sets [Builder.invoiceSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceSchedule] with a well-typed + * [InvoiceSchedule] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun invoiceSchedule(invoiceSchedule: JsonField) = apply { + this.invoiceSchedule = invoiceSchedule + } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** This field's availability is dependent on your client's configuration. */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String) = + netsuiteSalesOrderId(JsonField.of(netsuiteSalesOrderId)) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** + * If multiple credits or commits are applicable, the one with the lower + * priority will apply first. + */ + fun priority(priority: Double) = priority(JsonField.of(priority)) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(JsonField.of(rolloverFraction)) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } + + /** This field's availability is dependent on your client's configuration. */ + fun salesforceOpportunityId(salesforceOpportunityId: String) = + salesforceOpportunityId(JsonField.of(salesforceOpportunityId)) + + /** + * Sets [Builder.salesforceOpportunityId] to an arbitrary JSON value. + * + * You should usually call [Builder.salesforceOpportunityId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun salesforceOpportunityId(salesforceOpportunityId: JsonField) = + apply { + this.salesforceOpportunityId = salesforceOpportunityId + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. This + * field cannot be used together with `applicable_product_ids` or + * `applicable_product_tags`. Instead, to target usage by product or product + * tag, pass those values in the body of `specifiers`. + */ + fun specifiers(specifiers: List) = + specifiers(JsonField.of(specifiers)) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifierInput] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpecifier(specifier: CommitSpecifierInput) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + 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 [AddCommit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .product() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddCommit = + AddCommit( + checkRequired("id", id), + checkRequired("product", product), + checkRequired("type", type), + accessSchedule, + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + description, + hierarchyConfiguration, + invoiceSchedule, + name, + netsuiteSalesOrderId, + priority, + rateType, + rolloverFraction, + salesforceOpportunityId, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddCommit = apply { + if (validated) { + return@apply + } + + id() + product().validate() + type().validate() + accessSchedule().ifPresent { it.validate() } + applicableProductIds() + applicableProductTags() + description() + hierarchyConfiguration().ifPresent { it.validate() } + invoiceSchedule().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + priority() + rateType().ifPresent { it.validate() } + rolloverFraction() + salesforceOpportunityId() + specifiers().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (accessSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (invoiceSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + + (if (salesforceOpportunityId.asKnown().isPresent) 1 else 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val PREPAID = of("PREPAID") + + @JvmField val POSTPAID = of("POSTPAID") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + PREPAID, + POSTPAID, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + PREPAID, + POSTPAID, + /** + * An enum member indicating that [Type] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + PREPAID -> Value.PREPAID + POSTPAID -> Value.POSTPAID + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + PREPAID -> Known.PREPAID + POSTPAID -> Known.POSTPAID + else -> throw MetronomeInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The schedule that the customer will be invoiced for this commit. */ + class InvoiceSchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditType: JsonField, + private val doNotInvoice: JsonField, + private val scheduleItems: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_type") + @ExcludeMissing + creditType: JsonField = JsonMissing.of(), + @JsonProperty("do_not_invoice") + @ExcludeMissing + doNotInvoice: JsonField = JsonMissing.of(), + @JsonProperty("schedule_items") + @ExcludeMissing + scheduleItems: JsonField> = JsonMissing.of(), + ) : this(creditType, doNotInvoice, scheduleItems, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun creditType(): Optional = + creditType.getOptional("credit_type") + + /** + * If true, this schedule will not generate an invoice. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun doNotInvoice(): Optional = + doNotInvoice.getOptional("do_not_invoice") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun scheduleItems(): Optional> = + scheduleItems.getOptional("schedule_items") + + /** + * Returns the raw JSON value of [creditType]. + * + * Unlike [creditType], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type") + @ExcludeMissing + fun _creditType(): JsonField = creditType + + /** + * Returns the raw JSON value of [doNotInvoice]. + * + * Unlike [doNotInvoice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("do_not_invoice") + @ExcludeMissing + fun _doNotInvoice(): JsonField = doNotInvoice + + /** + * Returns the raw JSON value of [scheduleItems]. + * + * Unlike [scheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("schedule_items") + @ExcludeMissing + fun _scheduleItems(): JsonField> = scheduleItems + + @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 + * [InvoiceSchedule]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InvoiceSchedule]. */ + class Builder internal constructor() { + + private var creditType: JsonField = JsonMissing.of() + private var doNotInvoice: JsonField = JsonMissing.of() + private var scheduleItems: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(invoiceSchedule: InvoiceSchedule) = apply { + creditType = invoiceSchedule.creditType + doNotInvoice = invoiceSchedule.doNotInvoice + scheduleItems = invoiceSchedule.scheduleItems.map { it.toMutableList() } + additionalProperties = + invoiceSchedule.additionalProperties.toMutableMap() + } + + fun creditType(creditType: CreditTypeData) = + creditType(JsonField.of(creditType)) + + /** + * Sets [Builder.creditType] to an arbitrary JSON value. + * + * You should usually call [Builder.creditType] with a well-typed + * [CreditTypeData] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun creditType(creditType: JsonField) = apply { + this.creditType = creditType + } + + /** If true, this schedule will not generate an invoice. */ + fun doNotInvoice(doNotInvoice: Boolean) = + doNotInvoice(JsonField.of(doNotInvoice)) + + /** + * Sets [Builder.doNotInvoice] to an arbitrary JSON value. + * + * You should usually call [Builder.doNotInvoice] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun doNotInvoice(doNotInvoice: JsonField) = apply { + this.doNotInvoice = doNotInvoice + } + + fun scheduleItems(scheduleItems: List) = + scheduleItems(JsonField.of(scheduleItems)) + + /** + * Sets [Builder.scheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.scheduleItems] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun scheduleItems(scheduleItems: JsonField>) = apply { + this.scheduleItems = scheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [ScheduleItem] to [scheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addScheduleItem(scheduleItem: ScheduleItem) = apply { + scheduleItems = + (scheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("scheduleItems", it).add(scheduleItem) + } + } + + 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 [InvoiceSchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InvoiceSchedule = + InvoiceSchedule( + creditType, + doNotInvoice, + (scheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InvoiceSchedule = apply { + if (validated) { + return@apply + } + + creditType().ifPresent { it.validate() } + doNotInvoice() + scheduleItems().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (creditType.asKnown().getOrNull()?.validity() ?: 0) + + (if (doNotInvoice.asKnown().isPresent) 1 else 0) + + (scheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + class ScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val timestamp: JsonField, + private val amount: JsonField, + private val invoiceId: JsonField, + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("invoice_id") + @ExcludeMissing + invoiceId: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this( + id, + timestamp, + amount, + invoiceId, + quantity, + unitPrice, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException 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 timestamp(): OffsetDateTime = timestamp.getRequired("timestamp") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun invoiceId(): Optional = invoiceId.getOptional("invoice_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [invoiceId]. + * + * Unlike [invoiceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_id") + @ExcludeMissing + fun _invoiceId(): JsonField = invoiceId + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [ScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * .timestamp() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var timestamp: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var invoiceId: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(scheduleItem: ScheduleItem) = apply { + id = scheduleItem.id + timestamp = scheduleItem.timestamp + amount = scheduleItem.amount + invoiceId = scheduleItem.invoiceId + quantity = scheduleItem.quantity + unitPrice = scheduleItem.unitPrice + additionalProperties = + scheduleItem.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 timestamp(timestamp: OffsetDateTime) = + timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun invoiceId(invoiceId: String?) = + invoiceId(JsonField.ofNullable(invoiceId)) + + /** + * Alias for calling [Builder.invoiceId] with `invoiceId.orElse(null)`. + */ + fun invoiceId(invoiceId: Optional) = + invoiceId(invoiceId.getOrNull()) + + /** + * Sets [Builder.invoiceId] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceId] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun invoiceId(invoiceId: JsonField) = apply { + this.invoiceId = invoiceId + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed + * [Double] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [ScheduleItem]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .id() + * .timestamp() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ScheduleItem = + ScheduleItem( + checkRequired("id", id), + checkRequired("timestamp", timestamp), + amount, + invoiceId, + quantity, + unitPrice, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ScheduleItem = apply { + if (validated) { + return@apply + } + + id() + timestamp() + amount() + invoiceId() + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (timestamp.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (invoiceId.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ScheduleItem && + id == other.id && + timestamp == other.timestamp && + amount == other.amount && + invoiceId == other.invoiceId && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + timestamp, + amount, + invoiceId, + quantity, + unitPrice, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScheduleItem{id=$id, timestamp=$timestamp, amount=$amount, invoiceId=$invoiceId, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InvoiceSchedule && + creditType == other.creditType && + doNotInvoice == other.doNotInvoice && + scheduleItems == other.scheduleItems && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(creditType, doNotInvoice, scheduleItems, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InvoiceSchedule{creditType=$creditType, doNotInvoice=$doNotInvoice, scheduleItems=$scheduleItems, additionalProperties=$additionalProperties}" + } + + class RateType + @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 COMMIT_RATE = of("COMMIT_RATE") + + @JvmField val LIST_RATE = of("LIST_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + COMMIT_RATE, + LIST_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + COMMIT_RATE, + LIST_RATE, + /** + * An enum member indicating that [RateType] 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) { + COMMIT_RATE -> Value.COMMIT_RATE + LIST_RATE -> Value.LIST_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_RATE -> Known.COMMIT_RATE + LIST_RATE -> Known.LIST_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && 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 AddCommit && + id == other.id && + product == other.product && + type == other.type && + accessSchedule == other.accessSchedule && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + description == other.description && + hierarchyConfiguration == other.hierarchyConfiguration && + invoiceSchedule == other.invoiceSchedule && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + priority == other.priority && + rateType == other.rateType && + rolloverFraction == other.rolloverFraction && + salesforceOpportunityId == other.salesforceOpportunityId && + specifiers == other.specifiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + product, + type, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + invoiceSchedule, + name, + netsuiteSalesOrderId, + priority, + rateType, + rolloverFraction, + salesforceOpportunityId, + specifiers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddCommit{id=$id, product=$product, type=$type, accessSchedule=$accessSchedule, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, rolloverFraction=$rolloverFraction, salesforceOpportunityId=$salesforceOpportunityId, specifiers=$specifiers, additionalProperties=$additionalProperties}" + } + + class AddCredit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val product: JsonField, + private val type: JsonField, + private val accessSchedule: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val description: JsonField, + private val hierarchyConfiguration: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val priority: JsonField, + private val rateType: JsonField, + private val rolloverFraction: JsonField, + private val salesforceOpportunityId: JsonField, + private val specifiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("access_schedule") + @ExcludeMissing + accessSchedule: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + @JsonProperty("salesforce_opportunity_id") + @ExcludeMissing + salesforceOpportunityId: JsonField = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + ) : this( + id, + product, + type, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + rateType, + rolloverFraction, + salesforceOpportunityId, + specifiers, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException 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 product(): Product = product.getRequired("product") + + /** + * @throws MetronomeInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * The schedule that the customer will gain access to the credits. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun accessSchedule(): Optional = + accessSchedule.getOptional("access_schedule") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Optional configuration for recurring credit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * This field's availability is dependent on your client's configuration. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * If multiple credits or commits are applicable, the one with the lower priority + * will apply first. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun priority(): Optional = priority.getOptional("priority") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rateType(): Optional = rateType.getOptional("rate_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = + rolloverFraction.getOptional("rollover_fraction") + + /** + * This field's availability is dependent on your client's configuration. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun salesforceOpportunityId(): Optional = + salesforceOpportunityId.getOptional("salesforce_opportunity_id") + + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. This field cannot be + * used together with `applicable_product_ids` or `applicable_product_tags`. + * Instead, to target usage by product or product tag, pass those values in the body + * of `specifiers`. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [accessSchedule]. + * + * Unlike [accessSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_schedule") + @ExcludeMissing + fun _accessSchedule(): JsonField = accessSchedule + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction + + /** + * Returns the raw JSON value of [salesforceOpportunityId]. + * + * Unlike [salesforceOpportunityId], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("salesforce_opportunity_id") + @ExcludeMissing + fun _salesforceOpportunityId(): JsonField = salesforceOpportunityId + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + @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 [AddCredit]. + * + * The following fields are required: + * ```java + * .id() + * .product() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddCredit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var product: JsonField? = null + private var type: JsonField? = null + private var accessSchedule: JsonField = JsonMissing.of() + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var description: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var priority: JsonField = JsonMissing.of() + private var rateType: JsonField = JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var salesforceOpportunityId: JsonField = JsonMissing.of() + private var specifiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addCredit: AddCredit) = apply { + id = addCredit.id + product = addCredit.product + type = addCredit.type + accessSchedule = addCredit.accessSchedule + applicableProductIds = + addCredit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + addCredit.applicableProductTags.map { it.toMutableList() } + description = addCredit.description + hierarchyConfiguration = addCredit.hierarchyConfiguration + name = addCredit.name + netsuiteSalesOrderId = addCredit.netsuiteSalesOrderId + priority = addCredit.priority + rateType = addCredit.rateType + rolloverFraction = addCredit.rolloverFraction + salesforceOpportunityId = addCredit.salesforceOpportunityId + specifiers = addCredit.specifiers.map { it.toMutableList() } + additionalProperties = addCredit.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 product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + /** The schedule that the customer will gain access to the credits. */ + fun accessSchedule(accessSchedule: ScheduleDuration) = + accessSchedule(JsonField.of(accessSchedule)) + + /** + * Sets [Builder.accessSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.accessSchedule] with a well-typed + * [ScheduleDuration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun accessSchedule(accessSchedule: JsonField) = apply { + this.accessSchedule = accessSchedule + } + + fun applicableProductIds(applicableProductIds: List) = + applicableProductIds(JsonField.of(applicableProductIds)) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + fun applicableProductTags(applicableProductTags: List) = + applicableProductTags(JsonField.of(applicableProductTags)) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** Optional configuration for recurring credit hierarchy access control */ + fun hierarchyConfiguration( + hierarchyConfiguration: CommitHierarchyConfiguration + ) = hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** This field's availability is dependent on your client's configuration. */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String) = + netsuiteSalesOrderId(JsonField.of(netsuiteSalesOrderId)) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** + * If multiple credits or commits are applicable, the one with the lower + * priority will apply first. + */ + fun priority(priority: Double) = priority(JsonField.of(priority)) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(JsonField.of(rolloverFraction)) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } + + /** This field's availability is dependent on your client's configuration. */ + fun salesforceOpportunityId(salesforceOpportunityId: String) = + salesforceOpportunityId(JsonField.of(salesforceOpportunityId)) + + /** + * Sets [Builder.salesforceOpportunityId] to an arbitrary JSON value. + * + * You should usually call [Builder.salesforceOpportunityId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun salesforceOpportunityId(salesforceOpportunityId: JsonField) = + apply { + this.salesforceOpportunityId = salesforceOpportunityId + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. This + * field cannot be used together with `applicable_product_ids` or + * `applicable_product_tags`. Instead, to target usage by product or product + * tag, pass those values in the body of `specifiers`. + */ + fun specifiers(specifiers: List) = + specifiers(JsonField.of(specifiers)) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifierInput] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpecifier(specifier: CommitSpecifierInput) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + 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 [AddCredit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .product() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddCredit = + AddCredit( + checkRequired("id", id), + checkRequired("product", product), + checkRequired("type", type), + accessSchedule, + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + rateType, + rolloverFraction, + salesforceOpportunityId, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddCredit = apply { + if (validated) { + return@apply + } + + id() + product().validate() + type().validate() + accessSchedule().ifPresent { it.validate() } + applicableProductIds() + applicableProductTags() + description() + hierarchyConfiguration().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + priority() + rateType().ifPresent { it.validate() } + rolloverFraction() + salesforceOpportunityId() + specifiers().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (accessSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + + (if (salesforceOpportunityId.asKnown().isPresent) 1 else 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val CREDIT = of("CREDIT") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + CREDIT + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + CREDIT, + /** + * An enum member indicating that [Type] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + CREDIT -> Value.CREDIT + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + CREDIT -> Known.CREDIT + else -> throw MetronomeInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class RateType + @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 COMMIT_RATE = of("COMMIT_RATE") + + @JvmField val LIST_RATE = of("LIST_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + COMMIT_RATE, + LIST_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + COMMIT_RATE, + LIST_RATE, + /** + * An enum member indicating that [RateType] 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) { + COMMIT_RATE -> Value.COMMIT_RATE + LIST_RATE -> Value.LIST_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_RATE -> Known.COMMIT_RATE + LIST_RATE -> Known.LIST_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && 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 AddCredit && + id == other.id && + product == other.product && + type == other.type && + accessSchedule == other.accessSchedule && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + description == other.description && + hierarchyConfiguration == other.hierarchyConfiguration && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + priority == other.priority && + rateType == other.rateType && + rolloverFraction == other.rolloverFraction && + salesforceOpportunityId == other.salesforceOpportunityId && + specifiers == other.specifiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + product, + type, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + rateType, + rolloverFraction, + salesforceOpportunityId, + specifiers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddCredit{id=$id, product=$product, type=$type, accessSchedule=$accessSchedule, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, description=$description, hierarchyConfiguration=$hierarchyConfiguration, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, rateType=$rateType, rolloverFraction=$rolloverFraction, salesforceOpportunityId=$salesforceOpportunityId, specifiers=$specifiers, additionalProperties=$additionalProperties}" + } + + class AddOverride + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val startingAt: JsonField, + private val applicableProductTags: JsonField>, + private val endingBefore: JsonField, + private val entitled: JsonField, + private val isCommitSpecific: JsonField, + private val multiplier: JsonField, + private val overrideSpecifiers: JsonField>, + private val overrideTiers: JsonField>, + private val overwriteRate: JsonField, + private val priority: JsonField, + private val product: JsonField, + private val target: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("entitled") + @ExcludeMissing + entitled: JsonField = JsonMissing.of(), + @JsonProperty("is_commit_specific") + @ExcludeMissing + isCommitSpecific: JsonField = JsonMissing.of(), + @JsonProperty("multiplier") + @ExcludeMissing + multiplier: JsonField = JsonMissing.of(), + @JsonProperty("override_specifiers") + @ExcludeMissing + overrideSpecifiers: JsonField> = JsonMissing.of(), + @JsonProperty("override_tiers") + @ExcludeMissing + overrideTiers: JsonField> = JsonMissing.of(), + @JsonProperty("overwrite_rate") + @ExcludeMissing + overwriteRate: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + @JsonProperty("target") + @ExcludeMissing + target: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this( + id, + createdAt, + startingAt, + applicableProductTags, + endingBefore, + entitled, + isCommitSpecific, + multiplier, + overrideSpecifiers, + overrideTiers, + overwriteRate, + priority, + product, + target, + type, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("created_at") + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun entitled(): Optional = entitled.getOptional("entitled") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun isCommitSpecific(): Optional = + isCommitSpecific.getOptional("is_commit_specific") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun multiplier(): Optional = multiplier.getOptional("multiplier") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun overrideSpecifiers(): Optional> = + overrideSpecifiers.getOptional("override_specifiers") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun overrideTiers(): Optional> = + overrideTiers.getOptional("override_tiers") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun overwriteRate(): Optional = + overwriteRate.getOptional("overwrite_rate") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun priority(): Optional = priority.getOptional("priority") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun product(): Optional = product.getOptional("product") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun target(): Optional = target.getOptional("target") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [entitled]. + * + * Unlike [entitled], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("entitled") + @ExcludeMissing + fun _entitled(): JsonField = entitled + + /** + * Returns the raw JSON value of [isCommitSpecific]. + * + * Unlike [isCommitSpecific], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("is_commit_specific") + @ExcludeMissing + fun _isCommitSpecific(): JsonField = isCommitSpecific + + /** + * Returns the raw JSON value of [multiplier]. + * + * Unlike [multiplier], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("multiplier") + @ExcludeMissing + fun _multiplier(): JsonField = multiplier + + /** + * Returns the raw JSON value of [overrideSpecifiers]. + * + * Unlike [overrideSpecifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("override_specifiers") + @ExcludeMissing + fun _overrideSpecifiers(): JsonField> = overrideSpecifiers + + /** + * Returns the raw JSON value of [overrideTiers]. + * + * Unlike [overrideTiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("override_tiers") + @ExcludeMissing + fun _overrideTiers(): JsonField> = overrideTiers + + /** + * Returns the raw JSON value of [overwriteRate]. + * + * Unlike [overwriteRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("overwrite_rate") + @ExcludeMissing + fun _overwriteRate(): JsonField = overwriteRate + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + /** + * Returns the raw JSON value of [target]. + * + * Unlike [target], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("target") @ExcludeMissing fun _target(): JsonField = target + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AddOverride]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddOverride]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var startingAt: JsonField? = null + private var applicableProductTags: JsonField>? = null + private var endingBefore: JsonField = JsonMissing.of() + private var entitled: JsonField = JsonMissing.of() + private var isCommitSpecific: JsonField = JsonMissing.of() + private var multiplier: JsonField = JsonMissing.of() + private var overrideSpecifiers: JsonField>? = + null + private var overrideTiers: JsonField>? = null + private var overwriteRate: JsonField = JsonMissing.of() + private var priority: JsonField = JsonMissing.of() + private var product: JsonField = JsonMissing.of() + private var target: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addOverride: AddOverride) = apply { + id = addOverride.id + createdAt = addOverride.createdAt + startingAt = addOverride.startingAt + applicableProductTags = + addOverride.applicableProductTags.map { it.toMutableList() } + endingBefore = addOverride.endingBefore + entitled = addOverride.entitled + isCommitSpecific = addOverride.isCommitSpecific + multiplier = addOverride.multiplier + overrideSpecifiers = + addOverride.overrideSpecifiers.map { it.toMutableList() } + overrideTiers = addOverride.overrideTiers.map { it.toMutableList() } + overwriteRate = addOverride.overwriteRate + priority = addOverride.priority + product = addOverride.product + target = addOverride.target + type = addOverride.type + additionalProperties = addOverride.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 createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + fun applicableProductTags(applicableProductTags: List) = + applicableProductTags(JsonField.of(applicableProductTags)) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun entitled(entitled: Boolean) = entitled(JsonField.of(entitled)) + + /** + * Sets [Builder.entitled] to an arbitrary JSON value. + * + * You should usually call [Builder.entitled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun entitled(entitled: JsonField) = apply { this.entitled = entitled } + + fun isCommitSpecific(isCommitSpecific: Boolean) = + isCommitSpecific(JsonField.of(isCommitSpecific)) + + /** + * Sets [Builder.isCommitSpecific] to an arbitrary JSON value. + * + * You should usually call [Builder.isCommitSpecific] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun isCommitSpecific(isCommitSpecific: JsonField) = apply { + this.isCommitSpecific = isCommitSpecific + } + + fun multiplier(multiplier: Double) = multiplier(JsonField.of(multiplier)) + + /** + * Sets [Builder.multiplier] to an arbitrary JSON value. + * + * You should usually call [Builder.multiplier] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun multiplier(multiplier: JsonField) = apply { + this.multiplier = multiplier + } + + fun overrideSpecifiers(overrideSpecifiers: List) = + overrideSpecifiers(JsonField.of(overrideSpecifiers)) + + /** + * Sets [Builder.overrideSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.overrideSpecifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun overrideSpecifiers(overrideSpecifiers: JsonField>) = + apply { + this.overrideSpecifiers = overrideSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [OverrideSpecifier] to [overrideSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addOverrideSpecifier(overrideSpecifier: OverrideSpecifier) = apply { + overrideSpecifiers = + (overrideSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("overrideSpecifiers", it).add(overrideSpecifier) + } + } + + fun overrideTiers(overrideTiers: List) = + overrideTiers(JsonField.of(overrideTiers)) + + /** + * Sets [Builder.overrideTiers] to an arbitrary JSON value. + * + * You should usually call [Builder.overrideTiers] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun overrideTiers(overrideTiers: JsonField>) = apply { + this.overrideTiers = overrideTiers.map { it.toMutableList() } + } + + /** + * Adds a single [OverrideTier] to [overrideTiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addOverrideTier(overrideTier: OverrideTier) = apply { + overrideTiers = + (overrideTiers ?: JsonField.of(mutableListOf())).also { + checkKnown("overrideTiers", it).add(overrideTier) + } + } + + fun overwriteRate(overwriteRate: OverwriteRate) = + overwriteRate(JsonField.of(overwriteRate)) + + /** + * Sets [Builder.overwriteRate] to an arbitrary JSON value. + * + * You should usually call [Builder.overwriteRate] with a well-typed + * [OverwriteRate] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun overwriteRate(overwriteRate: JsonField) = apply { + this.overwriteRate = overwriteRate + } + + fun priority(priority: Double) = priority(JsonField.of(priority)) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + fun target(target: Target) = target(JsonField.of(target)) + + /** + * Sets [Builder.target] to an arbitrary JSON value. + * + * You should usually call [Builder.target] with a well-typed [Target] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun target(target: JsonField) = apply { this.target = target } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [AddOverride]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddOverride = + AddOverride( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("startingAt", startingAt), + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + endingBefore, + entitled, + isCommitSpecific, + multiplier, + (overrideSpecifiers ?: JsonMissing.of()).map { it.toImmutable() }, + (overrideTiers ?: JsonMissing.of()).map { it.toImmutable() }, + overwriteRate, + priority, + product, + target, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddOverride = apply { + if (validated) { + return@apply + } + + id() + createdAt() + startingAt() + applicableProductTags() + endingBefore() + entitled() + isCommitSpecific() + multiplier() + overrideSpecifiers().ifPresent { it.forEach { it.validate() } } + overrideTiers().ifPresent { it.forEach { it.validate() } } + overwriteRate().ifPresent { it.validate() } + priority() + product().ifPresent { it.validate() } + target().ifPresent { it.validate() } + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (entitled.asKnown().isPresent) 1 else 0) + + (if (isCommitSpecific.asKnown().isPresent) 1 else 0) + + (if (multiplier.asKnown().isPresent) 1 else 0) + + (overrideSpecifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (overrideTiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (overwriteRate.asKnown().getOrNull()?.validity() ?: 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + (target.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class OverrideSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val billingFrequency: JsonField, + private val commitIds: JsonField>, + private val presentationGroupValues: JsonField, + private val pricingGroupValues: JsonField, + private val productId: JsonField, + private val productTags: JsonField>, + private val recurringCommitIds: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("billing_frequency") + @ExcludeMissing + billingFrequency: JsonField = JsonMissing.of(), + @JsonProperty("commit_ids") + @ExcludeMissing + commitIds: JsonField> = JsonMissing.of(), + @JsonProperty("presentation_group_values") + @ExcludeMissing + presentationGroupValues: JsonField = + JsonMissing.of(), + @JsonProperty("pricing_group_values") + @ExcludeMissing + pricingGroupValues: JsonField = JsonMissing.of(), + @JsonProperty("product_id") + @ExcludeMissing + productId: JsonField = JsonMissing.of(), + @JsonProperty("product_tags") + @ExcludeMissing + productTags: JsonField> = JsonMissing.of(), + @JsonProperty("recurring_commit_ids") + @ExcludeMissing + recurringCommitIds: JsonField> = JsonMissing.of(), + ) : this( + billingFrequency, + commitIds, + presentationGroupValues, + pricingGroupValues, + productId, + productTags, + recurringCommitIds, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun billingFrequency(): Optional = + billingFrequency.getOptional("billing_frequency") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun commitIds(): Optional> = commitIds.getOptional("commit_ids") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun presentationGroupValues(): Optional = + presentationGroupValues.getOptional("presentation_group_values") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun pricingGroupValues(): Optional = + pricingGroupValues.getOptional("pricing_group_values") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun productId(): Optional = productId.getOptional("product_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun productTags(): Optional> = + productTags.getOptional("product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun recurringCommitIds(): Optional> = + recurringCommitIds.getOptional("recurring_commit_ids") + + /** + * Returns the raw JSON value of [billingFrequency]. + * + * Unlike [billingFrequency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billing_frequency") + @ExcludeMissing + fun _billingFrequency(): JsonField = billingFrequency + + /** + * Returns the raw JSON value of [commitIds]. + * + * Unlike [commitIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("commit_ids") + @ExcludeMissing + fun _commitIds(): JsonField> = commitIds + + /** + * Returns the raw JSON value of [presentationGroupValues]. + * + * Unlike [presentationGroupValues], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("presentation_group_values") + @ExcludeMissing + fun _presentationGroupValues(): JsonField = + presentationGroupValues + + /** + * Returns the raw JSON value of [pricingGroupValues]. + * + * Unlike [pricingGroupValues], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("pricing_group_values") + @ExcludeMissing + fun _pricingGroupValues(): JsonField = pricingGroupValues + + /** + * Returns the raw JSON value of [productId]. + * + * Unlike [productId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("product_id") + @ExcludeMissing + fun _productId(): JsonField = productId + + /** + * Returns the raw JSON value of [productTags]. + * + * Unlike [productTags], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("product_tags") + @ExcludeMissing + fun _productTags(): JsonField> = productTags + + /** + * Returns the raw JSON value of [recurringCommitIds]. + * + * Unlike [recurringCommitIds], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("recurring_commit_ids") + @ExcludeMissing + fun _recurringCommitIds(): JsonField> = recurringCommitIds + + @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 + * [OverrideSpecifier]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OverrideSpecifier]. */ + class Builder internal constructor() { + + private var billingFrequency: JsonField = JsonMissing.of() + private var commitIds: JsonField>? = null + private var presentationGroupValues: JsonField = + JsonMissing.of() + private var pricingGroupValues: JsonField = + JsonMissing.of() + private var productId: JsonField = JsonMissing.of() + private var productTags: JsonField>? = null + private var recurringCommitIds: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(overrideSpecifier: OverrideSpecifier) = apply { + billingFrequency = overrideSpecifier.billingFrequency + commitIds = overrideSpecifier.commitIds.map { it.toMutableList() } + presentationGroupValues = overrideSpecifier.presentationGroupValues + pricingGroupValues = overrideSpecifier.pricingGroupValues + productId = overrideSpecifier.productId + productTags = overrideSpecifier.productTags.map { it.toMutableList() } + recurringCommitIds = + overrideSpecifier.recurringCommitIds.map { it.toMutableList() } + additionalProperties = + overrideSpecifier.additionalProperties.toMutableMap() + } + + fun billingFrequency(billingFrequency: BillingFrequency) = + billingFrequency(JsonField.of(billingFrequency)) + + /** + * Sets [Builder.billingFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.billingFrequency] with a well-typed + * [BillingFrequency] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun billingFrequency(billingFrequency: JsonField) = + apply { + this.billingFrequency = billingFrequency + } + + fun commitIds(commitIds: List) = commitIds(JsonField.of(commitIds)) + + /** + * Sets [Builder.commitIds] to an arbitrary JSON value. + * + * You should usually call [Builder.commitIds] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun commitIds(commitIds: JsonField>) = apply { + this.commitIds = commitIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [commitIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addCommitId(commitId: String) = apply { + commitIds = + (commitIds ?: JsonField.of(mutableListOf())).also { + checkKnown("commitIds", it).add(commitId) + } + } + + fun presentationGroupValues( + presentationGroupValues: PresentationGroupValues + ) = presentationGroupValues(JsonField.of(presentationGroupValues)) + + /** + * Sets [Builder.presentationGroupValues] to an arbitrary JSON value. + * + * You should usually call [Builder.presentationGroupValues] with a + * well-typed [PresentationGroupValues] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun presentationGroupValues( + presentationGroupValues: JsonField + ) = apply { this.presentationGroupValues = presentationGroupValues } + + fun pricingGroupValues(pricingGroupValues: PricingGroupValues) = + pricingGroupValues(JsonField.of(pricingGroupValues)) + + /** + * Sets [Builder.pricingGroupValues] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingGroupValues] with a well-typed + * [PricingGroupValues] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun pricingGroupValues(pricingGroupValues: JsonField) = + apply { + this.pricingGroupValues = pricingGroupValues + } + + fun productId(productId: String) = productId(JsonField.of(productId)) + + /** + * Sets [Builder.productId] to an arbitrary JSON value. + * + * You should usually call [Builder.productId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun productId(productId: JsonField) = apply { + this.productId = productId + } + + fun productTags(productTags: List) = + productTags(JsonField.of(productTags)) + + /** + * Sets [Builder.productTags] to an arbitrary JSON value. + * + * You should usually call [Builder.productTags] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun productTags(productTags: JsonField>) = apply { + this.productTags = productTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [productTags]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addProductTag(productTag: String) = apply { + productTags = + (productTags ?: JsonField.of(mutableListOf())).also { + checkKnown("productTags", it).add(productTag) + } + } + + fun recurringCommitIds(recurringCommitIds: List) = + recurringCommitIds(JsonField.of(recurringCommitIds)) + + /** + * Sets [Builder.recurringCommitIds] to an arbitrary JSON value. + * + * You should usually call [Builder.recurringCommitIds] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun recurringCommitIds(recurringCommitIds: JsonField>) = + apply { + this.recurringCommitIds = + recurringCommitIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [recurringCommitIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addRecurringCommitId(recurringCommitId: String) = apply { + recurringCommitIds = + (recurringCommitIds ?: JsonField.of(mutableListOf())).also { + checkKnown("recurringCommitIds", it).add(recurringCommitId) + } + } + + 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 [OverrideSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): OverrideSpecifier = + OverrideSpecifier( + billingFrequency, + (commitIds ?: JsonMissing.of()).map { it.toImmutable() }, + presentationGroupValues, + pricingGroupValues, + productId, + (productTags ?: JsonMissing.of()).map { it.toImmutable() }, + (recurringCommitIds ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): OverrideSpecifier = apply { + if (validated) { + return@apply + } + + billingFrequency().ifPresent { it.validate() } + commitIds() + presentationGroupValues().ifPresent { it.validate() } + pricingGroupValues().ifPresent { it.validate() } + productId() + productTags() + recurringCommitIds() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (billingFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (commitIds.asKnown().getOrNull()?.size ?: 0) + + (presentationGroupValues.asKnown().getOrNull()?.validity() ?: 0) + + (pricingGroupValues.asKnown().getOrNull()?.validity() ?: 0) + + (if (productId.asKnown().isPresent) 1 else 0) + + (productTags.asKnown().getOrNull()?.size ?: 0) + + (recurringCommitIds.asKnown().getOrNull()?.size ?: 0) + + class BillingFrequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = BillingFrequency(JsonField.of(value)) + } + + /** An enum containing [BillingFrequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [BillingFrequency]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [BillingFrequency] 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 { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [BillingFrequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> + throw MetronomeInvalidDataException( + "Unknown BillingFrequency: $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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): BillingFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 BillingFrequency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class PresentationGroupValues + @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 + * [PresentationGroupValues]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PresentationGroupValues]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(presentationGroupValues: PresentationGroupValues) = + apply { + additionalProperties = + presentationGroupValues.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 [PresentationGroupValues]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): PresentationGroupValues = + PresentationGroupValues(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): PresentationGroupValues = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 PresentationGroupValues && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PresentationGroupValues{additionalProperties=$additionalProperties}" + } + + class PricingGroupValues + @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 + * [PricingGroupValues]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PricingGroupValues]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(pricingGroupValues: PricingGroupValues) = apply { + additionalProperties = + pricingGroupValues.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 [PricingGroupValues]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): PricingGroupValues = + PricingGroupValues(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): PricingGroupValues = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 PricingGroupValues && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PricingGroupValues{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OverrideSpecifier && + billingFrequency == other.billingFrequency && + commitIds == other.commitIds && + presentationGroupValues == other.presentationGroupValues && + pricingGroupValues == other.pricingGroupValues && + productId == other.productId && + productTags == other.productTags && + recurringCommitIds == other.recurringCommitIds && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + billingFrequency, + commitIds, + presentationGroupValues, + pricingGroupValues, + productId, + productTags, + recurringCommitIds, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OverrideSpecifier{billingFrequency=$billingFrequency, commitIds=$commitIds, presentationGroupValues=$presentationGroupValues, pricingGroupValues=$pricingGroupValues, productId=$productId, productTags=$productTags, recurringCommitIds=$recurringCommitIds, additionalProperties=$additionalProperties}" + } + + class OverwriteRate + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val rateType: JsonField, + private val creditType: JsonField, + private val customRate: JsonField, + private val isProrated: JsonField, + private val price: JsonField, + private val quantity: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("credit_type") + @ExcludeMissing + creditType: JsonField = JsonMissing.of(), + @JsonProperty("custom_rate") + @ExcludeMissing + customRate: JsonField = JsonMissing.of(), + @JsonProperty("is_prorated") + @ExcludeMissing + isProrated: JsonField = JsonMissing.of(), + @JsonProperty("price") + @ExcludeMissing + price: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this( + rateType, + creditType, + customRate, + isProrated, + price, + quantity, + tiers, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException 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 rateType(): RateType = rateType.getRequired("rate_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun creditType(): Optional = + creditType.getOptional("credit_type") + + /** + * Only set for CUSTOM rate_type. This field is interpreted by custom rate + * processors. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun customRate(): Optional = customRate.getOptional("custom_rate") + + /** + * Default proration configuration. Only valid for SUBSCRIPTION rate_type. Must + * be set to true. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun isProrated(): Optional = isProrated.getOptional("is_prorated") + + /** + * Default price. For FLAT rate_type, this must be >=0. For PERCENTAGE + * rate_type, this is a decimal fraction, e.g. use 0.1 for 10%; this must be >=0 + * and <=1. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun price(): Optional = price.getOptional("price") + + /** + * Default quantity. For SUBSCRIPTION rate_type, this must be >=0. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Only set for TIERED rate_type. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun tiers(): Optional> = tiers.getOptional("tiers") + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [creditType]. + * + * Unlike [creditType], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type") + @ExcludeMissing + fun _creditType(): JsonField = creditType + + /** + * Returns the raw JSON value of [customRate]. + * + * Unlike [customRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("custom_rate") + @ExcludeMissing + fun _customRate(): JsonField = customRate + + /** + * Returns the raw JSON value of [isProrated]. + * + * Unlike [isProrated], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("is_prorated") + @ExcludeMissing + fun _isProrated(): JsonField = isProrated + + /** + * Returns the raw JSON value of [price]. + * + * Unlike [price], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("price") @ExcludeMissing fun _price(): JsonField = price + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [tiers]. + * + * Unlike [tiers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tiers") + @ExcludeMissing + fun _tiers(): JsonField> = tiers + + @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 + * [OverwriteRate]. + * + * The following fields are required: + * ```java + * .rateType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OverwriteRate]. */ + class Builder internal constructor() { + + private var rateType: JsonField? = null + private var creditType: JsonField = JsonMissing.of() + private var customRate: JsonField = JsonMissing.of() + private var isProrated: JsonField = JsonMissing.of() + private var price: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(overwriteRate: OverwriteRate) = apply { + rateType = overwriteRate.rateType + creditType = overwriteRate.creditType + customRate = overwriteRate.customRate + isProrated = overwriteRate.isProrated + price = overwriteRate.price + quantity = overwriteRate.quantity + tiers = overwriteRate.tiers.map { it.toMutableList() } + additionalProperties = overwriteRate.additionalProperties.toMutableMap() + } + + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { + this.rateType = rateType + } + + fun creditType(creditType: CreditTypeData) = + creditType(JsonField.of(creditType)) + + /** + * Sets [Builder.creditType] to an arbitrary JSON value. + * + * You should usually call [Builder.creditType] with a well-typed + * [CreditTypeData] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun creditType(creditType: JsonField) = apply { + this.creditType = creditType + } + + /** + * Only set for CUSTOM rate_type. This field is interpreted by custom rate + * processors. + */ + fun customRate(customRate: CustomRate) = + customRate(JsonField.of(customRate)) + + /** + * Sets [Builder.customRate] to an arbitrary JSON value. + * + * You should usually call [Builder.customRate] with a well-typed + * [CustomRate] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun customRate(customRate: JsonField) = apply { + this.customRate = customRate + } + + /** + * Default proration configuration. Only valid for SUBSCRIPTION rate_type. + * Must be set to true. + */ + fun isProrated(isProrated: Boolean) = isProrated(JsonField.of(isProrated)) + + /** + * Sets [Builder.isProrated] to an arbitrary JSON value. + * + * You should usually call [Builder.isProrated] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun isProrated(isProrated: JsonField) = apply { + this.isProrated = isProrated + } + + /** + * Default price. For FLAT rate_type, this must be >=0. For PERCENTAGE + * rate_type, this is a decimal fraction, e.g. use 0.1 for 10%; this must + * be >=0 and <=1. + */ + fun price(price: Double) = price(JsonField.of(price)) + + /** + * Sets [Builder.price] to an arbitrary JSON value. + * + * You should usually call [Builder.price] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun price(price: JsonField) = apply { this.price = price } + + /** Default quantity. For SUBSCRIPTION rate_type, this must be >=0. */ + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + /** Only set for TIERED rate_type. */ + fun tiers(tiers: List) = tiers(JsonField.of(tiers)) + + /** + * Sets [Builder.tiers] to an arbitrary JSON value. + * + * You should usually call [Builder.tiers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tiers(tiers: JsonField>) = apply { + this.tiers = tiers.map { it.toMutableList() } + } + + /** + * Adds a single [Tier] to [tiers]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addTier(tier: Tier) = apply { + tiers = + (tiers ?: JsonField.of(mutableListOf())).also { + checkKnown("tiers", it).add(tier) + } + } + + 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 [OverwriteRate]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .rateType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OverwriteRate = + OverwriteRate( + checkRequired("rateType", rateType), + creditType, + customRate, + isProrated, + price, + quantity, + (tiers ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): OverwriteRate = apply { + if (validated) { + return@apply + } + + rateType().validate() + creditType().ifPresent { it.validate() } + customRate().ifPresent { it.validate() } + isProrated() + price() + quantity() + tiers().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (creditType.asKnown().getOrNull()?.validity() ?: 0) + + (customRate.asKnown().getOrNull()?.validity() ?: 0) + + (if (isProrated.asKnown().isPresent) 1 else 0) + + (if (price.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (tiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class RateType + @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 FLAT = of("FLAT") + + @JvmField val PERCENTAGE = of("PERCENTAGE") + + @JvmField val SUBSCRIPTION = of("SUBSCRIPTION") + + @JvmField val TIERED = of("TIERED") + + @JvmField val TIERED_PERCENTAGE = of("TIERED_PERCENTAGE") + + @JvmField val CUSTOM = of("CUSTOM") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + FLAT, + PERCENTAGE, + SUBSCRIPTION, + TIERED, + TIERED_PERCENTAGE, + CUSTOM, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + FLAT, + PERCENTAGE, + SUBSCRIPTION, + TIERED, + TIERED_PERCENTAGE, + CUSTOM, + /** + * An enum member indicating that [RateType] 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) { + FLAT -> Value.FLAT + PERCENTAGE -> Value.PERCENTAGE + SUBSCRIPTION -> Value.SUBSCRIPTION + TIERED -> Value.TIERED + TIERED_PERCENTAGE -> Value.TIERED_PERCENTAGE + CUSTOM -> Value.CUSTOM + 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + FLAT -> Known.FLAT + PERCENTAGE -> Known.PERCENTAGE + SUBSCRIPTION -> Known.SUBSCRIPTION + TIERED -> Known.TIERED + TIERED_PERCENTAGE -> Known.TIERED_PERCENTAGE + CUSTOM -> Known.CUSTOM + else -> + throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Only set for CUSTOM rate_type. This field is interpreted by custom rate + * processors. + */ + class CustomRate + @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 + * [CustomRate]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomRate]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customRate: CustomRate) = apply { + additionalProperties = + customRate.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 [CustomRate]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): CustomRate = CustomRate(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomRate = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 CustomRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomRate{additionalProperties=$additionalProperties}" + } + + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val price: JsonField, + private val size: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("price") + @ExcludeMissing + price: JsonField = JsonMissing.of(), + @JsonProperty("size") + @ExcludeMissing + size: JsonField = JsonMissing.of(), + ) : this(price, size, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 price(): Double = price.getRequired("price") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun size(): Optional = size.getOptional("size") + + /** + * Returns the raw JSON value of [price]. + * + * Unlike [price], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("price") + @ExcludeMissing + fun _price(): JsonField = price + + /** + * Returns the raw JSON value of [size]. + * + * Unlike [size], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("size") @ExcludeMissing fun _size(): JsonField = size + + @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 [Tier]. + * + * The following fields are required: + * ```java + * .price() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var price: JsonField? = null + private var size: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(tier: Tier) = apply { + price = tier.price + size = tier.size + additionalProperties = tier.additionalProperties.toMutableMap() + } + + fun price(price: Double) = price(JsonField.of(price)) + + /** + * Sets [Builder.price] to an arbitrary JSON value. + * + * You should usually call [Builder.price] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun price(price: JsonField) = apply { this.price = price } + + fun size(size: Double) = size(JsonField.of(size)) + + /** + * Sets [Builder.size] to an arbitrary JSON value. + * + * You should usually call [Builder.size] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun size(size: JsonField) = apply { this.size = size } + + 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .price() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("price", price), + size, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + price() + size() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (price.asKnown().isPresent) 1 else 0) + + (if (size.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + price == other.price && + size == other.size && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(price, size, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{price=$price, size=$size, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OverwriteRate && + rateType == other.rateType && + creditType == other.creditType && + customRate == other.customRate && + isProrated == other.isProrated && + price == other.price && + quantity == other.quantity && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + rateType, + creditType, + customRate, + isProrated, + price, + quantity, + tiers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OverwriteRate{rateType=$rateType, creditType=$creditType, customRate=$customRate, isProrated=$isProrated, price=$price, quantity=$quantity, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + class Target + @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 COMMIT_RATE = of("COMMIT_RATE") + + @JvmField val LIST_RATE = of("LIST_RATE") + + @JvmStatic fun of(value: String) = Target(JsonField.of(value)) + } + + /** An enum containing [Target]'s known values. */ + enum class Known { + COMMIT_RATE, + LIST_RATE, + } + + /** + * An enum containing [Target]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Target] 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 { + COMMIT_RATE, + LIST_RATE, + /** + * An enum member indicating that [Target] 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) { + COMMIT_RATE -> Value.COMMIT_RATE + LIST_RATE -> Value.LIST_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_RATE -> Known.COMMIT_RATE + LIST_RATE -> Known.LIST_RATE + else -> throw MetronomeInvalidDataException("Unknown Target: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Target = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Target && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val OVERWRITE = of("OVERWRITE") + + @JvmField val MULTIPLIER = of("MULTIPLIER") + + @JvmField val TIERED = of("TIERED") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + OVERWRITE, + MULTIPLIER, + TIERED, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + OVERWRITE, + MULTIPLIER, + TIERED, + /** + * An enum member indicating that [Type] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + OVERWRITE -> Value.OVERWRITE + MULTIPLIER -> Value.MULTIPLIER + TIERED -> Value.TIERED + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + OVERWRITE -> Known.OVERWRITE + MULTIPLIER -> Known.MULTIPLIER + TIERED -> Known.TIERED + else -> throw MetronomeInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddOverride && + id == other.id && + createdAt == other.createdAt && + startingAt == other.startingAt && + applicableProductTags == other.applicableProductTags && + endingBefore == other.endingBefore && + entitled == other.entitled && + isCommitSpecific == other.isCommitSpecific && + multiplier == other.multiplier && + overrideSpecifiers == other.overrideSpecifiers && + overrideTiers == other.overrideTiers && + overwriteRate == other.overwriteRate && + priority == other.priority && + product == other.product && + target == other.target && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + startingAt, + applicableProductTags, + endingBefore, + entitled, + isCommitSpecific, + multiplier, + overrideSpecifiers, + overrideTiers, + overwriteRate, + priority, + product, + target, + type, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddOverride{id=$id, createdAt=$createdAt, startingAt=$startingAt, applicableProductTags=$applicableProductTags, endingBefore=$endingBefore, entitled=$entitled, isCommitSpecific=$isCommitSpecific, multiplier=$multiplier, overrideSpecifiers=$overrideSpecifiers, overrideTiers=$overrideTiers, overwriteRate=$overwriteRate, priority=$priority, product=$product, target=$target, type=$type, additionalProperties=$additionalProperties}" + } + + class AddRecurringCommit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val accessAmount: JsonField, + private val commitDuration: JsonField, + private val priority: JsonField, + private val product: JsonField, + private val rateType: JsonField, + private val startingAt: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val contract: JsonField, + private val description: JsonField, + private val endingBefore: JsonField, + private val hierarchyConfiguration: JsonField, + private val invoiceAmount: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val proration: JsonField, + private val recurrenceFrequency: JsonField, + private val rolloverFraction: JsonField, + private val specifiers: JsonField>, + private val subscriptionConfig: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("access_amount") + @ExcludeMissing + accessAmount: JsonField = JsonMissing.of(), + @JsonProperty("commit_duration") + @ExcludeMissing + commitDuration: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("contract") + @ExcludeMissing + contract: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("invoice_amount") + @ExcludeMissing + invoiceAmount: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("proration") + @ExcludeMissing + proration: JsonField = JsonMissing.of(), + @JsonProperty("recurrence_frequency") + @ExcludeMissing + recurrenceFrequency: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("subscription_config") + @ExcludeMissing + subscriptionConfig: JsonField = + JsonMissing.of(), + ) : this( + id, + accessAmount, + commitDuration, + priority, + product, + rateType, + startingAt, + applicableProductIds, + applicableProductTags, + contract, + description, + endingBefore, + hierarchyConfiguration, + invoiceAmount, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + specifiers, + subscriptionConfig, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException 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") + + /** + * The amount of commit to grant. + * + * @throws MetronomeInvalidDataException 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 accessAmount(): AccessAmount = accessAmount.getRequired("access_amount") + + /** + * The amount of time the created commits will be valid for + * + * @throws MetronomeInvalidDataException 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 commitDuration(): CommitDuration = commitDuration.getRequired("commit_duration") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException 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 priority(): Double = priority.getRequired("priority") + + /** + * @throws MetronomeInvalidDataException 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 product(): Product = product.getRequired("product") + + /** + * Whether the created commits will use the commit rate or list rate + * + * @throws MetronomeInvalidDataException 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 rateType(): RateType = rateType.getRequired("rate_type") + + /** + * Determines the start time for the first commit + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun contract(): Optional = contract.getOptional("contract") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Determines when the contract will stop creating recurring commits. Optional + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * Optional configuration for recurring credit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * The amount the customer should be billed for the commit. Not required. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun invoiceAmount(): Optional = + invoiceAmount.getOptional("invoice_amount") + + /** + * Displayed on invoices. Will be passed through to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * Determines whether the first and last commit will be prorated. If not provided, + * the default is FIRST_AND_LAST (i.e. prorate both the first and last commits). + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun proration(): Optional = proration.getOptional("proration") + + /** + * The frequency at which the recurring commits will be created. If not provided: - + * The commits will be created on the usage invoice frequency. If provided: - The + * period defined in the duration will correspond to this frequency. - Commits will + * be created aligned with the recurring commit's starting_at rather than the usage + * invoice dates. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun recurrenceFrequency(): Optional = + recurrenceFrequency.getOptional("recurrence_frequency") + + /** + * Will be passed down to the individual commits. This controls how much of an + * individual unexpired commit will roll over upon contract transition. Must be + * between 0 and 1. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = + rolloverFraction.getOptional("rollover_fraction") + + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Attach a subscription to the recurring commit/credit. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun subscriptionConfig(): Optional = + subscriptionConfig.getOptional("subscription_config") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [accessAmount]. + * + * Unlike [accessAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_amount") + @ExcludeMissing + fun _accessAmount(): JsonField = accessAmount + + /** + * Returns the raw JSON value of [commitDuration]. + * + * Unlike [commitDuration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("commit_duration") + @ExcludeMissing + fun _commitDuration(): JsonField = commitDuration + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [contract]. + * + * Unlike [contract], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("contract") + @ExcludeMissing + fun _contract(): JsonField = contract + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * Returns the raw JSON value of [invoiceAmount]. + * + * Unlike [invoiceAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_amount") + @ExcludeMissing + fun _invoiceAmount(): JsonField = invoiceAmount + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [proration]. + * + * Unlike [proration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("proration") + @ExcludeMissing + fun _proration(): JsonField = proration + + /** + * Returns the raw JSON value of [recurrenceFrequency]. + * + * Unlike [recurrenceFrequency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("recurrence_frequency") + @ExcludeMissing + fun _recurrenceFrequency(): JsonField = recurrenceFrequency + + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + /** + * Returns the raw JSON value of [subscriptionConfig]. + * + * Unlike [subscriptionConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("subscription_config") + @ExcludeMissing + fun _subscriptionConfig(): JsonField = + subscriptionConfig + + @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 + * [AddRecurringCommit]. + * + * The following fields are required: + * ```java + * .id() + * .accessAmount() + * .commitDuration() + * .priority() + * .product() + * .rateType() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddRecurringCommit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var accessAmount: JsonField? = null + private var commitDuration: JsonField? = null + private var priority: JsonField? = null + private var product: JsonField? = null + private var rateType: JsonField? = null + private var startingAt: JsonField? = null + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var contract: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var invoiceAmount: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var proration: JsonField = JsonMissing.of() + private var recurrenceFrequency: JsonField = + JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var specifiers: JsonField>? = null + private var subscriptionConfig: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addRecurringCommit: AddRecurringCommit) = apply { + id = addRecurringCommit.id + accessAmount = addRecurringCommit.accessAmount + commitDuration = addRecurringCommit.commitDuration + priority = addRecurringCommit.priority + product = addRecurringCommit.product + rateType = addRecurringCommit.rateType + startingAt = addRecurringCommit.startingAt + applicableProductIds = + addRecurringCommit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + addRecurringCommit.applicableProductTags.map { it.toMutableList() } + contract = addRecurringCommit.contract + description = addRecurringCommit.description + endingBefore = addRecurringCommit.endingBefore + hierarchyConfiguration = addRecurringCommit.hierarchyConfiguration + invoiceAmount = addRecurringCommit.invoiceAmount + name = addRecurringCommit.name + netsuiteSalesOrderId = addRecurringCommit.netsuiteSalesOrderId + proration = addRecurringCommit.proration + recurrenceFrequency = addRecurringCommit.recurrenceFrequency + rolloverFraction = addRecurringCommit.rolloverFraction + specifiers = addRecurringCommit.specifiers.map { it.toMutableList() } + subscriptionConfig = addRecurringCommit.subscriptionConfig + additionalProperties = + addRecurringCommit.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 } + + /** The amount of commit to grant. */ + fun accessAmount(accessAmount: AccessAmount) = + accessAmount(JsonField.of(accessAmount)) + + /** + * Sets [Builder.accessAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.accessAmount] with a well-typed + * [AccessAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun accessAmount(accessAmount: JsonField) = apply { + this.accessAmount = accessAmount + } + + /** The amount of time the created commits will be valid for */ + fun commitDuration(commitDuration: CommitDuration) = + commitDuration(JsonField.of(commitDuration)) + + /** + * Sets [Builder.commitDuration] to an arbitrary JSON value. + * + * You should usually call [Builder.commitDuration] with a well-typed + * [CommitDuration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun commitDuration(commitDuration: JsonField) = apply { + this.commitDuration = commitDuration + } + + /** Will be passed down to the individual commits */ + fun priority(priority: Double) = priority(JsonField.of(priority)) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + /** Whether the created commits will use the commit rate or list rate */ + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + /** Determines the start time for the first commit */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + /** Will be passed down to the individual commits */ + fun applicableProductIds(applicableProductIds: List) = + applicableProductIds(JsonField.of(applicableProductIds)) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + /** Will be passed down to the individual commits */ + fun applicableProductTags(applicableProductTags: List) = + applicableProductTags(JsonField.of(applicableProductTags)) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun contract(contract: Contract) = contract(JsonField.of(contract)) + + /** + * Sets [Builder.contract] to an arbitrary JSON value. + * + * You should usually call [Builder.contract] with a well-typed [Contract] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun contract(contract: JsonField) = apply { this.contract = contract } + + /** Will be passed down to the individual commits */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** + * Determines when the contract will stop creating recurring commits. Optional + */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** Optional configuration for recurring credit hierarchy access control */ + fun hierarchyConfiguration( + hierarchyConfiguration: CommitHierarchyConfiguration + ) = hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + /** The amount the customer should be billed for the commit. Not required. */ + fun invoiceAmount(invoiceAmount: InvoiceAmount) = + invoiceAmount(JsonField.of(invoiceAmount)) + + /** + * Sets [Builder.invoiceAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceAmount] with a well-typed + * [InvoiceAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun invoiceAmount(invoiceAmount: JsonField) = apply { + this.invoiceAmount = invoiceAmount + } + + /** Displayed on invoices. Will be passed through to the individual commits */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Will be passed down to the individual commits */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String) = + netsuiteSalesOrderId(JsonField.of(netsuiteSalesOrderId)) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** + * Determines whether the first and last commit will be prorated. If not + * provided, the default is FIRST_AND_LAST (i.e. prorate both the first and last + * commits). + */ + fun proration(proration: Proration) = proration(JsonField.of(proration)) + + /** + * Sets [Builder.proration] to an arbitrary JSON value. + * + * You should usually call [Builder.proration] with a well-typed [Proration] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun proration(proration: JsonField) = apply { + this.proration = proration + } + + /** + * The frequency at which the recurring commits will be created. If not + * provided: - The commits will be created on the usage invoice frequency. If + * provided: - The period defined in the duration will correspond to this + * frequency. - Commits will be created aligned with the recurring commit's + * starting_at rather than the usage invoice dates. + */ + fun recurrenceFrequency(recurrenceFrequency: RecurrenceFrequency) = + recurrenceFrequency(JsonField.of(recurrenceFrequency)) + + /** + * Sets [Builder.recurrenceFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.recurrenceFrequency] with a well-typed + * [RecurrenceFrequency] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun recurrenceFrequency(recurrenceFrequency: JsonField) = + apply { + this.recurrenceFrequency = recurrenceFrequency + } + + /** + * Will be passed down to the individual commits. This controls how much of an + * individual unexpired commit will roll over upon contract transition. Must be + * between 0 and 1. + */ + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(JsonField.of(rolloverFraction)) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. + */ + fun specifiers(specifiers: List) = + specifiers(JsonField.of(specifiers)) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifier] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpecifier(specifier: CommitSpecifier) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + /** Attach a subscription to the recurring commit/credit. */ + fun subscriptionConfig(subscriptionConfig: RecurringCommitSubscriptionConfig) = + subscriptionConfig(JsonField.of(subscriptionConfig)) + + /** + * Sets [Builder.subscriptionConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.subscriptionConfig] with a well-typed + * [RecurringCommitSubscriptionConfig] value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun subscriptionConfig( + subscriptionConfig: JsonField + ) = apply { this.subscriptionConfig = subscriptionConfig } + + 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 [AddRecurringCommit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .accessAmount() + * .commitDuration() + * .priority() + * .product() + * .rateType() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddRecurringCommit = + AddRecurringCommit( + checkRequired("id", id), + checkRequired("accessAmount", accessAmount), + checkRequired("commitDuration", commitDuration), + checkRequired("priority", priority), + checkRequired("product", product), + checkRequired("rateType", rateType), + checkRequired("startingAt", startingAt), + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + contract, + description, + endingBefore, + hierarchyConfiguration, + invoiceAmount, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + subscriptionConfig, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddRecurringCommit = apply { + if (validated) { + return@apply + } + + id() + accessAmount().validate() + commitDuration().validate() + priority() + product().validate() + rateType().validate() + startingAt() + applicableProductIds() + applicableProductTags() + contract().ifPresent { it.validate() } + description() + endingBefore() + hierarchyConfiguration().ifPresent { it.validate() } + invoiceAmount().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + proration().ifPresent { it.validate() } + recurrenceFrequency().ifPresent { it.validate() } + rolloverFraction() + specifiers().ifPresent { it.forEach { it.validate() } } + subscriptionConfig().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (accessAmount.asKnown().getOrNull()?.validity() ?: 0) + + (commitDuration.asKnown().getOrNull()?.validity() ?: 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (contract.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (invoiceAmount.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (proration.asKnown().getOrNull()?.validity() ?: 0) + + (recurrenceFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (subscriptionConfig.asKnown().getOrNull()?.validity() ?: 0) + + /** The amount of commit to grant. */ + class AccessAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditTypeId: JsonField, + private val unitPrice: JsonField, + private val quantity: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + ) : this(creditTypeId, unitPrice, quantity, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 unitPrice(): Double = unitPrice.getRequired("unit_price") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + @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 [AccessAmount]. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .unitPrice() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccessAmount]. */ + class Builder internal constructor() { + + private var creditTypeId: JsonField? = null + private var unitPrice: JsonField? = null + private var quantity: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(accessAmount: AccessAmount) = apply { + creditTypeId = accessAmount.creditTypeId + unitPrice = accessAmount.unitPrice + quantity = accessAmount.quantity + additionalProperties = accessAmount.additionalProperties.toMutableMap() + } + + fun creditTypeId(creditTypeId: String) = + creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + 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 [AccessAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AccessAmount = + AccessAmount( + checkRequired("creditTypeId", creditTypeId), + checkRequired("unitPrice", unitPrice), + quantity, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AccessAmount = apply { + if (validated) { + return@apply + } + + creditTypeId() + unitPrice() + quantity() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (creditTypeId.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccessAmount && + creditTypeId == other.creditTypeId && + unitPrice == other.unitPrice && + quantity == other.quantity && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(creditTypeId, unitPrice, quantity, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessAmount{creditTypeId=$creditTypeId, unitPrice=$unitPrice, quantity=$quantity, additionalProperties=$additionalProperties}" + } + + /** The amount of time the created commits will be valid for */ + class CommitDuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val value: JsonField, + private val unit: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + @JsonProperty("unit") + @ExcludeMissing + unit: JsonField = JsonMissing.of(), + ) : this(value, unit, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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(): Double = value.getRequired("value") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unit(): Optional = unit.getOptional("unit") + + /** + * 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 + + /** + * Returns the raw JSON value of [unit]. + * + * Unlike [unit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit") @ExcludeMissing fun _unit(): JsonField = unit + + @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 + * [CommitDuration]. + * + * The following fields are required: + * ```java + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CommitDuration]. */ + class Builder internal constructor() { + + private var value: JsonField? = null + private var unit: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(commitDuration: CommitDuration) = apply { + value = commitDuration.value + unit = commitDuration.unit + additionalProperties = + commitDuration.additionalProperties.toMutableMap() + } + + fun value(value: Double) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Double] 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 unit(unit: Unit) = unit(JsonField.of(unit)) + + /** + * Sets [Builder.unit] to an arbitrary JSON value. + * + * You should usually call [Builder.unit] with a well-typed [Unit] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unit(unit: JsonField) = apply { this.unit = unit } + + 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 [CommitDuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CommitDuration = + CommitDuration( + checkRequired("value", value), + unit, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CommitDuration = apply { + if (validated) { + return@apply + } + + value() + unit().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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.asKnown().isPresent) 1 else 0) + + (unit.asKnown().getOrNull()?.validity() ?: 0) + + class Unit + @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 PERIODS = of("PERIODS") + + @JvmStatic fun of(value: String) = Unit(JsonField.of(value)) + } + + /** An enum containing [Unit]'s known values. */ + enum class Known { + PERIODS + } + + /** + * An enum containing [Unit]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Unit] 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 { + PERIODS, + /** + * An enum member indicating that [Unit] 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) { + PERIODS -> Value.PERIODS + 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + PERIODS -> Known.PERIODS + else -> throw MetronomeInvalidDataException("Unknown Unit: $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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Unit = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Unit && 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 CommitDuration && + value == other.value && + unit == other.unit && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(value, unit, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CommitDuration{value=$value, unit=$unit, additionalProperties=$additionalProperties}" + } + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + /** Whether the created commits will use the commit rate or list rate */ + class RateType + @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 COMMIT_RATE = of("COMMIT_RATE") + + @JvmField val LIST_RATE = of("LIST_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + COMMIT_RATE, + LIST_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + COMMIT_RATE, + LIST_RATE, + /** + * An enum member indicating that [RateType] 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) { + COMMIT_RATE -> Value.COMMIT_RATE + LIST_RATE -> Value.LIST_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_RATE -> Known.COMMIT_RATE + LIST_RATE -> Known.LIST_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Contract + @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 MetronomeInvalidDataException 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 [Contract]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Contract]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(contract: Contract) = apply { + id = contract.id + additionalProperties = contract.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 [Contract]. + * + * 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(): Contract = + Contract(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Contract = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Contract && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Contract{id=$id, additionalProperties=$additionalProperties}" + } + + /** The amount the customer should be billed for the commit. Not required. */ + class InvoiceAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditTypeId: JsonField, + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(creditTypeId, quantity, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 quantity(): Double = quantity.getRequired("quantity") + + /** + * @throws MetronomeInvalidDataException 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 unitPrice(): Double = unitPrice.getRequired("unit_price") + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [InvoiceAmount]. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .quantity() + * .unitPrice() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InvoiceAmount]. */ + class Builder internal constructor() { + + private var creditTypeId: JsonField? = null + private var quantity: JsonField? = null + private var unitPrice: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(invoiceAmount: InvoiceAmount) = apply { + creditTypeId = invoiceAmount.creditTypeId + quantity = invoiceAmount.quantity + unitPrice = invoiceAmount.unitPrice + additionalProperties = invoiceAmount.additionalProperties.toMutableMap() + } + + fun creditTypeId(creditTypeId: String) = + creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [InvoiceAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .quantity() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InvoiceAmount = + InvoiceAmount( + checkRequired("creditTypeId", creditTypeId), + checkRequired("quantity", quantity), + checkRequired("unitPrice", unitPrice), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InvoiceAmount = apply { + if (validated) { + return@apply + } + + creditTypeId() + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (creditTypeId.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InvoiceAmount && + creditTypeId == other.creditTypeId && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(creditTypeId, quantity, unitPrice, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InvoiceAmount{creditTypeId=$creditTypeId, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + /** + * Determines whether the first and last commit will be prorated. If not provided, + * the default is FIRST_AND_LAST (i.e. prorate both the first and last commits). + */ + class Proration + @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 FIRST = of("FIRST") + + @JvmField val LAST = of("LAST") + + @JvmField val FIRST_AND_LAST = of("FIRST_AND_LAST") + + @JvmStatic fun of(value: String) = Proration(JsonField.of(value)) + } + + /** An enum containing [Proration]'s known values. */ + enum class Known { + NONE, + FIRST, + LAST, + FIRST_AND_LAST, + } + + /** + * An enum containing [Proration]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Proration] 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, + FIRST, + LAST, + FIRST_AND_LAST, + /** + * An enum member indicating that [Proration] 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 + FIRST -> Value.FIRST + LAST -> Value.LAST + FIRST_AND_LAST -> Value.FIRST_AND_LAST + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + NONE -> Known.NONE + FIRST -> Known.FIRST + LAST -> Known.LAST + FIRST_AND_LAST -> Known.FIRST_AND_LAST + else -> throw MetronomeInvalidDataException("Unknown Proration: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Proration = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Proration && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * The frequency at which the recurring commits will be created. If not provided: - + * The commits will be created on the usage invoice frequency. If provided: - The + * period defined in the duration will correspond to this frequency. - Commits will + * be created aligned with the recurring commit's starting_at rather than the usage + * invoice dates. + */ + class RecurrenceFrequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = RecurrenceFrequency(JsonField.of(value)) + } + + /** An enum containing [RecurrenceFrequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [RecurrenceFrequency]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [RecurrenceFrequency] 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 { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [RecurrenceFrequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> + throw MetronomeInvalidDataException( + "Unknown RecurrenceFrequency: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RecurrenceFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RecurrenceFrequency && 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 AddRecurringCommit && + id == other.id && + accessAmount == other.accessAmount && + commitDuration == other.commitDuration && + priority == other.priority && + product == other.product && + rateType == other.rateType && + startingAt == other.startingAt && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + contract == other.contract && + description == other.description && + endingBefore == other.endingBefore && + hierarchyConfiguration == other.hierarchyConfiguration && + invoiceAmount == other.invoiceAmount && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + proration == other.proration && + recurrenceFrequency == other.recurrenceFrequency && + rolloverFraction == other.rolloverFraction && + specifiers == other.specifiers && + subscriptionConfig == other.subscriptionConfig && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + accessAmount, + commitDuration, + priority, + product, + rateType, + startingAt, + applicableProductIds, + applicableProductTags, + contract, + description, + endingBefore, + hierarchyConfiguration, + invoiceAmount, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + specifiers, + subscriptionConfig, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddRecurringCommit{id=$id, accessAmount=$accessAmount, commitDuration=$commitDuration, priority=$priority, product=$product, rateType=$rateType, startingAt=$startingAt, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, contract=$contract, description=$description, endingBefore=$endingBefore, hierarchyConfiguration=$hierarchyConfiguration, invoiceAmount=$invoiceAmount, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, proration=$proration, recurrenceFrequency=$recurrenceFrequency, rolloverFraction=$rolloverFraction, specifiers=$specifiers, subscriptionConfig=$subscriptionConfig, additionalProperties=$additionalProperties}" + } + + class AddRecurringCredit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val accessAmount: JsonField, + private val commitDuration: JsonField, + private val priority: JsonField, + private val product: JsonField, + private val rateType: JsonField, + private val startingAt: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val contract: JsonField, + private val description: JsonField, + private val endingBefore: JsonField, + private val hierarchyConfiguration: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val proration: JsonField, + private val recurrenceFrequency: JsonField, + private val rolloverFraction: JsonField, + private val specifiers: JsonField>, + private val subscriptionConfig: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("access_amount") + @ExcludeMissing + accessAmount: JsonField = JsonMissing.of(), + @JsonProperty("commit_duration") + @ExcludeMissing + commitDuration: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("contract") + @ExcludeMissing + contract: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("proration") + @ExcludeMissing + proration: JsonField = JsonMissing.of(), + @JsonProperty("recurrence_frequency") + @ExcludeMissing + recurrenceFrequency: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + @JsonProperty("subscription_config") + @ExcludeMissing + subscriptionConfig: JsonField = + JsonMissing.of(), + ) : this( + id, + accessAmount, + commitDuration, + priority, + product, + rateType, + startingAt, + applicableProductIds, + applicableProductTags, + contract, + description, + endingBefore, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + specifiers, + subscriptionConfig, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException 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") + + /** + * The amount of commit to grant. + * + * @throws MetronomeInvalidDataException 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 accessAmount(): AccessAmount = accessAmount.getRequired("access_amount") + + /** + * The amount of time the created commits will be valid for + * + * @throws MetronomeInvalidDataException 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 commitDuration(): CommitDuration = commitDuration.getRequired("commit_duration") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException 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 priority(): Double = priority.getRequired("priority") + + /** + * @throws MetronomeInvalidDataException 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 product(): Product = product.getRequired("product") + + /** + * Whether the created commits will use the commit rate or list rate + * + * @throws MetronomeInvalidDataException 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 rateType(): RateType = rateType.getRequired("rate_type") + + /** + * Determines the start time for the first commit + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun contract(): Optional = contract.getOptional("contract") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Determines when the contract will stop creating recurring commits. Optional + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * Optional configuration for recurring credit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * Displayed on invoices. Will be passed through to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Will be passed down to the individual commits + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * Determines whether the first and last commit will be prorated. If not provided, + * the default is FIRST_AND_LAST (i.e. prorate both the first and last commits). + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun proration(): Optional = proration.getOptional("proration") + + /** + * The frequency at which the recurring commits will be created. If not provided: - + * The commits will be created on the usage invoice frequency. If provided: - The + * period defined in the duration will correspond to this frequency. - Commits will + * be created aligned with the recurring commit's starting_at rather than the usage + * invoice dates. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun recurrenceFrequency(): Optional = + recurrenceFrequency.getOptional("recurrence_frequency") + + /** + * Will be passed down to the individual commits. This controls how much of an + * individual unexpired commit will roll over upon contract transition. Must be + * between 0 and 1. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = + rolloverFraction.getOptional("rollover_fraction") + + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Attach a subscription to the recurring commit/credit. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun subscriptionConfig(): Optional = + subscriptionConfig.getOptional("subscription_config") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [accessAmount]. + * + * Unlike [accessAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_amount") + @ExcludeMissing + fun _accessAmount(): JsonField = accessAmount + + /** + * Returns the raw JSON value of [commitDuration]. + * + * Unlike [commitDuration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("commit_duration") + @ExcludeMissing + fun _commitDuration(): JsonField = commitDuration + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [contract]. + * + * Unlike [contract], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("contract") + @ExcludeMissing + fun _contract(): JsonField = contract + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [proration]. + * + * Unlike [proration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("proration") + @ExcludeMissing + fun _proration(): JsonField = proration + + /** + * Returns the raw JSON value of [recurrenceFrequency]. + * + * Unlike [recurrenceFrequency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("recurrence_frequency") + @ExcludeMissing + fun _recurrenceFrequency(): JsonField = recurrenceFrequency + + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + /** + * Returns the raw JSON value of [subscriptionConfig]. + * + * Unlike [subscriptionConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("subscription_config") + @ExcludeMissing + fun _subscriptionConfig(): JsonField = + subscriptionConfig + + @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 + * [AddRecurringCredit]. + * + * The following fields are required: + * ```java + * .id() + * .accessAmount() + * .commitDuration() + * .priority() + * .product() + * .rateType() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddRecurringCredit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var accessAmount: JsonField? = null + private var commitDuration: JsonField? = null + private var priority: JsonField? = null + private var product: JsonField? = null + private var rateType: JsonField? = null + private var startingAt: JsonField? = null + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var contract: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var proration: JsonField = JsonMissing.of() + private var recurrenceFrequency: JsonField = + JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var specifiers: JsonField>? = null + private var subscriptionConfig: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addRecurringCredit: AddRecurringCredit) = apply { + id = addRecurringCredit.id + accessAmount = addRecurringCredit.accessAmount + commitDuration = addRecurringCredit.commitDuration + priority = addRecurringCredit.priority + product = addRecurringCredit.product + rateType = addRecurringCredit.rateType + startingAt = addRecurringCredit.startingAt + applicableProductIds = + addRecurringCredit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + addRecurringCredit.applicableProductTags.map { it.toMutableList() } + contract = addRecurringCredit.contract + description = addRecurringCredit.description + endingBefore = addRecurringCredit.endingBefore + hierarchyConfiguration = addRecurringCredit.hierarchyConfiguration + name = addRecurringCredit.name + netsuiteSalesOrderId = addRecurringCredit.netsuiteSalesOrderId + proration = addRecurringCredit.proration + recurrenceFrequency = addRecurringCredit.recurrenceFrequency + rolloverFraction = addRecurringCredit.rolloverFraction + specifiers = addRecurringCredit.specifiers.map { it.toMutableList() } + subscriptionConfig = addRecurringCredit.subscriptionConfig + additionalProperties = + addRecurringCredit.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 } + + /** The amount of commit to grant. */ + fun accessAmount(accessAmount: AccessAmount) = + accessAmount(JsonField.of(accessAmount)) + + /** + * Sets [Builder.accessAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.accessAmount] with a well-typed + * [AccessAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun accessAmount(accessAmount: JsonField) = apply { + this.accessAmount = accessAmount + } + + /** The amount of time the created commits will be valid for */ + fun commitDuration(commitDuration: CommitDuration) = + commitDuration(JsonField.of(commitDuration)) + + /** + * Sets [Builder.commitDuration] to an arbitrary JSON value. + * + * You should usually call [Builder.commitDuration] with a well-typed + * [CommitDuration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun commitDuration(commitDuration: JsonField) = apply { + this.commitDuration = commitDuration + } + + /** Will be passed down to the individual commits */ + fun priority(priority: Double) = priority(JsonField.of(priority)) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + /** Whether the created commits will use the commit rate or list rate */ + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + /** Determines the start time for the first commit */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + /** Will be passed down to the individual commits */ + fun applicableProductIds(applicableProductIds: List) = + applicableProductIds(JsonField.of(applicableProductIds)) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + /** Will be passed down to the individual commits */ + fun applicableProductTags(applicableProductTags: List) = + applicableProductTags(JsonField.of(applicableProductTags)) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun contract(contract: Contract) = contract(JsonField.of(contract)) + + /** + * Sets [Builder.contract] to an arbitrary JSON value. + * + * You should usually call [Builder.contract] with a well-typed [Contract] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun contract(contract: JsonField) = apply { this.contract = contract } + + /** Will be passed down to the individual commits */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** + * Determines when the contract will stop creating recurring commits. Optional + */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** Optional configuration for recurring credit hierarchy access control */ + fun hierarchyConfiguration( + hierarchyConfiguration: CommitHierarchyConfiguration + ) = hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + /** Displayed on invoices. Will be passed through to the individual commits */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Will be passed down to the individual commits */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String) = + netsuiteSalesOrderId(JsonField.of(netsuiteSalesOrderId)) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** + * Determines whether the first and last commit will be prorated. If not + * provided, the default is FIRST_AND_LAST (i.e. prorate both the first and last + * commits). + */ + fun proration(proration: Proration) = proration(JsonField.of(proration)) + + /** + * Sets [Builder.proration] to an arbitrary JSON value. + * + * You should usually call [Builder.proration] with a well-typed [Proration] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun proration(proration: JsonField) = apply { + this.proration = proration + } + + /** + * The frequency at which the recurring commits will be created. If not + * provided: - The commits will be created on the usage invoice frequency. If + * provided: - The period defined in the duration will correspond to this + * frequency. - Commits will be created aligned with the recurring commit's + * starting_at rather than the usage invoice dates. + */ + fun recurrenceFrequency(recurrenceFrequency: RecurrenceFrequency) = + recurrenceFrequency(JsonField.of(recurrenceFrequency)) + + /** + * Sets [Builder.recurrenceFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.recurrenceFrequency] with a well-typed + * [RecurrenceFrequency] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun recurrenceFrequency(recurrenceFrequency: JsonField) = + apply { + this.recurrenceFrequency = recurrenceFrequency + } + + /** + * Will be passed down to the individual commits. This controls how much of an + * individual unexpired commit will roll over upon contract transition. Must be + * between 0 and 1. + */ + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(JsonField.of(rolloverFraction)) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. + */ + fun specifiers(specifiers: List) = + specifiers(JsonField.of(specifiers)) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifier] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpecifier(specifier: CommitSpecifier) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + /** Attach a subscription to the recurring commit/credit. */ + fun subscriptionConfig(subscriptionConfig: RecurringCommitSubscriptionConfig) = + subscriptionConfig(JsonField.of(subscriptionConfig)) + + /** + * Sets [Builder.subscriptionConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.subscriptionConfig] with a well-typed + * [RecurringCommitSubscriptionConfig] value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun subscriptionConfig( + subscriptionConfig: JsonField + ) = apply { this.subscriptionConfig = subscriptionConfig } + + 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 [AddRecurringCredit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .accessAmount() + * .commitDuration() + * .priority() + * .product() + * .rateType() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddRecurringCredit = + AddRecurringCredit( + checkRequired("id", id), + checkRequired("accessAmount", accessAmount), + checkRequired("commitDuration", commitDuration), + checkRequired("priority", priority), + checkRequired("product", product), + checkRequired("rateType", rateType), + checkRequired("startingAt", startingAt), + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + contract, + description, + endingBefore, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + subscriptionConfig, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddRecurringCredit = apply { + if (validated) { + return@apply + } + + id() + accessAmount().validate() + commitDuration().validate() + priority() + product().validate() + rateType().validate() + startingAt() + applicableProductIds() + applicableProductTags() + contract().ifPresent { it.validate() } + description() + endingBefore() + hierarchyConfiguration().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + proration().ifPresent { it.validate() } + recurrenceFrequency().ifPresent { it.validate() } + rolloverFraction() + specifiers().ifPresent { it.forEach { it.validate() } } + subscriptionConfig().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (accessAmount.asKnown().getOrNull()?.validity() ?: 0) + + (commitDuration.asKnown().getOrNull()?.validity() ?: 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (contract.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (proration.asKnown().getOrNull()?.validity() ?: 0) + + (recurrenceFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (subscriptionConfig.asKnown().getOrNull()?.validity() ?: 0) + + /** The amount of commit to grant. */ + class AccessAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditTypeId: JsonField, + private val unitPrice: JsonField, + private val quantity: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + ) : this(creditTypeId, unitPrice, quantity, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 creditTypeId(): String = creditTypeId.getRequired("credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 unitPrice(): Double = unitPrice.getRequired("unit_price") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + @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 [AccessAmount]. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .unitPrice() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccessAmount]. */ + class Builder internal constructor() { + + private var creditTypeId: JsonField? = null + private var unitPrice: JsonField? = null + private var quantity: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(accessAmount: AccessAmount) = apply { + creditTypeId = accessAmount.creditTypeId + unitPrice = accessAmount.unitPrice + quantity = accessAmount.quantity + additionalProperties = accessAmount.additionalProperties.toMutableMap() + } + + fun creditTypeId(creditTypeId: String) = + creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + 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 [AccessAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .creditTypeId() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AccessAmount = + AccessAmount( + checkRequired("creditTypeId", creditTypeId), + checkRequired("unitPrice", unitPrice), + quantity, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AccessAmount = apply { + if (validated) { + return@apply + } + + creditTypeId() + unitPrice() + quantity() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (creditTypeId.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccessAmount && + creditTypeId == other.creditTypeId && + unitPrice == other.unitPrice && + quantity == other.quantity && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(creditTypeId, unitPrice, quantity, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessAmount{creditTypeId=$creditTypeId, unitPrice=$unitPrice, quantity=$quantity, additionalProperties=$additionalProperties}" + } + + /** The amount of time the created commits will be valid for */ + class CommitDuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val value: JsonField, + private val unit: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + @JsonProperty("unit") + @ExcludeMissing + unit: JsonField = JsonMissing.of(), + ) : this(value, unit, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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(): Double = value.getRequired("value") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unit(): Optional = unit.getOptional("unit") + + /** + * 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 + + /** + * Returns the raw JSON value of [unit]. + * + * Unlike [unit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit") @ExcludeMissing fun _unit(): JsonField = unit + + @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 + * [CommitDuration]. + * + * The following fields are required: + * ```java + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CommitDuration]. */ + class Builder internal constructor() { + + private var value: JsonField? = null + private var unit: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(commitDuration: CommitDuration) = apply { + value = commitDuration.value + unit = commitDuration.unit + additionalProperties = + commitDuration.additionalProperties.toMutableMap() + } + + fun value(value: Double) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Double] 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 unit(unit: Unit) = unit(JsonField.of(unit)) + + /** + * Sets [Builder.unit] to an arbitrary JSON value. + * + * You should usually call [Builder.unit] with a well-typed [Unit] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unit(unit: JsonField) = apply { this.unit = unit } + + 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 [CommitDuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CommitDuration = + CommitDuration( + checkRequired("value", value), + unit, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CommitDuration = apply { + if (validated) { + return@apply + } + + value() + unit().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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.asKnown().isPresent) 1 else 0) + + (unit.asKnown().getOrNull()?.validity() ?: 0) + + class Unit + @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 PERIODS = of("PERIODS") + + @JvmStatic fun of(value: String) = Unit(JsonField.of(value)) + } + + /** An enum containing [Unit]'s known values. */ + enum class Known { + PERIODS + } + + /** + * An enum containing [Unit]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Unit] 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 { + PERIODS, + /** + * An enum member indicating that [Unit] 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) { + PERIODS -> Value.PERIODS + 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + PERIODS -> Known.PERIODS + else -> throw MetronomeInvalidDataException("Unknown Unit: $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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Unit = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Unit && 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 CommitDuration && + value == other.value && + unit == other.unit && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(value, unit, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CommitDuration{value=$value, unit=$unit, additionalProperties=$additionalProperties}" + } + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + /** Whether the created commits will use the commit rate or list rate */ + class RateType + @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 COMMIT_RATE = of("COMMIT_RATE") + + @JvmField val LIST_RATE = of("LIST_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + COMMIT_RATE, + LIST_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + COMMIT_RATE, + LIST_RATE, + /** + * An enum member indicating that [RateType] 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) { + COMMIT_RATE -> Value.COMMIT_RATE + LIST_RATE -> Value.LIST_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_RATE -> Known.COMMIT_RATE + LIST_RATE -> Known.LIST_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Contract + @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 MetronomeInvalidDataException 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 [Contract]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Contract]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(contract: Contract) = apply { + id = contract.id + additionalProperties = contract.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 [Contract]. + * + * 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(): Contract = + Contract(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Contract = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Contract && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Contract{id=$id, additionalProperties=$additionalProperties}" + } + + /** + * Determines whether the first and last commit will be prorated. If not provided, + * the default is FIRST_AND_LAST (i.e. prorate both the first and last commits). + */ + class Proration + @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 FIRST = of("FIRST") + + @JvmField val LAST = of("LAST") + + @JvmField val FIRST_AND_LAST = of("FIRST_AND_LAST") + + @JvmStatic fun of(value: String) = Proration(JsonField.of(value)) + } + + /** An enum containing [Proration]'s known values. */ + enum class Known { + NONE, + FIRST, + LAST, + FIRST_AND_LAST, + } + + /** + * An enum containing [Proration]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Proration] 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, + FIRST, + LAST, + FIRST_AND_LAST, + /** + * An enum member indicating that [Proration] 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 + FIRST -> Value.FIRST + LAST -> Value.LAST + FIRST_AND_LAST -> Value.FIRST_AND_LAST + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + NONE -> Known.NONE + FIRST -> Known.FIRST + LAST -> Known.LAST + FIRST_AND_LAST -> Known.FIRST_AND_LAST + else -> throw MetronomeInvalidDataException("Unknown Proration: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Proration = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Proration && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * The frequency at which the recurring commits will be created. If not provided: - + * The commits will be created on the usage invoice frequency. If provided: - The + * period defined in the duration will correspond to this frequency. - Commits will + * be created aligned with the recurring commit's starting_at rather than the usage + * invoice dates. + */ + class RecurrenceFrequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = RecurrenceFrequency(JsonField.of(value)) + } + + /** An enum containing [RecurrenceFrequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [RecurrenceFrequency]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [RecurrenceFrequency] 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 { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [RecurrenceFrequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> + throw MetronomeInvalidDataException( + "Unknown RecurrenceFrequency: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RecurrenceFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RecurrenceFrequency && 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 AddRecurringCredit && + id == other.id && + accessAmount == other.accessAmount && + commitDuration == other.commitDuration && + priority == other.priority && + product == other.product && + rateType == other.rateType && + startingAt == other.startingAt && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + contract == other.contract && + description == other.description && + endingBefore == other.endingBefore && + hierarchyConfiguration == other.hierarchyConfiguration && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + proration == other.proration && + recurrenceFrequency == other.recurrenceFrequency && + rolloverFraction == other.rolloverFraction && + specifiers == other.specifiers && + subscriptionConfig == other.subscriptionConfig && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + accessAmount, + commitDuration, + priority, + product, + rateType, + startingAt, + applicableProductIds, + applicableProductTags, + contract, + description, + endingBefore, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + proration, + recurrenceFrequency, + rolloverFraction, + specifiers, + subscriptionConfig, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddRecurringCredit{id=$id, accessAmount=$accessAmount, commitDuration=$commitDuration, priority=$priority, product=$product, rateType=$rateType, startingAt=$startingAt, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, contract=$contract, description=$description, endingBefore=$endingBefore, hierarchyConfiguration=$hierarchyConfiguration, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, proration=$proration, recurrenceFrequency=$recurrenceFrequency, rolloverFraction=$rolloverFraction, specifiers=$specifiers, subscriptionConfig=$subscriptionConfig, additionalProperties=$additionalProperties}" + } + + class AddResellerRoyalty + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val resellerType: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val awsAccountNumber: JsonField, + private val awsOfferId: JsonField, + private val awsPayerReferenceId: JsonField, + private val endingBefore: JsonField, + private val fraction: JsonField, + private val gcpAccountId: JsonField, + private val gcpOfferId: JsonField, + private val netsuiteResellerId: JsonField, + private val resellerContractValue: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("reseller_type") + @ExcludeMissing + resellerType: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("aws_account_number") + @ExcludeMissing + awsAccountNumber: JsonField = JsonMissing.of(), + @JsonProperty("aws_offer_id") + @ExcludeMissing + awsOfferId: JsonField = JsonMissing.of(), + @JsonProperty("aws_payer_reference_id") + @ExcludeMissing + awsPayerReferenceId: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("fraction") + @ExcludeMissing + fraction: JsonField = JsonMissing.of(), + @JsonProperty("gcp_account_id") + @ExcludeMissing + gcpAccountId: JsonField = JsonMissing.of(), + @JsonProperty("gcp_offer_id") + @ExcludeMissing + gcpOfferId: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_reseller_id") + @ExcludeMissing + netsuiteResellerId: JsonField = JsonMissing.of(), + @JsonProperty("reseller_contract_value") + @ExcludeMissing + resellerContractValue: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this( + resellerType, + applicableProductIds, + applicableProductTags, + awsAccountNumber, + awsOfferId, + awsPayerReferenceId, + endingBefore, + fraction, + gcpAccountId, + gcpOfferId, + netsuiteResellerId, + resellerContractValue, + startingAt, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException 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 resellerType(): ResellerType = resellerType.getRequired("reseller_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun awsAccountNumber(): Optional = + awsAccountNumber.getOptional("aws_account_number") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun awsOfferId(): Optional = awsOfferId.getOptional("aws_offer_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun awsPayerReferenceId(): Optional = + awsPayerReferenceId.getOptional("aws_payer_reference_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun fraction(): Optional = fraction.getOptional("fraction") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun gcpAccountId(): Optional = gcpAccountId.getOptional("gcp_account_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun gcpOfferId(): Optional = gcpOfferId.getOptional("gcp_offer_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteResellerId(): Optional = + netsuiteResellerId.getOptional("netsuite_reseller_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun resellerContractValue(): Optional = + resellerContractValue.getOptional("reseller_contract_value") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun startingAt(): Optional = startingAt.getOptional("starting_at") + + /** + * Returns the raw JSON value of [resellerType]. + * + * Unlike [resellerType], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reseller_type") + @ExcludeMissing + fun _resellerType(): JsonField = resellerType + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [awsAccountNumber]. + * + * Unlike [awsAccountNumber], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("aws_account_number") + @ExcludeMissing + fun _awsAccountNumber(): JsonField = awsAccountNumber + + /** + * Returns the raw JSON value of [awsOfferId]. + * + * Unlike [awsOfferId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("aws_offer_id") + @ExcludeMissing + fun _awsOfferId(): JsonField = awsOfferId + + /** + * Returns the raw JSON value of [awsPayerReferenceId]. + * + * Unlike [awsPayerReferenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("aws_payer_reference_id") + @ExcludeMissing + fun _awsPayerReferenceId(): JsonField = awsPayerReferenceId + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [fraction]. + * + * Unlike [fraction], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("fraction") + @ExcludeMissing + fun _fraction(): JsonField = fraction + + /** + * Returns the raw JSON value of [gcpAccountId]. + * + * Unlike [gcpAccountId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("gcp_account_id") + @ExcludeMissing + fun _gcpAccountId(): JsonField = gcpAccountId + + /** + * Returns the raw JSON value of [gcpOfferId]. + * + * Unlike [gcpOfferId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("gcp_offer_id") + @ExcludeMissing + fun _gcpOfferId(): JsonField = gcpOfferId + + /** + * Returns the raw JSON value of [netsuiteResellerId]. + * + * Unlike [netsuiteResellerId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_reseller_id") + @ExcludeMissing + fun _netsuiteResellerId(): JsonField = netsuiteResellerId + + /** + * Returns the raw JSON value of [resellerContractValue]. + * + * Unlike [resellerContractValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("reseller_contract_value") + @ExcludeMissing + fun _resellerContractValue(): JsonField = resellerContractValue + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [AddResellerRoyalty]. + * + * The following fields are required: + * ```java + * .resellerType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddResellerRoyalty]. */ + class Builder internal constructor() { + + private var resellerType: JsonField? = null + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var awsAccountNumber: JsonField = JsonMissing.of() + private var awsOfferId: JsonField = JsonMissing.of() + private var awsPayerReferenceId: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var fraction: JsonField = JsonMissing.of() + private var gcpAccountId: JsonField = JsonMissing.of() + private var gcpOfferId: JsonField = JsonMissing.of() + private var netsuiteResellerId: JsonField = JsonMissing.of() + private var resellerContractValue: JsonField = JsonMissing.of() + private var startingAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addResellerRoyalty: AddResellerRoyalty) = apply { + resellerType = addResellerRoyalty.resellerType + applicableProductIds = + addResellerRoyalty.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + addResellerRoyalty.applicableProductTags.map { it.toMutableList() } + awsAccountNumber = addResellerRoyalty.awsAccountNumber + awsOfferId = addResellerRoyalty.awsOfferId + awsPayerReferenceId = addResellerRoyalty.awsPayerReferenceId + endingBefore = addResellerRoyalty.endingBefore + fraction = addResellerRoyalty.fraction + gcpAccountId = addResellerRoyalty.gcpAccountId + gcpOfferId = addResellerRoyalty.gcpOfferId + netsuiteResellerId = addResellerRoyalty.netsuiteResellerId + resellerContractValue = addResellerRoyalty.resellerContractValue + startingAt = addResellerRoyalty.startingAt + additionalProperties = + addResellerRoyalty.additionalProperties.toMutableMap() + } + + fun resellerType(resellerType: ResellerType) = + resellerType(JsonField.of(resellerType)) + + /** + * Sets [Builder.resellerType] to an arbitrary JSON value. + * + * You should usually call [Builder.resellerType] with a well-typed + * [ResellerType] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun resellerType(resellerType: JsonField) = apply { + this.resellerType = resellerType + } + + fun applicableProductIds(applicableProductIds: List) = + applicableProductIds(JsonField.of(applicableProductIds)) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + fun applicableProductTags(applicableProductTags: List) = + applicableProductTags(JsonField.of(applicableProductTags)) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun awsAccountNumber(awsAccountNumber: String) = + awsAccountNumber(JsonField.of(awsAccountNumber)) + + /** + * Sets [Builder.awsAccountNumber] to an arbitrary JSON value. + * + * You should usually call [Builder.awsAccountNumber] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun awsAccountNumber(awsAccountNumber: JsonField) = apply { + this.awsAccountNumber = awsAccountNumber + } + + fun awsOfferId(awsOfferId: String) = awsOfferId(JsonField.of(awsOfferId)) + + /** + * Sets [Builder.awsOfferId] to an arbitrary JSON value. + * + * You should usually call [Builder.awsOfferId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun awsOfferId(awsOfferId: JsonField) = apply { + this.awsOfferId = awsOfferId + } + + fun awsPayerReferenceId(awsPayerReferenceId: String) = + awsPayerReferenceId(JsonField.of(awsPayerReferenceId)) + + /** + * Sets [Builder.awsPayerReferenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.awsPayerReferenceId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun awsPayerReferenceId(awsPayerReferenceId: JsonField) = apply { + this.awsPayerReferenceId = awsPayerReferenceId + } + + fun endingBefore(endingBefore: OffsetDateTime?) = + endingBefore(JsonField.ofNullable(endingBefore)) + + /** + * Alias for calling [Builder.endingBefore] with `endingBefore.orElse(null)`. + */ + fun endingBefore(endingBefore: Optional) = + endingBefore(endingBefore.getOrNull()) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun fraction(fraction: Double) = fraction(JsonField.of(fraction)) + + /** + * Sets [Builder.fraction] to an arbitrary JSON value. + * + * You should usually call [Builder.fraction] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun fraction(fraction: JsonField) = apply { this.fraction = fraction } + + fun gcpAccountId(gcpAccountId: String) = + gcpAccountId(JsonField.of(gcpAccountId)) + + /** + * Sets [Builder.gcpAccountId] to an arbitrary JSON value. + * + * You should usually call [Builder.gcpAccountId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun gcpAccountId(gcpAccountId: JsonField) = apply { + this.gcpAccountId = gcpAccountId + } + + fun gcpOfferId(gcpOfferId: String) = gcpOfferId(JsonField.of(gcpOfferId)) + + /** + * Sets [Builder.gcpOfferId] to an arbitrary JSON value. + * + * You should usually call [Builder.gcpOfferId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun gcpOfferId(gcpOfferId: JsonField) = apply { + this.gcpOfferId = gcpOfferId + } + + fun netsuiteResellerId(netsuiteResellerId: String) = + netsuiteResellerId(JsonField.of(netsuiteResellerId)) + + /** + * Sets [Builder.netsuiteResellerId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteResellerId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteResellerId(netsuiteResellerId: JsonField) = apply { + this.netsuiteResellerId = netsuiteResellerId + } + + fun resellerContractValue(resellerContractValue: Double) = + resellerContractValue(JsonField.of(resellerContractValue)) + + /** + * Sets [Builder.resellerContractValue] to an arbitrary JSON value. + * + * You should usually call [Builder.resellerContractValue] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun resellerContractValue(resellerContractValue: JsonField) = apply { + this.resellerContractValue = resellerContractValue + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [AddResellerRoyalty]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .resellerType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddResellerRoyalty = + AddResellerRoyalty( + checkRequired("resellerType", resellerType), + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + awsAccountNumber, + awsOfferId, + awsPayerReferenceId, + endingBefore, + fraction, + gcpAccountId, + gcpOfferId, + netsuiteResellerId, + resellerContractValue, + startingAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddResellerRoyalty = apply { + if (validated) { + return@apply + } + + resellerType().validate() + applicableProductIds() + applicableProductTags() + awsAccountNumber() + awsOfferId() + awsPayerReferenceId() + endingBefore() + fraction() + gcpAccountId() + gcpOfferId() + netsuiteResellerId() + resellerContractValue() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (resellerType.asKnown().getOrNull()?.validity() ?: 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (if (awsAccountNumber.asKnown().isPresent) 1 else 0) + + (if (awsOfferId.asKnown().isPresent) 1 else 0) + + (if (awsPayerReferenceId.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (fraction.asKnown().isPresent) 1 else 0) + + (if (gcpAccountId.asKnown().isPresent) 1 else 0) + + (if (gcpOfferId.asKnown().isPresent) 1 else 0) + + (if (netsuiteResellerId.asKnown().isPresent) 1 else 0) + + (if (resellerContractValue.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + class ResellerType + @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 AWS = of("AWS") + + @JvmField val AWS_PRO_SERVICE = of("AWS_PRO_SERVICE") + + @JvmField val GCP = of("GCP") + + @JvmField val GCP_PRO_SERVICE = of("GCP_PRO_SERVICE") + + @JvmStatic fun of(value: String) = ResellerType(JsonField.of(value)) + } + + /** An enum containing [ResellerType]'s known values. */ + enum class Known { + AWS, + AWS_PRO_SERVICE, + GCP, + GCP_PRO_SERVICE, + } + + /** + * An enum containing [ResellerType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ResellerType] 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 { + AWS, + AWS_PRO_SERVICE, + GCP, + GCP_PRO_SERVICE, + /** + * An enum member indicating that [ResellerType] 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) { + AWS -> Value.AWS + AWS_PRO_SERVICE -> Value.AWS_PRO_SERVICE + GCP -> Value.GCP + GCP_PRO_SERVICE -> Value.GCP_PRO_SERVICE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + AWS -> Known.AWS + AWS_PRO_SERVICE -> Known.AWS_PRO_SERVICE + GCP -> Known.GCP + GCP_PRO_SERVICE -> Known.GCP_PRO_SERVICE + else -> + throw MetronomeInvalidDataException("Unknown ResellerType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ResellerType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ResellerType && 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 AddResellerRoyalty && + resellerType == other.resellerType && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + awsAccountNumber == other.awsAccountNumber && + awsOfferId == other.awsOfferId && + awsPayerReferenceId == other.awsPayerReferenceId && + endingBefore == other.endingBefore && + fraction == other.fraction && + gcpAccountId == other.gcpAccountId && + gcpOfferId == other.gcpOfferId && + netsuiteResellerId == other.netsuiteResellerId && + resellerContractValue == other.resellerContractValue && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + resellerType, + applicableProductIds, + applicableProductTags, + awsAccountNumber, + awsOfferId, + awsPayerReferenceId, + endingBefore, + fraction, + gcpAccountId, + gcpOfferId, + netsuiteResellerId, + resellerContractValue, + startingAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddResellerRoyalty{resellerType=$resellerType, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, awsAccountNumber=$awsAccountNumber, awsOfferId=$awsOfferId, awsPayerReferenceId=$awsPayerReferenceId, endingBefore=$endingBefore, fraction=$fraction, gcpAccountId=$gcpAccountId, gcpOfferId=$gcpOfferId, netsuiteResellerId=$netsuiteResellerId, resellerContractValue=$resellerContractValue, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + class AddScheduledCharge + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val product: JsonField, + private val schedule: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + @JsonProperty("schedule") + @ExcludeMissing + schedule: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + ) : this(id, product, schedule, name, netsuiteSalesOrderId, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException 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 product(): Product = product.getRequired("product") + + /** + * @throws MetronomeInvalidDataException 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 schedule(): SchedulePointInTime = schedule.getRequired("schedule") + + /** + * displayed on invoices + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * This field's availability is dependent on your client's configuration. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_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 + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + /** + * Returns the raw JSON value of [schedule]. + * + * Unlike [schedule], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("schedule") + @ExcludeMissing + fun _schedule(): JsonField = schedule + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + @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 + * [AddScheduledCharge]. + * + * The following fields are required: + * ```java + * .id() + * .product() + * .schedule() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddScheduledCharge]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var product: JsonField? = null + private var schedule: JsonField? = null + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addScheduledCharge: AddScheduledCharge) = apply { + id = addScheduledCharge.id + product = addScheduledCharge.product + schedule = addScheduledCharge.schedule + name = addScheduledCharge.name + netsuiteSalesOrderId = addScheduledCharge.netsuiteSalesOrderId + additionalProperties = + addScheduledCharge.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 product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + fun schedule(schedule: SchedulePointInTime) = schedule(JsonField.of(schedule)) + + /** + * Sets [Builder.schedule] to an arbitrary JSON value. + * + * You should usually call [Builder.schedule] with a well-typed + * [SchedulePointInTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun schedule(schedule: JsonField) = apply { + this.schedule = schedule + } + + /** displayed on invoices */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** This field's availability is dependent on your client's configuration. */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String) = + netsuiteSalesOrderId(JsonField.of(netsuiteSalesOrderId)) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + 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 [AddScheduledCharge]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .product() + * .schedule() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddScheduledCharge = + AddScheduledCharge( + checkRequired("id", id), + checkRequired("product", product), + checkRequired("schedule", schedule), + name, + netsuiteSalesOrderId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddScheduledCharge = apply { + if (validated) { + return@apply + } + + id() + product().validate() + schedule().validate() + name() + netsuiteSalesOrderId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + (schedule.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddScheduledCharge && + id == other.id && + product == other.product && + schedule == other.schedule && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + product, + schedule, + name, + netsuiteSalesOrderId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddScheduledCharge{id=$id, product=$product, schedule=$schedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, additionalProperties=$additionalProperties}" + } + + class AddSubscription + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val billingPeriods: JsonField, + private val collectionSchedule: JsonField, + private val proration: JsonField, + private val quantityManagementMode: JsonField, + private val quantitySchedule: JsonField>, + private val startingAt: JsonField, + private val subscriptionRate: JsonField, + private val id: JsonField, + private val customFields: JsonField, + private val description: JsonField, + private val endingBefore: JsonField, + private val fiatCreditTypeId: JsonField, + private val name: JsonField, + private val seatConfig: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("billing_periods") + @ExcludeMissing + billingPeriods: JsonField = JsonMissing.of(), + @JsonProperty("collection_schedule") + @ExcludeMissing + collectionSchedule: JsonField = JsonMissing.of(), + @JsonProperty("proration") + @ExcludeMissing + proration: JsonField = JsonMissing.of(), + @JsonProperty("quantity_management_mode") + @ExcludeMissing + quantityManagementMode: JsonField = JsonMissing.of(), + @JsonProperty("quantity_schedule") + @ExcludeMissing + quantitySchedule: JsonField> = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("subscription_rate") + @ExcludeMissing + subscriptionRate: JsonField = JsonMissing.of(), + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("custom_fields") + @ExcludeMissing + customFields: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("fiat_credit_type_id") + @ExcludeMissing + fiatCreditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("seat_config") + @ExcludeMissing + seatConfig: JsonField = JsonMissing.of(), + ) : this( + billingPeriods, + collectionSchedule, + proration, + quantityManagementMode, + quantitySchedule, + startingAt, + subscriptionRate, + id, + customFields, + description, + endingBefore, + fiatCreditTypeId, + name, + seatConfig, + mutableMapOf(), + ) + + /** + * Previous, current, and next billing periods for the subscription. + * + * @throws MetronomeInvalidDataException 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 billingPeriods(): BillingPeriods = billingPeriods.getRequired("billing_periods") + + /** + * @throws MetronomeInvalidDataException 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 collectionSchedule(): CollectionSchedule = + collectionSchedule.getRequired("collection_schedule") + + /** + * @throws MetronomeInvalidDataException 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 proration(): Proration = proration.getRequired("proration") + + /** + * Determines how the subscription's quantity is controlled. Defaults to + * QUANTITY_ONLY. **QUANTITY_ONLY**: The subscription quantity is specified directly + * on the subscription. `initial_quantity` must be provided with this option. + * Compatible with recurring commits/credits that use POOLED allocation. + * **SEAT_BASED**: Use when you want to pass specific seat identifiers (e.g. add + * user_123) to increment and decrement a subscription quantity, rather than + * directly providing the quantity. You must use a **SEAT_BASED** subscription to + * use a linked recurring credit with an allocation per seat. `seat_config` must be + * provided with this option. + * + * @throws MetronomeInvalidDataException 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 quantityManagementMode(): QuantityManagementMode = + quantityManagementMode.getRequired("quantity_management_mode") + + /** + * List of quantity schedule items for the subscription. Only includes the current + * quantity and future quantity changes. + * + * @throws MetronomeInvalidDataException 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 quantitySchedule(): List = + quantitySchedule.getRequired("quantity_schedule") + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * @throws MetronomeInvalidDataException 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 subscriptionRate(): SubscriptionRate = + subscriptionRate.getRequired("subscription_rate") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun id(): Optional = id.getOptional("id") + + /** + * Custom fields to be added eg. { "key1": "value1", "key2": "value2" } + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun customFields(): Optional = + customFields.getOptional("custom_fields") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun fiatCreditTypeId(): Optional = + fiatCreditTypeId.getOptional("fiat_credit_type_id") + + /** + * @throws MetronomeInvalidDataException 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 MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun seatConfig(): Optional = seatConfig.getOptional("seat_config") + + /** + * Returns the raw JSON value of [billingPeriods]. + * + * Unlike [billingPeriods], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billing_periods") + @ExcludeMissing + fun _billingPeriods(): JsonField = billingPeriods + + /** + * Returns the raw JSON value of [collectionSchedule]. + * + * Unlike [collectionSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("collection_schedule") + @ExcludeMissing + fun _collectionSchedule(): JsonField = collectionSchedule + + /** + * Returns the raw JSON value of [proration]. + * + * Unlike [proration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("proration") + @ExcludeMissing + fun _proration(): JsonField = proration + + /** + * Returns the raw JSON value of [quantityManagementMode]. + * + * Unlike [quantityManagementMode], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("quantity_management_mode") + @ExcludeMissing + fun _quantityManagementMode(): JsonField = + quantityManagementMode + + /** + * Returns the raw JSON value of [quantitySchedule]. + * + * Unlike [quantitySchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity_schedule") + @ExcludeMissing + fun _quantitySchedule(): JsonField> = quantitySchedule + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [subscriptionRate]. + * + * Unlike [subscriptionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("subscription_rate") + @ExcludeMissing + fun _subscriptionRate(): JsonField = subscriptionRate + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [customFields]. + * + * Unlike [customFields], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("custom_fields") + @ExcludeMissing + fun _customFields(): JsonField = customFields + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [fiatCreditTypeId]. + * + * Unlike [fiatCreditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fiat_credit_type_id") + @ExcludeMissing + fun _fiatCreditTypeId(): JsonField = fiatCreditTypeId + + /** + * 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 [seatConfig]. + * + * Unlike [seatConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("seat_config") + @ExcludeMissing + fun _seatConfig(): JsonField = seatConfig + + @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 [AddSubscription]. + * + * The following fields are required: + * ```java + * .billingPeriods() + * .collectionSchedule() + * .proration() + * .quantityManagementMode() + * .quantitySchedule() + * .startingAt() + * .subscriptionRate() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddSubscription]. */ + class Builder internal constructor() { + + private var billingPeriods: JsonField? = null + private var collectionSchedule: JsonField? = null + private var proration: JsonField? = null + private var quantityManagementMode: JsonField? = null + private var quantitySchedule: JsonField>? = null + private var startingAt: JsonField? = null + private var subscriptionRate: JsonField? = null + private var id: JsonField = JsonMissing.of() + private var customFields: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var fiatCreditTypeId: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var seatConfig: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addSubscription: AddSubscription) = apply { + billingPeriods = addSubscription.billingPeriods + collectionSchedule = addSubscription.collectionSchedule + proration = addSubscription.proration + quantityManagementMode = addSubscription.quantityManagementMode + quantitySchedule = + addSubscription.quantitySchedule.map { it.toMutableList() } + startingAt = addSubscription.startingAt + subscriptionRate = addSubscription.subscriptionRate + id = addSubscription.id + customFields = addSubscription.customFields + description = addSubscription.description + endingBefore = addSubscription.endingBefore + fiatCreditTypeId = addSubscription.fiatCreditTypeId + name = addSubscription.name + seatConfig = addSubscription.seatConfig + additionalProperties = addSubscription.additionalProperties.toMutableMap() + } + + /** Previous, current, and next billing periods for the subscription. */ + fun billingPeriods(billingPeriods: BillingPeriods) = + billingPeriods(JsonField.of(billingPeriods)) + + /** + * Sets [Builder.billingPeriods] to an arbitrary JSON value. + * + * You should usually call [Builder.billingPeriods] with a well-typed + * [BillingPeriods] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun billingPeriods(billingPeriods: JsonField) = apply { + this.billingPeriods = billingPeriods + } + + fun collectionSchedule(collectionSchedule: CollectionSchedule) = + collectionSchedule(JsonField.of(collectionSchedule)) + + /** + * Sets [Builder.collectionSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.collectionSchedule] with a well-typed + * [CollectionSchedule] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun collectionSchedule(collectionSchedule: JsonField) = + apply { + this.collectionSchedule = collectionSchedule + } + + fun proration(proration: Proration) = proration(JsonField.of(proration)) + + /** + * Sets [Builder.proration] to an arbitrary JSON value. + * + * You should usually call [Builder.proration] with a well-typed [Proration] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun proration(proration: JsonField) = apply { + this.proration = proration + } + + /** + * Determines how the subscription's quantity is controlled. Defaults to + * QUANTITY_ONLY. **QUANTITY_ONLY**: The subscription quantity is specified + * directly on the subscription. `initial_quantity` must be provided with this + * option. Compatible with recurring commits/credits that use POOLED allocation. + * **SEAT_BASED**: Use when you want to pass specific seat identifiers (e.g. add + * user_123) to increment and decrement a subscription quantity, rather than + * directly providing the quantity. You must use a **SEAT_BASED** subscription + * to use a linked recurring credit with an allocation per seat. `seat_config` + * must be provided with this option. + */ + fun quantityManagementMode(quantityManagementMode: QuantityManagementMode) = + quantityManagementMode(JsonField.of(quantityManagementMode)) + + /** + * Sets [Builder.quantityManagementMode] to an arbitrary JSON value. + * + * You should usually call [Builder.quantityManagementMode] with a well-typed + * [QuantityManagementMode] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun quantityManagementMode( + quantityManagementMode: JsonField + ) = apply { this.quantityManagementMode = quantityManagementMode } + + /** + * List of quantity schedule items for the subscription. Only includes the + * current quantity and future quantity changes. + */ + fun quantitySchedule(quantitySchedule: List) = + quantitySchedule(JsonField.of(quantitySchedule)) + + /** + * Sets [Builder.quantitySchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.quantitySchedule] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun quantitySchedule(quantitySchedule: JsonField>) = + apply { + this.quantitySchedule = quantitySchedule.map { it.toMutableList() } + } + + /** + * Adds a single [QuantitySchedule] to [Builder.quantitySchedule]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addQuantitySchedule(quantitySchedule: QuantitySchedule) = apply { + this.quantitySchedule = + (this.quantitySchedule ?: JsonField.of(mutableListOf())).also { + checkKnown("quantitySchedule", it).add(quantitySchedule) + } + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + fun subscriptionRate(subscriptionRate: SubscriptionRate) = + subscriptionRate(JsonField.of(subscriptionRate)) + + /** + * Sets [Builder.subscriptionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.subscriptionRate] with a well-typed + * [SubscriptionRate] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun subscriptionRate(subscriptionRate: JsonField) = apply { + this.subscriptionRate = subscriptionRate + } + + 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 } + + /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ + fun customFields(customFields: CustomFields) = + customFields(JsonField.of(customFields)) + + /** + * Sets [Builder.customFields] to an arbitrary JSON value. + * + * You should usually call [Builder.customFields] with a well-typed + * [CustomFields] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun customFields(customFields: JsonField) = apply { + this.customFields = customFields + } + + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun fiatCreditTypeId(fiatCreditTypeId: String) = + fiatCreditTypeId(JsonField.of(fiatCreditTypeId)) + + /** + * Sets [Builder.fiatCreditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.fiatCreditTypeId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fiatCreditTypeId(fiatCreditTypeId: JsonField) = apply { + this.fiatCreditTypeId = fiatCreditTypeId + } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun seatConfig(seatConfig: SeatConfig) = seatConfig(JsonField.of(seatConfig)) + + /** + * Sets [Builder.seatConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.seatConfig] with a well-typed [SeatConfig] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun seatConfig(seatConfig: JsonField) = apply { + this.seatConfig = seatConfig + } + + 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 [AddSubscription]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .billingPeriods() + * .collectionSchedule() + * .proration() + * .quantityManagementMode() + * .quantitySchedule() + * .startingAt() + * .subscriptionRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddSubscription = + AddSubscription( + checkRequired("billingPeriods", billingPeriods), + checkRequired("collectionSchedule", collectionSchedule), + checkRequired("proration", proration), + checkRequired("quantityManagementMode", quantityManagementMode), + checkRequired("quantitySchedule", quantitySchedule).map { + it.toImmutable() + }, + checkRequired("startingAt", startingAt), + checkRequired("subscriptionRate", subscriptionRate), + id, + customFields, + description, + endingBefore, + fiatCreditTypeId, + name, + seatConfig, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddSubscription = apply { + if (validated) { + return@apply + } + + billingPeriods().validate() + collectionSchedule().validate() + proration().validate() + quantityManagementMode().validate() + quantitySchedule().forEach { it.validate() } + startingAt() + subscriptionRate().validate() + id() + customFields().ifPresent { it.validate() } + description() + endingBefore() + fiatCreditTypeId() + name() + seatConfig().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (billingPeriods.asKnown().getOrNull()?.validity() ?: 0) + + (collectionSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (proration.asKnown().getOrNull()?.validity() ?: 0) + + (quantityManagementMode.asKnown().getOrNull()?.validity() ?: 0) + + (quantitySchedule.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (subscriptionRate.asKnown().getOrNull()?.validity() ?: 0) + + (if (id.asKnown().isPresent) 1 else 0) + + (customFields.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (fiatCreditTypeId.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (seatConfig.asKnown().getOrNull()?.validity() ?: 0) + + /** Previous, current, and next billing periods for the subscription. */ + class BillingPeriods + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val current: JsonField, + private val next: JsonField, + private val previous: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("current") + @ExcludeMissing + current: JsonField = JsonMissing.of(), + @JsonProperty("next") + @ExcludeMissing + next: JsonField = JsonMissing.of(), + @JsonProperty("previous") + @ExcludeMissing + previous: JsonField = JsonMissing.of(), + ) : this(current, next, previous, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun current(): Optional = current.getOptional("current") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun next(): Optional = next.getOptional("next") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun previous(): Optional = previous.getOptional("previous") + + /** + * Returns the raw JSON value of [current]. + * + * Unlike [current], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("current") + @ExcludeMissing + fun _current(): JsonField = current + + /** + * Returns the raw JSON value of [next]. + * + * Unlike [next], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("next") @ExcludeMissing fun _next(): JsonField = next + + /** + * Returns the raw JSON value of [previous]. + * + * Unlike [previous], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("previous") + @ExcludeMissing + fun _previous(): JsonField = previous + + @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 + * [BillingPeriods]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BillingPeriods]. */ + class Builder internal constructor() { + + private var current: JsonField = JsonMissing.of() + private var next: JsonField = JsonMissing.of() + private var previous: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(billingPeriods: BillingPeriods) = apply { + current = billingPeriods.current + next = billingPeriods.next + previous = billingPeriods.previous + additionalProperties = + billingPeriods.additionalProperties.toMutableMap() + } + + fun current(current: Current) = current(JsonField.of(current)) + + /** + * Sets [Builder.current] to an arbitrary JSON value. + * + * You should usually call [Builder.current] with a well-typed [Current] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun current(current: JsonField) = apply { this.current = current } + + fun next(next: Next) = next(JsonField.of(next)) + + /** + * Sets [Builder.next] to an arbitrary JSON value. + * + * You should usually call [Builder.next] with a well-typed [Next] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun next(next: JsonField) = apply { this.next = next } + + fun previous(previous: Previous) = previous(JsonField.of(previous)) + + /** + * Sets [Builder.previous] to an arbitrary JSON value. + * + * You should usually call [Builder.previous] with a well-typed [Previous] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun previous(previous: JsonField) = apply { + this.previous = previous + } + + 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 [BillingPeriods]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BillingPeriods = + BillingPeriods( + current, + next, + previous, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): BillingPeriods = apply { + if (validated) { + return@apply + } + + current().ifPresent { it.validate() } + next().ifPresent { it.validate() } + previous().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (current.asKnown().getOrNull()?.validity() ?: 0) + + (next.asKnown().getOrNull()?.validity() ?: 0) + + (previous.asKnown().getOrNull()?.validity() ?: 0) + + class Current + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(endingBefore, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 endingBefore(): OffsetDateTime = + endingBefore.getRequired("ending_before") + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 [Current]. + * + * The following fields are required: + * ```java + * .endingBefore() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Current]. */ + class Builder internal constructor() { + + private var endingBefore: JsonField? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(current: Current) = apply { + endingBefore = current.endingBefore + startingAt = current.startingAt + additionalProperties = current.additionalProperties.toMutableMap() + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [Current]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .endingBefore() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Current = + Current( + checkRequired("endingBefore", endingBefore), + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Current = apply { + if (validated) { + return@apply + } + + endingBefore() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Current && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(endingBefore, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Current{endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + class Next + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(endingBefore, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 endingBefore(): OffsetDateTime = + endingBefore.getRequired("ending_before") + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 [Next]. + * + * The following fields are required: + * ```java + * .endingBefore() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Next]. */ + class Builder internal constructor() { + + private var endingBefore: JsonField? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(next: Next) = apply { + endingBefore = next.endingBefore + startingAt = next.startingAt + additionalProperties = next.additionalProperties.toMutableMap() + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [Next]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .endingBefore() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Next = + Next( + checkRequired("endingBefore", endingBefore), + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Next = apply { + if (validated) { + return@apply + } + + endingBefore() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Next && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(endingBefore, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Next{endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + class Previous + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(endingBefore, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 endingBefore(): OffsetDateTime = + endingBefore.getRequired("ending_before") + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 [Previous]. + * + * The following fields are required: + * ```java + * .endingBefore() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Previous]. */ + class Builder internal constructor() { + + private var endingBefore: JsonField? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(previous: Previous) = apply { + endingBefore = previous.endingBefore + startingAt = previous.startingAt + additionalProperties = previous.additionalProperties.toMutableMap() + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [Previous]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .endingBefore() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Previous = + Previous( + checkRequired("endingBefore", endingBefore), + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Previous = apply { + if (validated) { + return@apply + } + + endingBefore() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Previous && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(endingBefore, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Previous{endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BillingPeriods && + current == other.current && + next == other.next && + previous == other.previous && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(current, next, previous, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BillingPeriods{current=$current, next=$next, previous=$previous, additionalProperties=$additionalProperties}" + } + + class CollectionSchedule + @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 ADVANCE = of("ADVANCE") + + @JvmField val ARREARS = of("ARREARS") + + @JvmStatic fun of(value: String) = CollectionSchedule(JsonField.of(value)) + } + + /** An enum containing [CollectionSchedule]'s known values. */ + enum class Known { + ADVANCE, + ARREARS, + } + + /** + * An enum containing [CollectionSchedule]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [CollectionSchedule] 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 { + ADVANCE, + ARREARS, + /** + * An enum member indicating that [CollectionSchedule] 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) { + ADVANCE -> Value.ADVANCE + ARREARS -> Value.ARREARS + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + ADVANCE -> Known.ADVANCE + ARREARS -> Known.ARREARS + else -> + throw MetronomeInvalidDataException( + "Unknown CollectionSchedule: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CollectionSchedule = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 CollectionSchedule && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Proration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val invoiceBehavior: JsonField, + private val isProrated: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("invoice_behavior") + @ExcludeMissing + invoiceBehavior: JsonField = JsonMissing.of(), + @JsonProperty("is_prorated") + @ExcludeMissing + isProrated: JsonField = JsonMissing.of(), + ) : this(invoiceBehavior, isProrated, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 invoiceBehavior(): InvoiceBehavior = + invoiceBehavior.getRequired("invoice_behavior") + + /** + * @throws MetronomeInvalidDataException 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 isProrated(): Boolean = isProrated.getRequired("is_prorated") + + /** + * Returns the raw JSON value of [invoiceBehavior]. + * + * Unlike [invoiceBehavior], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_behavior") + @ExcludeMissing + fun _invoiceBehavior(): JsonField = invoiceBehavior + + /** + * Returns the raw JSON value of [isProrated]. + * + * Unlike [isProrated], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("is_prorated") + @ExcludeMissing + fun _isProrated(): JsonField = isProrated + + @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 [Proration]. + * + * The following fields are required: + * ```java + * .invoiceBehavior() + * .isProrated() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Proration]. */ + class Builder internal constructor() { + + private var invoiceBehavior: JsonField? = null + private var isProrated: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(proration: Proration) = apply { + invoiceBehavior = proration.invoiceBehavior + isProrated = proration.isProrated + additionalProperties = proration.additionalProperties.toMutableMap() + } + + fun invoiceBehavior(invoiceBehavior: InvoiceBehavior) = + invoiceBehavior(JsonField.of(invoiceBehavior)) + + /** + * Sets [Builder.invoiceBehavior] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceBehavior] with a well-typed + * [InvoiceBehavior] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun invoiceBehavior(invoiceBehavior: JsonField) = apply { + this.invoiceBehavior = invoiceBehavior + } + + fun isProrated(isProrated: Boolean) = isProrated(JsonField.of(isProrated)) + + /** + * Sets [Builder.isProrated] to an arbitrary JSON value. + * + * You should usually call [Builder.isProrated] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun isProrated(isProrated: JsonField) = apply { + this.isProrated = isProrated + } + + 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 [Proration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .invoiceBehavior() + * .isProrated() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Proration = + Proration( + checkRequired("invoiceBehavior", invoiceBehavior), + checkRequired("isProrated", isProrated), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Proration = apply { + if (validated) { + return@apply + } + + invoiceBehavior().validate() + isProrated() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (invoiceBehavior.asKnown().getOrNull()?.validity() ?: 0) + + (if (isProrated.asKnown().isPresent) 1 else 0) + + class InvoiceBehavior + @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 BILL_IMMEDIATELY = of("BILL_IMMEDIATELY") + + @JvmField + val BILL_ON_NEXT_COLLECTION_DATE = of("BILL_ON_NEXT_COLLECTION_DATE") + + @JvmStatic fun of(value: String) = InvoiceBehavior(JsonField.of(value)) + } + + /** An enum containing [InvoiceBehavior]'s known values. */ + enum class Known { + BILL_IMMEDIATELY, + BILL_ON_NEXT_COLLECTION_DATE, + } + + /** + * An enum containing [InvoiceBehavior]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [InvoiceBehavior] 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 { + BILL_IMMEDIATELY, + BILL_ON_NEXT_COLLECTION_DATE, + /** + * An enum member indicating that [InvoiceBehavior] 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) { + BILL_IMMEDIATELY -> Value.BILL_IMMEDIATELY + BILL_ON_NEXT_COLLECTION_DATE -> Value.BILL_ON_NEXT_COLLECTION_DATE + 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + BILL_IMMEDIATELY -> Known.BILL_IMMEDIATELY + BILL_ON_NEXT_COLLECTION_DATE -> Known.BILL_ON_NEXT_COLLECTION_DATE + else -> + throw MetronomeInvalidDataException( + "Unknown InvoiceBehavior: $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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InvoiceBehavior = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 InvoiceBehavior && 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 Proration && + invoiceBehavior == other.invoiceBehavior && + isProrated == other.isProrated && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(invoiceBehavior, isProrated, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Proration{invoiceBehavior=$invoiceBehavior, isProrated=$isProrated, additionalProperties=$additionalProperties}" + } + + /** + * Determines how the subscription's quantity is controlled. Defaults to + * QUANTITY_ONLY. **QUANTITY_ONLY**: The subscription quantity is specified directly + * on the subscription. `initial_quantity` must be provided with this option. + * Compatible with recurring commits/credits that use POOLED allocation. + * **SEAT_BASED**: Use when you want to pass specific seat identifiers (e.g. add + * user_123) to increment and decrement a subscription quantity, rather than + * directly providing the quantity. You must use a **SEAT_BASED** subscription to + * use a linked recurring credit with an allocation per seat. `seat_config` must be + * provided with this option. + */ + class QuantityManagementMode + @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 SEAT_BASED = of("SEAT_BASED") + + @JvmField val QUANTITY_ONLY = of("QUANTITY_ONLY") + + @JvmStatic + fun of(value: String) = QuantityManagementMode(JsonField.of(value)) + } + + /** An enum containing [QuantityManagementMode]'s known values. */ + enum class Known { + SEAT_BASED, + QUANTITY_ONLY, + } + + /** + * An enum containing [QuantityManagementMode]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [QuantityManagementMode] 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 { + SEAT_BASED, + QUANTITY_ONLY, + /** + * An enum member indicating that [QuantityManagementMode] 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) { + SEAT_BASED -> Value.SEAT_BASED + QUANTITY_ONLY -> Value.QUANTITY_ONLY + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + SEAT_BASED -> Known.SEAT_BASED + QUANTITY_ONLY -> Known.QUANTITY_ONLY + else -> + throw MetronomeInvalidDataException( + "Unknown QuantityManagementMode: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): QuantityManagementMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 QuantityManagementMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class QuantitySchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val quantity: JsonField, + private val startingAt: JsonField, + private val endingBefore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + ) : this(quantity, startingAt, endingBefore, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 quantity(): Double = quantity.getRequired("quantity") + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + @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 + * [QuantitySchedule]. + * + * The following fields are required: + * ```java + * .quantity() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [QuantitySchedule]. */ + class Builder internal constructor() { + + private var quantity: JsonField? = null + private var startingAt: JsonField? = null + private var endingBefore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(quantitySchedule: QuantitySchedule) = apply { + quantity = quantitySchedule.quantity + startingAt = quantitySchedule.startingAt + endingBefore = quantitySchedule.endingBefore + additionalProperties = + quantitySchedule.additionalProperties.toMutableMap() + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + 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 [QuantitySchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .quantity() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): QuantitySchedule = + QuantitySchedule( + checkRequired("quantity", quantity), + checkRequired("startingAt", startingAt), + endingBefore, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): QuantitySchedule = apply { + if (validated) { + return@apply + } + + quantity() + startingAt() + endingBefore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (quantity.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is QuantitySchedule && + quantity == other.quantity && + startingAt == other.startingAt && + endingBefore == other.endingBefore && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(quantity, startingAt, endingBefore, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "QuantitySchedule{quantity=$quantity, startingAt=$startingAt, endingBefore=$endingBefore, additionalProperties=$additionalProperties}" + } + + class SubscriptionRate + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val billingFrequency: JsonField, + private val product: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("billing_frequency") + @ExcludeMissing + billingFrequency: JsonField = JsonMissing.of(), + @JsonProperty("product") + @ExcludeMissing + product: JsonField = JsonMissing.of(), + ) : this(billingFrequency, product, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 billingFrequency(): BillingFrequency = + billingFrequency.getRequired("billing_frequency") + + /** + * @throws MetronomeInvalidDataException 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 product(): Product = product.getRequired("product") + + /** + * Returns the raw JSON value of [billingFrequency]. + * + * Unlike [billingFrequency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billing_frequency") + @ExcludeMissing + fun _billingFrequency(): JsonField = billingFrequency + + /** + * Returns the raw JSON value of [product]. + * + * Unlike [product], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("product") + @ExcludeMissing + fun _product(): JsonField = product + + @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 + * [SubscriptionRate]. + * + * The following fields are required: + * ```java + * .billingFrequency() + * .product() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SubscriptionRate]. */ + class Builder internal constructor() { + + private var billingFrequency: JsonField? = null + private var product: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(subscriptionRate: SubscriptionRate) = apply { + billingFrequency = subscriptionRate.billingFrequency + product = subscriptionRate.product + additionalProperties = + subscriptionRate.additionalProperties.toMutableMap() + } + + fun billingFrequency(billingFrequency: BillingFrequency) = + billingFrequency(JsonField.of(billingFrequency)) + + /** + * Sets [Builder.billingFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.billingFrequency] with a well-typed + * [BillingFrequency] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun billingFrequency(billingFrequency: JsonField) = + apply { + this.billingFrequency = billingFrequency + } + + fun product(product: Product) = product(JsonField.of(product)) + + /** + * Sets [Builder.product] to an arbitrary JSON value. + * + * You should usually call [Builder.product] with a well-typed [Product] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun product(product: JsonField) = apply { this.product = product } + + 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 [SubscriptionRate]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .billingFrequency() + * .product() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SubscriptionRate = + SubscriptionRate( + checkRequired("billingFrequency", billingFrequency), + checkRequired("product", product), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): SubscriptionRate = apply { + if (validated) { + return@apply + } + + billingFrequency().validate() + product().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (billingFrequency.asKnown().getOrNull()?.validity() ?: 0) + + (product.asKnown().getOrNull()?.validity() ?: 0) + + class BillingFrequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = BillingFrequency(JsonField.of(value)) + } + + /** An enum containing [BillingFrequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [BillingFrequency]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [BillingFrequency] 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 { + MONTHLY, + QUARTERLY, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [BillingFrequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> + throw MetronomeInvalidDataException( + "Unknown BillingFrequency: $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 MetronomeInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): BillingFrequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 BillingFrequency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(id, name, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Product]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + id = product.id + name = product.name + additionalProperties = product.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Product]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("id", id), + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + id() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{id=$id, name=$name, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SubscriptionRate && + billingFrequency == other.billingFrequency && + product == other.product && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(billingFrequency, product, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SubscriptionRate{billingFrequency=$billingFrequency, product=$product, additionalProperties=$additionalProperties}" + } + + /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ + class CustomFields + @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 [CustomFields]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFields]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customFields: CustomFields) = apply { + additionalProperties = customFields.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 [CustomFields]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CustomFields = CustomFields(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomFields = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 CustomFields && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomFields{additionalProperties=$additionalProperties}" + } + + class SeatConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val seatGroupKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("seat_group_key") + @ExcludeMissing + seatGroupKey: JsonField = JsonMissing.of() + ) : this(seatGroupKey, mutableMapOf()) + + /** + * The property name, sent on usage events, that identifies the seat ID + * associated with the usage event. For example, the property name might be + * seat_id or user_id. The property must be set as a group key on billable + * metrics and a presentation/pricing group key on contract products. This + * allows linked recurring credits with an allocation per seat to be consumed by + * only one seat's usage. + * + * @throws MetronomeInvalidDataException 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 seatGroupKey(): String = seatGroupKey.getRequired("seat_group_key") + + /** + * Returns the raw JSON value of [seatGroupKey]. + * + * Unlike [seatGroupKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("seat_group_key") + @ExcludeMissing + fun _seatGroupKey(): JsonField = seatGroupKey + + @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 [SeatConfig]. + * + * The following fields are required: + * ```java + * .seatGroupKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SeatConfig]. */ + class Builder internal constructor() { + + private var seatGroupKey: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(seatConfig: SeatConfig) = apply { + seatGroupKey = seatConfig.seatGroupKey + additionalProperties = seatConfig.additionalProperties.toMutableMap() + } + + /** + * The property name, sent on usage events, that identifies the seat ID + * associated with the usage event. For example, the property name might be + * seat_id or user_id. The property must be set as a group key on billable + * metrics and a presentation/pricing group key on contract products. This + * allows linked recurring credits with an allocation per seat to be + * consumed by only one seat's usage. + */ + fun seatGroupKey(seatGroupKey: String) = + seatGroupKey(JsonField.of(seatGroupKey)) + + /** + * Sets [Builder.seatGroupKey] to an arbitrary JSON value. + * + * You should usually call [Builder.seatGroupKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun seatGroupKey(seatGroupKey: JsonField) = apply { + this.seatGroupKey = seatGroupKey + } + + 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 [SeatConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .seatGroupKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SeatConfig = + SeatConfig( + checkRequired("seatGroupKey", seatGroupKey), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): SeatConfig = apply { + if (validated) { + return@apply + } + + seatGroupKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (seatGroupKey.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SeatConfig && + seatGroupKey == other.seatGroupKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(seatGroupKey, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SeatConfig{seatGroupKey=$seatGroupKey, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddSubscription && + billingPeriods == other.billingPeriods && + collectionSchedule == other.collectionSchedule && + proration == other.proration && + quantityManagementMode == other.quantityManagementMode && + quantitySchedule == other.quantitySchedule && + startingAt == other.startingAt && + subscriptionRate == other.subscriptionRate && + id == other.id && + customFields == other.customFields && + description == other.description && + endingBefore == other.endingBefore && + fiatCreditTypeId == other.fiatCreditTypeId && + name == other.name && + seatConfig == other.seatConfig && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + billingPeriods, + collectionSchedule, + proration, + quantityManagementMode, + quantitySchedule, + startingAt, + subscriptionRate, + id, + customFields, + description, + endingBefore, + fiatCreditTypeId, + name, + seatConfig, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddSubscription{billingPeriods=$billingPeriods, collectionSchedule=$collectionSchedule, proration=$proration, quantityManagementMode=$quantityManagementMode, quantitySchedule=$quantitySchedule, startingAt=$startingAt, subscriptionRate=$subscriptionRate, id=$id, customFields=$customFields, description=$description, endingBefore=$endingBefore, fiatCreditTypeId=$fiatCreditTypeId, name=$name, seatConfig=$seatConfig, additionalProperties=$additionalProperties}" + } + + class AddUsageFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupKey: JsonField, + private val groupValues: JsonField>, + private val startingAt: JsonField, + private val endingBefore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("group_key") + @ExcludeMissing + groupKey: JsonField = JsonMissing.of(), + @JsonProperty("group_values") + @ExcludeMissing + groupValues: JsonField> = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + ) : this(groupKey, groupValues, startingAt, endingBefore, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 groupKey(): String = groupKey.getRequired("group_key") + + /** + * @throws MetronomeInvalidDataException 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 groupValues(): List = groupValues.getRequired("group_values") + + /** + * This will match contract starting_at value if usage filter is active from the + * beginning of the contract. + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * This will match contract ending_before value if usage filter is active until the + * end of the contract. It will be undefined if the contract is open-ended. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * Returns the raw JSON value of [groupKey]. + * + * Unlike [groupKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("group_key") + @ExcludeMissing + fun _groupKey(): JsonField = groupKey + + /** + * Returns the raw JSON value of [groupValues]. + * + * Unlike [groupValues], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_values") + @ExcludeMissing + fun _groupValues(): JsonField> = groupValues + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + @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 [AddUsageFilter]. + * + * The following fields are required: + * ```java + * .groupKey() + * .groupValues() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddUsageFilter]. */ + class Builder internal constructor() { + + private var groupKey: JsonField? = null + private var groupValues: JsonField>? = null + private var startingAt: JsonField? = null + private var endingBefore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addUsageFilter: AddUsageFilter) = apply { + groupKey = addUsageFilter.groupKey + groupValues = addUsageFilter.groupValues.map { it.toMutableList() } + startingAt = addUsageFilter.startingAt + endingBefore = addUsageFilter.endingBefore + additionalProperties = addUsageFilter.additionalProperties.toMutableMap() + } + + fun groupKey(groupKey: String) = groupKey(JsonField.of(groupKey)) + + /** + * Sets [Builder.groupKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun groupKey(groupKey: JsonField) = apply { this.groupKey = groupKey } + + fun groupValues(groupValues: List) = + groupValues(JsonField.of(groupValues)) + + /** + * Sets [Builder.groupValues] to an arbitrary JSON value. + * + * You should usually call [Builder.groupValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun groupValues(groupValues: JsonField>) = apply { + this.groupValues = groupValues.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [groupValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupValue(groupValue: String) = apply { + groupValues = + (groupValues ?: JsonField.of(mutableListOf())).also { + checkKnown("groupValues", it).add(groupValue) + } + } + + /** + * This will match contract starting_at value if usage filter is active from the + * beginning of the contract. + */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + /** + * This will match contract ending_before value if usage filter is active until + * the end of the contract. It will be undefined if the contract is open-ended. + */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + 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 [AddUsageFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .groupKey() + * .groupValues() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddUsageFilter = + AddUsageFilter( + checkRequired("groupKey", groupKey), + checkRequired("groupValues", groupValues).map { it.toImmutable() }, + checkRequired("startingAt", startingAt), + endingBefore, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AddUsageFilter = apply { + if (validated) { + return@apply + } + + groupKey() + groupValues() + startingAt() + endingBefore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (groupKey.asKnown().isPresent) 1 else 0) + + (groupValues.asKnown().getOrNull()?.size ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddUsageFilter && + groupKey == other.groupKey && + groupValues == other.groupValues && + startingAt == other.startingAt && + endingBefore == other.endingBefore && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupKey, + groupValues, + startingAt, + endingBefore, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddUsageFilter{groupKey=$groupKey, groupValues=$groupValues, startingAt=$startingAt, endingBefore=$endingBefore, additionalProperties=$additionalProperties}" + } + + class ArchiveCommit + @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 MetronomeInvalidDataException 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 [ArchiveCommit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ArchiveCommit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(archiveCommit: ArchiveCommit) = apply { + id = archiveCommit.id + additionalProperties = archiveCommit.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 [ArchiveCommit]. + * + * 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(): ArchiveCommit = + ArchiveCommit(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ArchiveCommit = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ArchiveCommit && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ArchiveCommit{id=$id, additionalProperties=$additionalProperties}" + } + + class ArchiveCredit + @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 MetronomeInvalidDataException 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 [ArchiveCredit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ArchiveCredit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(archiveCredit: ArchiveCredit) = apply { + id = archiveCredit.id + additionalProperties = archiveCredit.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 [ArchiveCredit]. + * + * 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(): ArchiveCredit = + ArchiveCredit(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ArchiveCredit = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ArchiveCredit && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ArchiveCredit{id=$id, additionalProperties=$additionalProperties}" + } + + class ArchiveScheduledCharge + @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 MetronomeInvalidDataException 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 + * [ArchiveScheduledCharge]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ArchiveScheduledCharge]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(archiveScheduledCharge: ArchiveScheduledCharge) = apply { + id = archiveScheduledCharge.id + additionalProperties = + archiveScheduledCharge.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 [ArchiveScheduledCharge]. + * + * 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(): ArchiveScheduledCharge = + ArchiveScheduledCharge( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ArchiveScheduledCharge = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 ArchiveScheduledCharge && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ArchiveScheduledCharge{id=$id, additionalProperties=$additionalProperties}" + } + + class RemoveOverride + @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 MetronomeInvalidDataException 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 [RemoveOverride]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveOverride]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(removeOverride: RemoveOverride) = apply { + id = removeOverride.id + additionalProperties = removeOverride.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 [RemoveOverride]. + * + * 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(): RemoveOverride = + RemoveOverride(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): RemoveOverride = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RemoveOverride && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveOverride{id=$id, additionalProperties=$additionalProperties}" + } + + class UpdateCommit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val accessSchedule: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val description: JsonField, + private val hierarchyConfiguration: JsonField, + private val invoiceSchedule: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val priority: JsonField, + private val productId: JsonField, + private val rateType: JsonField, + private val rolloverFraction: JsonField, + private val specifiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("access_schedule") + @ExcludeMissing + accessSchedule: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("invoice_schedule") + @ExcludeMissing + invoiceSchedule: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product_id") + @ExcludeMissing + productId: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + ) : this( + id, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + invoiceSchedule, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + specifiers, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun accessSchedule(): Optional = + accessSchedule.getOptional("access_schedule") + + /** + * Which products the commit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the commit applies to all + * products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * Which tags the commit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the commit applies to all + * products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Optional configuration for commit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun invoiceSchedule(): Optional = + invoiceSchedule.getOptional("invoice_schedule") + + /** + * @throws MetronomeInvalidDataException 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 MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * If multiple commits are applicable, the one with the lower priority will apply + * first. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun priority(): Optional = priority.getOptional("priority") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun productId(): Optional = productId.getOptional("product_id") + + /** + * If set, the commit's rate type was updated to the specified value. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rateType(): Optional = rateType.getOptional("rate_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = + rolloverFraction.getOptional("rollover_fraction") + + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. This field cannot be + * used together with `applicable_product_ids` or `applicable_product_tags`. + * Instead, to target usage by product or product tag, pass those values in the body + * of `specifiers`. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [accessSchedule]. + * + * Unlike [accessSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_schedule") + @ExcludeMissing + fun _accessSchedule(): JsonField = accessSchedule + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * Returns the raw JSON value of [invoiceSchedule]. + * + * Unlike [invoiceSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_schedule") + @ExcludeMissing + fun _invoiceSchedule(): JsonField = invoiceSchedule + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [productId]. + * + * Unlike [productId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product_id") + @ExcludeMissing + fun _productId(): JsonField = productId + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + @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 [UpdateCommit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateCommit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var accessSchedule: JsonField = JsonMissing.of() + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var description: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var invoiceSchedule: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var priority: JsonField = JsonMissing.of() + private var productId: JsonField = JsonMissing.of() + private var rateType: JsonField = JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var specifiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateCommit: UpdateCommit) = apply { + id = updateCommit.id + accessSchedule = updateCommit.accessSchedule + applicableProductIds = + updateCommit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + updateCommit.applicableProductTags.map { it.toMutableList() } + description = updateCommit.description + hierarchyConfiguration = updateCommit.hierarchyConfiguration + invoiceSchedule = updateCommit.invoiceSchedule + name = updateCommit.name + netsuiteSalesOrderId = updateCommit.netsuiteSalesOrderId + priority = updateCommit.priority + productId = updateCommit.productId + rateType = updateCommit.rateType + rolloverFraction = updateCommit.rolloverFraction + specifiers = updateCommit.specifiers.map { it.toMutableList() } + additionalProperties = updateCommit.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 accessSchedule(accessSchedule: AccessSchedule) = + accessSchedule(JsonField.of(accessSchedule)) + + /** + * Sets [Builder.accessSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.accessSchedule] with a well-typed + * [AccessSchedule] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun accessSchedule(accessSchedule: JsonField) = apply { + this.accessSchedule = accessSchedule + } + + /** + * Which products the commit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the commit applies to + * all products. + */ + fun applicableProductIds(applicableProductIds: List?) = + applicableProductIds(JsonField.ofNullable(applicableProductIds)) + + /** + * Alias for calling [Builder.applicableProductIds] with + * `applicableProductIds.orElse(null)`. + */ + fun applicableProductIds(applicableProductIds: Optional>) = + applicableProductIds(applicableProductIds.getOrNull()) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + /** + * Which tags the commit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the commit applies to + * all products. + */ + fun applicableProductTags(applicableProductTags: List?) = + applicableProductTags(JsonField.ofNullable(applicableProductTags)) + + /** + * Alias for calling [Builder.applicableProductTags] with + * `applicableProductTags.orElse(null)`. + */ + fun applicableProductTags(applicableProductTags: Optional>) = + applicableProductTags(applicableProductTags.getOrNull()) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** Optional configuration for commit hierarchy access control */ + fun hierarchyConfiguration( + hierarchyConfiguration: CommitHierarchyConfiguration + ) = hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + fun invoiceSchedule(invoiceSchedule: InvoiceSchedule) = + invoiceSchedule(JsonField.of(invoiceSchedule)) + + /** + * Sets [Builder.invoiceSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceSchedule] with a well-typed + * [InvoiceSchedule] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun invoiceSchedule(invoiceSchedule: JsonField) = apply { + this.invoiceSchedule = invoiceSchedule + } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String?) = + netsuiteSalesOrderId(JsonField.ofNullable(netsuiteSalesOrderId)) + + /** + * Alias for calling [Builder.netsuiteSalesOrderId] with + * `netsuiteSalesOrderId.orElse(null)`. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: Optional) = + netsuiteSalesOrderId(netsuiteSalesOrderId.getOrNull()) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** + * If multiple commits are applicable, the one with the lower priority will + * apply first. + */ + fun priority(priority: Double?) = priority(JsonField.ofNullable(priority)) + + /** + * Alias for [Builder.priority]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun priority(priority: Double) = priority(priority as Double?) + + /** Alias for calling [Builder.priority] with `priority.orElse(null)`. */ + fun priority(priority: Optional) = priority(priority.getOrNull()) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun productId(productId: String) = productId(JsonField.of(productId)) + + /** + * Sets [Builder.productId] to an arbitrary JSON value. + * + * You should usually call [Builder.productId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun productId(productId: JsonField) = apply { + this.productId = productId + } + + /** If set, the commit's rate type was updated to the specified value. */ + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + fun rolloverFraction(rolloverFraction: Double?) = + rolloverFraction(JsonField.ofNullable(rolloverFraction)) + + /** + * Alias for [Builder.rolloverFraction]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(rolloverFraction as Double?) + + /** + * Alias for calling [Builder.rolloverFraction] with + * `rolloverFraction.orElse(null)`. + */ + fun rolloverFraction(rolloverFraction: Optional) = + rolloverFraction(rolloverFraction.getOrNull()) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. This + * field cannot be used together with `applicable_product_ids` or + * `applicable_product_tags`. Instead, to target usage by product or product + * tag, pass those values in the body of `specifiers`. + */ + fun specifiers(specifiers: List?) = + specifiers(JsonField.ofNullable(specifiers)) + + /** Alias for calling [Builder.specifiers] with `specifiers.orElse(null)`. */ + fun specifiers(specifiers: Optional>) = + specifiers(specifiers.getOrNull()) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifierInput] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpecifier(specifier: CommitSpecifierInput) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + 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 [UpdateCommit]. + * + * 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(): UpdateCommit = + UpdateCommit( + checkRequired("id", id), + accessSchedule, + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + description, + hierarchyConfiguration, + invoiceSchedule, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateCommit = apply { + if (validated) { + return@apply + } + + id() + accessSchedule().ifPresent { it.validate() } + applicableProductIds() + applicableProductTags() + description() + hierarchyConfiguration().ifPresent { it.validate() } + invoiceSchedule().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + priority() + productId() + rateType().ifPresent { it.validate() } + rolloverFraction() + specifiers().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (accessSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (invoiceSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (if (productId.asKnown().isPresent) 1 else 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class AccessSchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val addScheduleItems: JsonField>, + private val removeScheduleItems: JsonField>, + private val updateScheduleItems: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("add_schedule_items") + @ExcludeMissing + addScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("remove_schedule_items") + @ExcludeMissing + removeScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("update_schedule_items") + @ExcludeMissing + updateScheduleItems: JsonField> = JsonMissing.of(), + ) : this( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun addScheduleItems(): Optional> = + addScheduleItems.getOptional("add_schedule_items") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun removeScheduleItems(): Optional> = + removeScheduleItems.getOptional("remove_schedule_items") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun updateScheduleItems(): Optional> = + updateScheduleItems.getOptional("update_schedule_items") + + /** + * Returns the raw JSON value of [addScheduleItems]. + * + * Unlike [addScheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_schedule_items") + @ExcludeMissing + fun _addScheduleItems(): JsonField> = addScheduleItems + + /** + * Returns the raw JSON value of [removeScheduleItems]. + * + * Unlike [removeScheduleItems], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("remove_schedule_items") + @ExcludeMissing + fun _removeScheduleItems(): JsonField> = + removeScheduleItems + + /** + * Returns the raw JSON value of [updateScheduleItems]. + * + * Unlike [updateScheduleItems], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("update_schedule_items") + @ExcludeMissing + fun _updateScheduleItems(): JsonField> = + updateScheduleItems + + @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 + * [AccessSchedule]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccessSchedule]. */ + class Builder internal constructor() { + + private var addScheduleItems: JsonField>? = + null + private var removeScheduleItems: + JsonField>? = + null + private var updateScheduleItems: + JsonField>? = + null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(accessSchedule: AccessSchedule) = apply { + addScheduleItems = + accessSchedule.addScheduleItems.map { it.toMutableList() } + removeScheduleItems = + accessSchedule.removeScheduleItems.map { it.toMutableList() } + updateScheduleItems = + accessSchedule.updateScheduleItems.map { it.toMutableList() } + additionalProperties = + accessSchedule.additionalProperties.toMutableMap() + } + + fun addScheduleItems(addScheduleItems: List) = + addScheduleItems(JsonField.of(addScheduleItems)) + + /** + * Sets [Builder.addScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.addScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun addScheduleItems(addScheduleItems: JsonField>) = + apply { + this.addScheduleItems = addScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [AddScheduleItem] to [addScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addAddScheduleItem(addScheduleItem: AddScheduleItem) = apply { + addScheduleItems = + (addScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("addScheduleItems", it).add(addScheduleItem) + } + } + + fun removeScheduleItems(removeScheduleItems: List) = + removeScheduleItems(JsonField.of(removeScheduleItems)) + + /** + * Sets [Builder.removeScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.removeScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun removeScheduleItems( + removeScheduleItems: JsonField> + ) = apply { + this.removeScheduleItems = + removeScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [RemoveScheduleItem] to [removeScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addRemoveScheduleItem(removeScheduleItem: RemoveScheduleItem) = apply { + removeScheduleItems = + (removeScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("removeScheduleItems", it).add(removeScheduleItem) + } + } + + fun updateScheduleItems(updateScheduleItems: List) = + updateScheduleItems(JsonField.of(updateScheduleItems)) + + /** + * Sets [Builder.updateScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.updateScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun updateScheduleItems( + updateScheduleItems: JsonField> + ) = apply { + this.updateScheduleItems = + updateScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateScheduleItem] to [updateScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addUpdateScheduleItem(updateScheduleItem: UpdateScheduleItem) = apply { + updateScheduleItems = + (updateScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("updateScheduleItems", it).add(updateScheduleItem) + } + } + + 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 [AccessSchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AccessSchedule = + AccessSchedule( + (addScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (removeScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (updateScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AccessSchedule = apply { + if (validated) { + return@apply + } + + addScheduleItems().ifPresent { it.forEach { it.validate() } } + removeScheduleItems().ifPresent { it.forEach { it.validate() } } + updateScheduleItems().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (addScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (removeScheduleItems.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + (updateScheduleItems.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + class AddScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(amount, endingBefore, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * RFC 3339 timestamp (exclusive) + * + * @throws MetronomeInvalidDataException 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 endingBefore(): OffsetDateTime = + endingBefore.getRequired("ending_before") + + /** + * RFC 3339 timestamp (inclusive) + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [AddScheduleItem]. + * + * The following fields are required: + * ```java + * .amount() + * .endingBefore() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddScheduleItem]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var endingBefore: JsonField? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(addScheduleItem: AddScheduleItem) = apply { + amount = addScheduleItem.amount + endingBefore = addScheduleItem.endingBefore + startingAt = addScheduleItem.startingAt + additionalProperties = + addScheduleItem.additionalProperties.toMutableMap() + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** RFC 3339 timestamp (exclusive) */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** RFC 3339 timestamp (inclusive) */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [AddScheduleItem]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .amount() + * .endingBefore() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddScheduleItem = + AddScheduleItem( + checkRequired("amount", amount), + checkRequired("endingBefore", endingBefore), + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AddScheduleItem = apply { + if (validated) { + return@apply + } + + amount() + endingBefore() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddScheduleItem && + amount == other.amount && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, endingBefore, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddScheduleItem{amount=$amount, endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + class RemoveScheduleItem + @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 MetronomeInvalidDataException 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 + * [RemoveScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(removeScheduleItem: RemoveScheduleItem) = apply { + id = removeScheduleItem.id + additionalProperties = + removeScheduleItem.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 [RemoveScheduleItem]. + * + * 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(): RemoveScheduleItem = + RemoveScheduleItem( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RemoveScheduleItem = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RemoveScheduleItem && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveScheduleItem{id=$id, additionalProperties=$additionalProperties}" + } + + class UpdateScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val amount: JsonField, + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(id, amount, endingBefore, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * RFC 3339 timestamp (exclusive) + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * RFC 3339 timestamp (inclusive) + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun startingAt(): Optional = + startingAt.getOptional("starting_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [UpdateScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var startingAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(updateScheduleItem: UpdateScheduleItem) = apply { + id = updateScheduleItem.id + amount = updateScheduleItem.amount + endingBefore = updateScheduleItem.endingBefore + startingAt = updateScheduleItem.startingAt + additionalProperties = + updateScheduleItem.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 amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** RFC 3339 timestamp (exclusive) */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** RFC 3339 timestamp (inclusive) */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [UpdateScheduleItem]. + * + * 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(): UpdateScheduleItem = + UpdateScheduleItem( + checkRequired("id", id), + amount, + endingBefore, + startingAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): UpdateScheduleItem = apply { + if (validated) { + return@apply + } + + id() + amount() + endingBefore() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateScheduleItem && + id == other.id && + amount == other.amount && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, amount, endingBefore, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateScheduleItem{id=$id, amount=$amount, endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccessSchedule && + addScheduleItems == other.addScheduleItems && + removeScheduleItems == other.removeScheduleItems && + updateScheduleItems == other.updateScheduleItems && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessSchedule{addScheduleItems=$addScheduleItems, removeScheduleItems=$removeScheduleItems, updateScheduleItems=$updateScheduleItems, additionalProperties=$additionalProperties}" + } + + class InvoiceSchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val addScheduleItems: JsonField>, + private val removeScheduleItems: JsonField>, + private val updateScheduleItems: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("add_schedule_items") + @ExcludeMissing + addScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("remove_schedule_items") + @ExcludeMissing + removeScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("update_schedule_items") + @ExcludeMissing + updateScheduleItems: JsonField> = JsonMissing.of(), + ) : this( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun addScheduleItems(): Optional> = + addScheduleItems.getOptional("add_schedule_items") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun removeScheduleItems(): Optional> = + removeScheduleItems.getOptional("remove_schedule_items") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun updateScheduleItems(): Optional> = + updateScheduleItems.getOptional("update_schedule_items") + + /** + * Returns the raw JSON value of [addScheduleItems]. + * + * Unlike [addScheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_schedule_items") + @ExcludeMissing + fun _addScheduleItems(): JsonField> = addScheduleItems + + /** + * Returns the raw JSON value of [removeScheduleItems]. + * + * Unlike [removeScheduleItems], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("remove_schedule_items") + @ExcludeMissing + fun _removeScheduleItems(): JsonField> = + removeScheduleItems + + /** + * Returns the raw JSON value of [updateScheduleItems]. + * + * Unlike [updateScheduleItems], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("update_schedule_items") + @ExcludeMissing + fun _updateScheduleItems(): JsonField> = + updateScheduleItems + + @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 + * [InvoiceSchedule]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InvoiceSchedule]. */ + class Builder internal constructor() { + + private var addScheduleItems: JsonField>? = + null + private var removeScheduleItems: + JsonField>? = + null + private var updateScheduleItems: + JsonField>? = + null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(invoiceSchedule: InvoiceSchedule) = apply { + addScheduleItems = + invoiceSchedule.addScheduleItems.map { it.toMutableList() } + removeScheduleItems = + invoiceSchedule.removeScheduleItems.map { it.toMutableList() } + updateScheduleItems = + invoiceSchedule.updateScheduleItems.map { it.toMutableList() } + additionalProperties = + invoiceSchedule.additionalProperties.toMutableMap() + } + + fun addScheduleItems(addScheduleItems: List) = + addScheduleItems(JsonField.of(addScheduleItems)) + + /** + * Sets [Builder.addScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.addScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun addScheduleItems(addScheduleItems: JsonField>) = + apply { + this.addScheduleItems = addScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [AddScheduleItem] to [addScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addAddScheduleItem(addScheduleItem: AddScheduleItem) = apply { + addScheduleItems = + (addScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("addScheduleItems", it).add(addScheduleItem) + } + } + + fun removeScheduleItems(removeScheduleItems: List) = + removeScheduleItems(JsonField.of(removeScheduleItems)) + + /** + * Sets [Builder.removeScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.removeScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun removeScheduleItems( + removeScheduleItems: JsonField> + ) = apply { + this.removeScheduleItems = + removeScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [RemoveScheduleItem] to [removeScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addRemoveScheduleItem(removeScheduleItem: RemoveScheduleItem) = apply { + removeScheduleItems = + (removeScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("removeScheduleItems", it).add(removeScheduleItem) + } + } + + fun updateScheduleItems(updateScheduleItems: List) = + updateScheduleItems(JsonField.of(updateScheduleItems)) + + /** + * Sets [Builder.updateScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.updateScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun updateScheduleItems( + updateScheduleItems: JsonField> + ) = apply { + this.updateScheduleItems = + updateScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateScheduleItem] to [updateScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addUpdateScheduleItem(updateScheduleItem: UpdateScheduleItem) = apply { + updateScheduleItems = + (updateScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("updateScheduleItems", it).add(updateScheduleItem) + } + } + + 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 [InvoiceSchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InvoiceSchedule = + InvoiceSchedule( + (addScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (removeScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (updateScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InvoiceSchedule = apply { + if (validated) { + return@apply + } + + addScheduleItems().ifPresent { it.forEach { it.validate() } } + removeScheduleItems().ifPresent { it.forEach { it.validate() } } + updateScheduleItems().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (addScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (removeScheduleItems.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + (updateScheduleItems.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + class AddScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val timestamp: JsonField, + private val amount: JsonField, + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(timestamp, amount, quantity, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 timestamp(): OffsetDateTime = timestamp.getRequired("timestamp") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [AddScheduleItem]. + * + * The following fields are required: + * ```java + * .timestamp() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddScheduleItem]. */ + class Builder internal constructor() { + + private var timestamp: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(addScheduleItem: AddScheduleItem) = apply { + timestamp = addScheduleItem.timestamp + amount = addScheduleItem.amount + quantity = addScheduleItem.quantity + unitPrice = addScheduleItem.unitPrice + additionalProperties = + addScheduleItem.additionalProperties.toMutableMap() + } + + fun timestamp(timestamp: OffsetDateTime) = + timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed + * [Double] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [AddScheduleItem]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .timestamp() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddScheduleItem = + AddScheduleItem( + checkRequired("timestamp", timestamp), + amount, + quantity, + unitPrice, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AddScheduleItem = apply { + if (validated) { + return@apply + } + + timestamp() + amount() + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (timestamp.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddScheduleItem && + timestamp == other.timestamp && + amount == other.amount && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + timestamp, + amount, + quantity, + unitPrice, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddScheduleItem{timestamp=$timestamp, amount=$amount, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + class RemoveScheduleItem + @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 MetronomeInvalidDataException 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 + * [RemoveScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(removeScheduleItem: RemoveScheduleItem) = apply { + id = removeScheduleItem.id + additionalProperties = + removeScheduleItem.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 [RemoveScheduleItem]. + * + * 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(): RemoveScheduleItem = + RemoveScheduleItem( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RemoveScheduleItem = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RemoveScheduleItem && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveScheduleItem{id=$id, additionalProperties=$additionalProperties}" + } + + class UpdateScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val amount: JsonField, + private val quantity: JsonField, + private val timestamp: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(id, amount, quantity, timestamp, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun timestamp(): Optional = + timestamp.getOptional("timestamp") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [UpdateScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var timestamp: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(updateScheduleItem: UpdateScheduleItem) = apply { + id = updateScheduleItem.id + amount = updateScheduleItem.amount + quantity = updateScheduleItem.quantity + timestamp = updateScheduleItem.timestamp + unitPrice = updateScheduleItem.unitPrice + additionalProperties = + updateScheduleItem.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 amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun timestamp(timestamp: OffsetDateTime) = + timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed + * [Double] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [UpdateScheduleItem]. + * + * 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(): UpdateScheduleItem = + UpdateScheduleItem( + checkRequired("id", id), + amount, + quantity, + timestamp, + unitPrice, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): UpdateScheduleItem = apply { + if (validated) { + return@apply + } + + id() + amount() + quantity() + timestamp() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (timestamp.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateScheduleItem && + id == other.id && + amount == other.amount && + quantity == other.quantity && + timestamp == other.timestamp && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + quantity, + timestamp, + unitPrice, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateScheduleItem{id=$id, amount=$amount, quantity=$quantity, timestamp=$timestamp, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InvoiceSchedule && + addScheduleItems == other.addScheduleItems && + removeScheduleItems == other.removeScheduleItems && + updateScheduleItems == other.updateScheduleItems && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InvoiceSchedule{addScheduleItems=$addScheduleItems, removeScheduleItems=$removeScheduleItems, updateScheduleItems=$updateScheduleItems, additionalProperties=$additionalProperties}" + } + + /** If set, the commit's rate type was updated to the specified value. */ + class RateType + @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 COMMIT_RATE = of("COMMIT_RATE") + + @JvmField val LIST_RATE = of("LIST_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + COMMIT_RATE, + LIST_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + COMMIT_RATE, + LIST_RATE, + /** + * An enum member indicating that [RateType] 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) { + COMMIT_RATE -> Value.COMMIT_RATE + LIST_RATE -> Value.LIST_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + COMMIT_RATE -> Known.COMMIT_RATE + LIST_RATE -> Known.LIST_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && 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 UpdateCommit && + id == other.id && + accessSchedule == other.accessSchedule && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + description == other.description && + hierarchyConfiguration == other.hierarchyConfiguration && + invoiceSchedule == other.invoiceSchedule && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + priority == other.priority && + productId == other.productId && + rateType == other.rateType && + rolloverFraction == other.rolloverFraction && + specifiers == other.specifiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + invoiceSchedule, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + specifiers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateCommit{id=$id, accessSchedule=$accessSchedule, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, description=$description, hierarchyConfiguration=$hierarchyConfiguration, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, productId=$productId, rateType=$rateType, rolloverFraction=$rolloverFraction, specifiers=$specifiers, additionalProperties=$additionalProperties}" + } + + class UpdateCredit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val accessSchedule: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val description: JsonField, + private val hierarchyConfiguration: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val priority: JsonField, + private val productId: JsonField, + private val rateType: JsonField, + private val rolloverFraction: JsonField, + private val specifiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("access_schedule") + @ExcludeMissing + accessSchedule: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + hierarchyConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product_id") + @ExcludeMissing + productId: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + @JsonProperty("rollover_fraction") + @ExcludeMissing + rolloverFraction: JsonField = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + ) : this( + id, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + specifiers, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun accessSchedule(): Optional = + accessSchedule.getOptional("access_schedule") + + /** + * Which products the credit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the credit applies to all + * products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * Which tags the credit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the credit applies to all + * products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Optional configuration for credit hierarchy access control + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun hierarchyConfiguration(): Optional = + hierarchyConfiguration.getOptional("hierarchy_configuration") + + /** + * @throws MetronomeInvalidDataException 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 MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * If multiple credits are applicable, the one with the lower priority will apply + * first. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun priority(): Optional = priority.getOptional("priority") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun productId(): Optional = productId.getOptional("product_id") + + /** + * If set, the credit's rate type was updated to the specified value. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rateType(): Optional = rateType.getOptional("rate_type") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rolloverFraction(): Optional = + rolloverFraction.getOptional("rollover_fraction") + + /** + * List of filters that determine what kind of customer usage draws down a commit or + * credit. A customer's usage needs to meet the condition of at least one of the + * specifiers to contribute to a commit's or credit's drawdown. This field cannot be + * used together with `applicable_product_ids` or `applicable_product_tags`. + * Instead, to target usage by product or product tag, pass those values in the body + * of `specifiers`. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [accessSchedule]. + * + * Unlike [accessSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_schedule") + @ExcludeMissing + fun _accessSchedule(): JsonField = accessSchedule + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [hierarchyConfiguration]. + * + * Unlike [hierarchyConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("hierarchy_configuration") + @ExcludeMissing + fun _hierarchyConfiguration(): JsonField = + hierarchyConfiguration + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [productId]. + * + * Unlike [productId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product_id") + @ExcludeMissing + fun _productId(): JsonField = productId + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + /** + * Returns the raw JSON value of [rolloverFraction]. + * + * Unlike [rolloverFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("rollover_fraction") + @ExcludeMissing + fun _rolloverFraction(): JsonField = rolloverFraction + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + @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 [UpdateCredit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateCredit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var accessSchedule: JsonField = JsonMissing.of() + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var description: JsonField = JsonMissing.of() + private var hierarchyConfiguration: JsonField = + JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var priority: JsonField = JsonMissing.of() + private var productId: JsonField = JsonMissing.of() + private var rateType: JsonField = JsonMissing.of() + private var rolloverFraction: JsonField = JsonMissing.of() + private var specifiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateCredit: UpdateCredit) = apply { + id = updateCredit.id + accessSchedule = updateCredit.accessSchedule + applicableProductIds = + updateCredit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + updateCredit.applicableProductTags.map { it.toMutableList() } + description = updateCredit.description + hierarchyConfiguration = updateCredit.hierarchyConfiguration + name = updateCredit.name + netsuiteSalesOrderId = updateCredit.netsuiteSalesOrderId + priority = updateCredit.priority + productId = updateCredit.productId + rateType = updateCredit.rateType + rolloverFraction = updateCredit.rolloverFraction + specifiers = updateCredit.specifiers.map { it.toMutableList() } + additionalProperties = updateCredit.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 accessSchedule(accessSchedule: AccessSchedule) = + accessSchedule(JsonField.of(accessSchedule)) + + /** + * Sets [Builder.accessSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.accessSchedule] with a well-typed + * [AccessSchedule] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun accessSchedule(accessSchedule: JsonField) = apply { + this.accessSchedule = accessSchedule + } + + /** + * Which products the credit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the credit applies to + * all products. + */ + fun applicableProductIds(applicableProductIds: List?) = + applicableProductIds(JsonField.ofNullable(applicableProductIds)) + + /** + * Alias for calling [Builder.applicableProductIds] with + * `applicableProductIds.orElse(null)`. + */ + fun applicableProductIds(applicableProductIds: Optional>) = + applicableProductIds(applicableProductIds.getOrNull()) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + /** + * Which tags the credit applies to. If applicable_product_ids, + * applicable_product_tags or specifiers are not provided, the credit applies to + * all products. + */ + fun applicableProductTags(applicableProductTags: List?) = + applicableProductTags(JsonField.ofNullable(applicableProductTags)) + + /** + * Alias for calling [Builder.applicableProductTags] with + * `applicableProductTags.orElse(null)`. + */ + fun applicableProductTags(applicableProductTags: Optional>) = + applicableProductTags(applicableProductTags.getOrNull()) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it).add(applicableProductTag) + } + } + + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** Optional configuration for credit hierarchy access control */ + fun hierarchyConfiguration( + hierarchyConfiguration: CommitHierarchyConfiguration + ) = hierarchyConfiguration(JsonField.of(hierarchyConfiguration)) + + /** + * Sets [Builder.hierarchyConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.hierarchyConfiguration] with a well-typed + * [CommitHierarchyConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun hierarchyConfiguration( + hierarchyConfiguration: JsonField + ) = apply { this.hierarchyConfiguration = hierarchyConfiguration } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String?) = + netsuiteSalesOrderId(JsonField.ofNullable(netsuiteSalesOrderId)) + + /** + * Alias for calling [Builder.netsuiteSalesOrderId] with + * `netsuiteSalesOrderId.orElse(null)`. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: Optional) = + netsuiteSalesOrderId(netsuiteSalesOrderId.getOrNull()) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** + * If multiple credits are applicable, the one with the lower priority will + * apply first. + */ + fun priority(priority: Double?) = priority(JsonField.ofNullable(priority)) + + /** + * Alias for [Builder.priority]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun priority(priority: Double) = priority(priority as Double?) + + /** Alias for calling [Builder.priority] with `priority.orElse(null)`. */ + fun priority(priority: Optional) = priority(priority.getOrNull()) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun priority(priority: JsonField) = apply { this.priority = priority } + + fun productId(productId: String) = productId(JsonField.of(productId)) + + /** + * Sets [Builder.productId] to an arbitrary JSON value. + * + * You should usually call [Builder.productId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun productId(productId: JsonField) = apply { + this.productId = productId + } + + /** If set, the credit's rate type was updated to the specified value. */ + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + fun rolloverFraction(rolloverFraction: Double?) = + rolloverFraction(JsonField.ofNullable(rolloverFraction)) + + /** + * Alias for [Builder.rolloverFraction]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun rolloverFraction(rolloverFraction: Double) = + rolloverFraction(rolloverFraction as Double?) + + /** + * Alias for calling [Builder.rolloverFraction] with + * `rolloverFraction.orElse(null)`. + */ + fun rolloverFraction(rolloverFraction: Optional) = + rolloverFraction(rolloverFraction.getOrNull()) + + /** + * Sets [Builder.rolloverFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.rolloverFraction] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rolloverFraction(rolloverFraction: JsonField) = apply { + this.rolloverFraction = rolloverFraction + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. This + * field cannot be used together with `applicable_product_ids` or + * `applicable_product_tags`. Instead, to target usage by product or product + * tag, pass those values in the body of `specifiers`. + */ + fun specifiers(specifiers: List?) = + specifiers(JsonField.ofNullable(specifiers)) + + /** Alias for calling [Builder.specifiers] with `specifiers.orElse(null)`. */ + fun specifiers(specifiers: Optional>) = + specifiers(specifiers.getOrNull()) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifierInput] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSpecifier(specifier: CommitSpecifierInput) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + 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 [UpdateCredit]. + * + * 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(): UpdateCredit = + UpdateCredit( + checkRequired("id", id), + accessSchedule, + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { it.toImmutable() }, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateCredit = apply { + if (validated) { + return@apply + } + + id() + accessSchedule().ifPresent { it.validate() } + applicableProductIds() + applicableProductTags() + description() + hierarchyConfiguration().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + priority() + productId() + rateType().ifPresent { it.validate() } + rolloverFraction() + specifiers().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (accessSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (hierarchyConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (if (productId.asKnown().isPresent) 1 else 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + (if (rolloverFraction.asKnown().isPresent) 1 else 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class AccessSchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val addScheduleItems: JsonField>, + private val removeScheduleItems: JsonField>, + private val updateScheduleItems: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("add_schedule_items") + @ExcludeMissing + addScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("remove_schedule_items") + @ExcludeMissing + removeScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("update_schedule_items") + @ExcludeMissing + updateScheduleItems: JsonField> = JsonMissing.of(), + ) : this( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun addScheduleItems(): Optional> = + addScheduleItems.getOptional("add_schedule_items") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun removeScheduleItems(): Optional> = + removeScheduleItems.getOptional("remove_schedule_items") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun updateScheduleItems(): Optional> = + updateScheduleItems.getOptional("update_schedule_items") + + /** + * Returns the raw JSON value of [addScheduleItems]. + * + * Unlike [addScheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_schedule_items") + @ExcludeMissing + fun _addScheduleItems(): JsonField> = addScheduleItems + + /** + * Returns the raw JSON value of [removeScheduleItems]. + * + * Unlike [removeScheduleItems], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("remove_schedule_items") + @ExcludeMissing + fun _removeScheduleItems(): JsonField> = + removeScheduleItems + + /** + * Returns the raw JSON value of [updateScheduleItems]. + * + * Unlike [updateScheduleItems], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("update_schedule_items") + @ExcludeMissing + fun _updateScheduleItems(): JsonField> = + updateScheduleItems + + @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 + * [AccessSchedule]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccessSchedule]. */ + class Builder internal constructor() { + + private var addScheduleItems: JsonField>? = + null + private var removeScheduleItems: + JsonField>? = + null + private var updateScheduleItems: + JsonField>? = + null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(accessSchedule: AccessSchedule) = apply { + addScheduleItems = + accessSchedule.addScheduleItems.map { it.toMutableList() } + removeScheduleItems = + accessSchedule.removeScheduleItems.map { it.toMutableList() } + updateScheduleItems = + accessSchedule.updateScheduleItems.map { it.toMutableList() } + additionalProperties = + accessSchedule.additionalProperties.toMutableMap() + } + + fun addScheduleItems(addScheduleItems: List) = + addScheduleItems(JsonField.of(addScheduleItems)) + + /** + * Sets [Builder.addScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.addScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun addScheduleItems(addScheduleItems: JsonField>) = + apply { + this.addScheduleItems = addScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [AddScheduleItem] to [addScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addAddScheduleItem(addScheduleItem: AddScheduleItem) = apply { + addScheduleItems = + (addScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("addScheduleItems", it).add(addScheduleItem) + } + } + + fun removeScheduleItems(removeScheduleItems: List) = + removeScheduleItems(JsonField.of(removeScheduleItems)) + + /** + * Sets [Builder.removeScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.removeScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun removeScheduleItems( + removeScheduleItems: JsonField> + ) = apply { + this.removeScheduleItems = + removeScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [RemoveScheduleItem] to [removeScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addRemoveScheduleItem(removeScheduleItem: RemoveScheduleItem) = apply { + removeScheduleItems = + (removeScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("removeScheduleItems", it).add(removeScheduleItem) + } + } + + fun updateScheduleItems(updateScheduleItems: List) = + updateScheduleItems(JsonField.of(updateScheduleItems)) + + /** + * Sets [Builder.updateScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.updateScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun updateScheduleItems( + updateScheduleItems: JsonField> + ) = apply { + this.updateScheduleItems = + updateScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateScheduleItem] to [updateScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addUpdateScheduleItem(updateScheduleItem: UpdateScheduleItem) = apply { + updateScheduleItems = + (updateScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("updateScheduleItems", it).add(updateScheduleItem) + } + } + + 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 [AccessSchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AccessSchedule = + AccessSchedule( + (addScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (removeScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (updateScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AccessSchedule = apply { + if (validated) { + return@apply + } + + addScheduleItems().ifPresent { it.forEach { it.validate() } } + removeScheduleItems().ifPresent { it.forEach { it.validate() } } + updateScheduleItems().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (addScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (removeScheduleItems.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + (updateScheduleItems.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + class AddScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(amount, endingBefore, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * RFC 3339 timestamp (exclusive) + * + * @throws MetronomeInvalidDataException 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 endingBefore(): OffsetDateTime = + endingBefore.getRequired("ending_before") + + /** + * RFC 3339 timestamp (inclusive) + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [AddScheduleItem]. + * + * The following fields are required: + * ```java + * .amount() + * .endingBefore() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddScheduleItem]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var endingBefore: JsonField? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(addScheduleItem: AddScheduleItem) = apply { + amount = addScheduleItem.amount + endingBefore = addScheduleItem.endingBefore + startingAt = addScheduleItem.startingAt + additionalProperties = + addScheduleItem.additionalProperties.toMutableMap() + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** RFC 3339 timestamp (exclusive) */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** RFC 3339 timestamp (inclusive) */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [AddScheduleItem]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .amount() + * .endingBefore() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddScheduleItem = + AddScheduleItem( + checkRequired("amount", amount), + checkRequired("endingBefore", endingBefore), + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AddScheduleItem = apply { + if (validated) { + return@apply + } + + amount() + endingBefore() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddScheduleItem && + amount == other.amount && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, endingBefore, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddScheduleItem{amount=$amount, endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + class RemoveScheduleItem + @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 MetronomeInvalidDataException 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 + * [RemoveScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(removeScheduleItem: RemoveScheduleItem) = apply { + id = removeScheduleItem.id + additionalProperties = + removeScheduleItem.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 [RemoveScheduleItem]. + * + * 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(): RemoveScheduleItem = + RemoveScheduleItem( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RemoveScheduleItem = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RemoveScheduleItem && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveScheduleItem{id=$id, additionalProperties=$additionalProperties}" + } + + class UpdateScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val amount: JsonField, + private val endingBefore: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(id, amount, endingBefore, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * RFC 3339 timestamp (exclusive) + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * RFC 3339 timestamp (inclusive) + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun startingAt(): Optional = + startingAt.getOptional("starting_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [UpdateScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var startingAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(updateScheduleItem: UpdateScheduleItem) = apply { + id = updateScheduleItem.id + amount = updateScheduleItem.amount + endingBefore = updateScheduleItem.endingBefore + startingAt = updateScheduleItem.startingAt + additionalProperties = + updateScheduleItem.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 amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** RFC 3339 timestamp (exclusive) */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + /** RFC 3339 timestamp (inclusive) */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [UpdateScheduleItem]. + * + * 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(): UpdateScheduleItem = + UpdateScheduleItem( + checkRequired("id", id), + amount, + endingBefore, + startingAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): UpdateScheduleItem = apply { + if (validated) { + return@apply + } + + id() + amount() + endingBefore() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateScheduleItem && + id == other.id && + amount == other.amount && + endingBefore == other.endingBefore && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, amount, endingBefore, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateScheduleItem{id=$id, amount=$amount, endingBefore=$endingBefore, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccessSchedule && + addScheduleItems == other.addScheduleItems && + removeScheduleItems == other.removeScheduleItems && + updateScheduleItems == other.updateScheduleItems && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessSchedule{addScheduleItems=$addScheduleItems, removeScheduleItems=$removeScheduleItems, updateScheduleItems=$updateScheduleItems, additionalProperties=$additionalProperties}" + } + + /** If set, the credit's rate type was updated to the specified value. */ + class RateType + @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 LIST_RATE = of("LIST_RATE") + + @JvmField val COMMIT_RATE = of("COMMIT_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + LIST_RATE, + COMMIT_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + LIST_RATE, + COMMIT_RATE, + /** + * An enum member indicating that [RateType] 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) { + LIST_RATE -> Value.LIST_RATE + COMMIT_RATE -> Value.COMMIT_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + LIST_RATE -> Known.LIST_RATE + COMMIT_RATE -> Known.COMMIT_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && 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 UpdateCredit && + id == other.id && + accessSchedule == other.accessSchedule && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + description == other.description && + hierarchyConfiguration == other.hierarchyConfiguration && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + priority == other.priority && + productId == other.productId && + rateType == other.rateType && + rolloverFraction == other.rolloverFraction && + specifiers == other.specifiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + accessSchedule, + applicableProductIds, + applicableProductTags, + description, + hierarchyConfiguration, + name, + netsuiteSalesOrderId, + priority, + productId, + rateType, + rolloverFraction, + specifiers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateCredit{id=$id, accessSchedule=$accessSchedule, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, description=$description, hierarchyConfiguration=$hierarchyConfiguration, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, priority=$priority, productId=$productId, rateType=$rateType, rolloverFraction=$rolloverFraction, specifiers=$specifiers, additionalProperties=$additionalProperties}" + } + + class UpdateDiscount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val customFields: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val schedule: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("custom_fields") + @ExcludeMissing + customFields: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + @JsonProperty("schedule") + @ExcludeMissing + schedule: JsonField = JsonMissing.of(), + ) : this(id, customFields, name, netsuiteSalesOrderId, schedule, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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") + + /** + * Custom fields to be added eg. { "key1": "value1", "key2": "value2" } + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun customFields(): Optional = + customFields.getOptional("custom_fields") + + /** + * @throws MetronomeInvalidDataException 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 MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_id") + + /** + * Must provide either schedule_items or recurring_schedule. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun schedule(): Optional = schedule.getOptional("schedule") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [customFields]. + * + * Unlike [customFields], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("custom_fields") + @ExcludeMissing + fun _customFields(): JsonField = customFields + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + /** + * Returns the raw JSON value of [schedule]. + * + * Unlike [schedule], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("schedule") + @ExcludeMissing + fun _schedule(): JsonField = schedule + + @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 [UpdateDiscount]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateDiscount]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var customFields: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var schedule: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateDiscount: UpdateDiscount) = apply { + id = updateDiscount.id + customFields = updateDiscount.customFields + name = updateDiscount.name + netsuiteSalesOrderId = updateDiscount.netsuiteSalesOrderId + schedule = updateDiscount.schedule + additionalProperties = updateDiscount.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 } + + /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ + fun customFields(customFields: CustomFields) = + customFields(JsonField.of(customFields)) + + /** + * Sets [Builder.customFields] to an arbitrary JSON value. + * + * You should usually call [Builder.customFields] with a well-typed + * [CustomFields] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun customFields(customFields: JsonField) = apply { + this.customFields = customFields + } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String) = + netsuiteSalesOrderId(JsonField.of(netsuiteSalesOrderId)) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + /** Must provide either schedule_items or recurring_schedule. */ + fun schedule(schedule: Schedule) = schedule(JsonField.of(schedule)) + + /** + * Sets [Builder.schedule] to an arbitrary JSON value. + * + * You should usually call [Builder.schedule] with a well-typed [Schedule] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun schedule(schedule: JsonField) = apply { this.schedule = schedule } + + 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 [UpdateDiscount]. + * + * 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(): UpdateDiscount = + UpdateDiscount( + checkRequired("id", id), + customFields, + name, + netsuiteSalesOrderId, + schedule, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateDiscount = apply { + if (validated) { + return@apply + } + + id() + customFields().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + schedule().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (customFields.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + (schedule.asKnown().getOrNull()?.validity() ?: 0) + + /** Custom fields to be added eg. { "key1": "value1", "key2": "value2" } */ + class CustomFields + @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 [CustomFields]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFields]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customFields: CustomFields) = apply { + additionalProperties = customFields.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 [CustomFields]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CustomFields = CustomFields(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomFields = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 CustomFields && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomFields{additionalProperties=$additionalProperties}" + } + + /** Must provide either schedule_items or recurring_schedule. */ + class Schedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val creditTypeId: JsonField, + private val doNotInvoice: JsonField, + private val recurringSchedule: JsonField, + private val scheduleItems: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credit_type_id") + @ExcludeMissing + creditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("do_not_invoice") + @ExcludeMissing + doNotInvoice: JsonField = JsonMissing.of(), + @JsonProperty("recurring_schedule") + @ExcludeMissing + recurringSchedule: JsonField = JsonMissing.of(), + @JsonProperty("schedule_items") + @ExcludeMissing + scheduleItems: JsonField> = JsonMissing.of(), + ) : this( + creditTypeId, + doNotInvoice, + recurringSchedule, + scheduleItems, + mutableMapOf(), + ) + + /** + * Defaults to USD (cents) if not passed. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun creditTypeId(): Optional = + creditTypeId.getOptional("credit_type_id") + + /** + * This field is only applicable to commit invoice schedules. If true, this + * schedule will not generate an invoice. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun doNotInvoice(): Optional = + doNotInvoice.getOptional("do_not_invoice") + + /** + * Enter the unit price and quantity for the charge or instead only send the + * amount. If amount is sent, the unit price is assumed to be the amount and + * quantity is inferred to be 1. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun recurringSchedule(): Optional = + recurringSchedule.getOptional("recurring_schedule") + + /** + * Either provide amount or provide both unit_price and quantity. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun scheduleItems(): Optional> = + scheduleItems.getOptional("schedule_items") + + /** + * Returns the raw JSON value of [creditTypeId]. + * + * Unlike [creditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_type_id") + @ExcludeMissing + fun _creditTypeId(): JsonField = creditTypeId + + /** + * Returns the raw JSON value of [doNotInvoice]. + * + * Unlike [doNotInvoice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("do_not_invoice") + @ExcludeMissing + fun _doNotInvoice(): JsonField = doNotInvoice + + /** + * Returns the raw JSON value of [recurringSchedule]. + * + * Unlike [recurringSchedule], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("recurring_schedule") + @ExcludeMissing + fun _recurringSchedule(): JsonField = recurringSchedule + + /** + * Returns the raw JSON value of [scheduleItems]. + * + * Unlike [scheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("schedule_items") + @ExcludeMissing + fun _scheduleItems(): JsonField> = scheduleItems + + @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 [Schedule]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Schedule]. */ + class Builder internal constructor() { + + private var creditTypeId: JsonField = JsonMissing.of() + private var doNotInvoice: JsonField = JsonMissing.of() + private var recurringSchedule: JsonField = + JsonMissing.of() + private var scheduleItems: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(schedule: Schedule) = apply { + creditTypeId = schedule.creditTypeId + doNotInvoice = schedule.doNotInvoice + recurringSchedule = schedule.recurringSchedule + scheduleItems = schedule.scheduleItems.map { it.toMutableList() } + additionalProperties = schedule.additionalProperties.toMutableMap() + } + + /** Defaults to USD (cents) if not passed. */ + fun creditTypeId(creditTypeId: String) = + creditTypeId(JsonField.of(creditTypeId)) + + /** + * Sets [Builder.creditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.creditTypeId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun creditTypeId(creditTypeId: JsonField) = apply { + this.creditTypeId = creditTypeId + } + + /** + * This field is only applicable to commit invoice schedules. If true, this + * schedule will not generate an invoice. + */ + fun doNotInvoice(doNotInvoice: Boolean) = + doNotInvoice(JsonField.of(doNotInvoice)) + + /** + * Sets [Builder.doNotInvoice] to an arbitrary JSON value. + * + * You should usually call [Builder.doNotInvoice] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun doNotInvoice(doNotInvoice: JsonField) = apply { + this.doNotInvoice = doNotInvoice + } + + /** + * Enter the unit price and quantity for the charge or instead only send the + * amount. If amount is sent, the unit price is assumed to be the amount and + * quantity is inferred to be 1. + */ + fun recurringSchedule(recurringSchedule: RecurringSchedule) = + recurringSchedule(JsonField.of(recurringSchedule)) + + /** + * Sets [Builder.recurringSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.recurringSchedule] with a well-typed + * [RecurringSchedule] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun recurringSchedule(recurringSchedule: JsonField) = + apply { + this.recurringSchedule = recurringSchedule + } + + /** Either provide amount or provide both unit_price and quantity. */ + fun scheduleItems(scheduleItems: List) = + scheduleItems(JsonField.of(scheduleItems)) + + /** + * Sets [Builder.scheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.scheduleItems] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun scheduleItems(scheduleItems: JsonField>) = apply { + this.scheduleItems = scheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [ScheduleItem] to [scheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addScheduleItem(scheduleItem: ScheduleItem) = apply { + scheduleItems = + (scheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("scheduleItems", it).add(scheduleItem) + } + } + + 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 [Schedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Schedule = + Schedule( + creditTypeId, + doNotInvoice, + recurringSchedule, + (scheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Schedule = apply { + if (validated) { + return@apply + } + + creditTypeId() + doNotInvoice() + recurringSchedule().ifPresent { it.validate() } + scheduleItems().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (creditTypeId.asKnown().isPresent) 1 else 0) + + (if (doNotInvoice.asKnown().isPresent) 1 else 0) + + (recurringSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (scheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + /** + * Enter the unit price and quantity for the charge or instead only send the + * amount. If amount is sent, the unit price is assumed to be the amount and + * quantity is inferred to be 1. + */ + class RecurringSchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amountDistribution: JsonField, + private val endingBefore: JsonField, + private val frequency: JsonField, + private val startingAt: JsonField, + private val amount: JsonField, + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount_distribution") + @ExcludeMissing + amountDistribution: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + frequency: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this( + amountDistribution, + endingBefore, + frequency, + startingAt, + amount, + quantity, + unitPrice, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException 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 amountDistribution(): AmountDistribution = + amountDistribution.getRequired("amount_distribution") + + /** + * RFC 3339 timestamp (exclusive). + * + * @throws MetronomeInvalidDataException 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 endingBefore(): OffsetDateTime = + endingBefore.getRequired("ending_before") + + /** + * @throws MetronomeInvalidDataException 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 frequency(): Frequency = frequency.getRequired("frequency") + + /** + * RFC 3339 timestamp (inclusive). + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Amount for the charge. Can be provided instead of unit_price and + * quantity. If amount is sent, the unit_price is assumed to be the amount + * and quantity is inferred to be 1. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * Quantity for the charge. Will be multiplied by unit_price to determine + * the amount and must be specified with unit_price. If specified amount + * cannot be provided. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Unit price for the charge. Will be multiplied by quantity to determine + * the amount and must be specified with quantity. If specified amount + * cannot be provided. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [amountDistribution]. + * + * Unlike [amountDistribution], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("amount_distribution") + @ExcludeMissing + fun _amountDistribution(): JsonField = + amountDistribution + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [frequency]. + * + * Unlike [frequency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [RecurringSchedule]. + * + * The following fields are required: + * ```java + * .amountDistribution() + * .endingBefore() + * .frequency() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RecurringSchedule]. */ + class Builder internal constructor() { + + private var amountDistribution: JsonField? = null + private var endingBefore: JsonField? = null + private var frequency: JsonField? = null + private var startingAt: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(recurringSchedule: RecurringSchedule) = apply { + amountDistribution = recurringSchedule.amountDistribution + endingBefore = recurringSchedule.endingBefore + frequency = recurringSchedule.frequency + startingAt = recurringSchedule.startingAt + amount = recurringSchedule.amount + quantity = recurringSchedule.quantity + unitPrice = recurringSchedule.unitPrice + additionalProperties = + recurringSchedule.additionalProperties.toMutableMap() + } + + fun amountDistribution(amountDistribution: AmountDistribution) = + amountDistribution(JsonField.of(amountDistribution)) + + /** + * Sets [Builder.amountDistribution] to an arbitrary JSON value. + * + * You should usually call [Builder.amountDistribution] with a + * well-typed [AmountDistribution] value instead. This method is + * primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun amountDistribution( + amountDistribution: JsonField + ) = apply { this.amountDistribution = amountDistribution } + + /** RFC 3339 timestamp (exclusive). */ + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun frequency(frequency: Frequency) = frequency(JsonField.of(frequency)) + + /** + * Sets [Builder.frequency] to an arbitrary JSON value. + * + * You should usually call [Builder.frequency] with a well-typed + * [Frequency] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + /** RFC 3339 timestamp (inclusive). */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + /** + * Amount for the charge. Can be provided instead of unit_price and + * quantity. If amount is sent, the unit_price is assumed to be the + * amount and quantity is inferred to be 1. + */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** + * Quantity for the charge. Will be multiplied by unit_price to + * determine the amount and must be specified with unit_price. If + * specified amount cannot be provided. + */ + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + /** + * Unit price for the charge. Will be multiplied by quantity to + * determine the amount and must be specified with quantity. If + * specified amount cannot be provided. + */ + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed + * [Double] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [RecurringSchedule]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .amountDistribution() + * .endingBefore() + * .frequency() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RecurringSchedule = + RecurringSchedule( + checkRequired("amountDistribution", amountDistribution), + checkRequired("endingBefore", endingBefore), + checkRequired("frequency", frequency), + checkRequired("startingAt", startingAt), + amount, + quantity, + unitPrice, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RecurringSchedule = apply { + if (validated) { + return@apply + } + + amountDistribution().validate() + endingBefore() + frequency().validate() + startingAt() + amount() + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (amountDistribution.asKnown().getOrNull()?.validity() ?: 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (frequency.asKnown().getOrNull()?.validity() ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + class AmountDistribution + @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 DIVIDED = of("DIVIDED") + + @JvmField val DIVIDED_ROUNDED = of("DIVIDED_ROUNDED") + + @JvmField val EACH = of("EACH") + + @JvmStatic + fun of(value: String) = AmountDistribution(JsonField.of(value)) + } + + /** An enum containing [AmountDistribution]'s known values. */ + enum class Known { + DIVIDED, + DIVIDED_ROUNDED, + EACH, + } + + /** + * An enum containing [AmountDistribution]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [AmountDistribution] 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 { + DIVIDED, + DIVIDED_ROUNDED, + EACH, + /** + * An enum member indicating that [AmountDistribution] 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) { + DIVIDED -> Value.DIVIDED + DIVIDED_ROUNDED -> Value.DIVIDED_ROUNDED + EACH -> Value.EACH + 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 MetronomeInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + DIVIDED -> Known.DIVIDED + DIVIDED_ROUNDED -> Known.DIVIDED_ROUNDED + EACH -> Known.EACH + else -> + throw MetronomeInvalidDataException( + "Unknown AmountDistribution: $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 MetronomeInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): AmountDistribution = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 AmountDistribution && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Frequency + @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 MONTHLY = of("MONTHLY") + + @JvmField val QUARTERLY = of("QUARTERLY") + + @JvmField val SEMI_ANNUAL = of("SEMI_ANNUAL") + + @JvmField val ANNUAL = of("ANNUAL") + + @JvmField val WEEKLY = of("WEEKLY") + + @JvmStatic fun of(value: String) = Frequency(JsonField.of(value)) + } + + /** An enum containing [Frequency]'s known values. */ + enum class Known { + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + WEEKLY, + } + + /** + * An enum containing [Frequency]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Frequency] 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 { + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + WEEKLY, + /** + * An enum member indicating that [Frequency] 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) { + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUAL -> Value.SEMI_ANNUAL + ANNUAL -> Value.ANNUAL + WEEKLY -> Value.WEEKLY + 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 MetronomeInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUAL -> Known.SEMI_ANNUAL + ANNUAL -> Known.ANNUAL + WEEKLY -> Known.WEEKLY + else -> + throw MetronomeInvalidDataException( + "Unknown Frequency: $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 MetronomeInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Frequency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Frequency && 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 RecurringSchedule && + amountDistribution == other.amountDistribution && + endingBefore == other.endingBefore && + frequency == other.frequency && + startingAt == other.startingAt && + amount == other.amount && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + amountDistribution, + endingBefore, + frequency, + startingAt, + amount, + quantity, + unitPrice, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RecurringSchedule{amountDistribution=$amountDistribution, endingBefore=$endingBefore, frequency=$frequency, startingAt=$startingAt, amount=$amount, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + class ScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val timestamp: JsonField, + private val amount: JsonField, + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(timestamp, amount, quantity, unitPrice, mutableMapOf()) + + /** + * timestamp of the scheduled event + * + * @throws MetronomeInvalidDataException 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 timestamp(): OffsetDateTime = timestamp.getRequired("timestamp") + + /** + * Amount for the charge. Can be provided instead of unit_price and + * quantity. If amount is sent, the unit_price is assumed to be the amount + * and quantity is inferred to be 1. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * Quantity for the charge. Will be multiplied by unit_price to determine + * the amount and must be specified with unit_price. If specified amount + * cannot be provided. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Unit price for the charge. Will be multiplied by quantity to determine + * the amount and must be specified with quantity. If specified amount + * cannot be provided. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [ScheduleItem]. + * + * The following fields are required: + * ```java + * .timestamp() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ScheduleItem]. */ + class Builder internal constructor() { + + private var timestamp: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(scheduleItem: ScheduleItem) = apply { + timestamp = scheduleItem.timestamp + amount = scheduleItem.amount + quantity = scheduleItem.quantity + unitPrice = scheduleItem.unitPrice + additionalProperties = + scheduleItem.additionalProperties.toMutableMap() + } + + /** timestamp of the scheduled event */ + fun timestamp(timestamp: OffsetDateTime) = + timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + /** + * Amount for the charge. Can be provided instead of unit_price and + * quantity. If amount is sent, the unit_price is assumed to be the + * amount and quantity is inferred to be 1. + */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** + * Quantity for the charge. Will be multiplied by unit_price to + * determine the amount and must be specified with unit_price. If + * specified amount cannot be provided. + */ + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + /** + * Unit price for the charge. Will be multiplied by quantity to + * determine the amount and must be specified with quantity. If + * specified amount cannot be provided. + */ + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed + * [Double] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [ScheduleItem]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .timestamp() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ScheduleItem = + ScheduleItem( + checkRequired("timestamp", timestamp), + amount, + quantity, + unitPrice, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ScheduleItem = apply { + if (validated) { + return@apply + } + + timestamp() + amount() + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (timestamp.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ScheduleItem && + timestamp == other.timestamp && + amount == other.amount && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + timestamp, + amount, + quantity, + unitPrice, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScheduleItem{timestamp=$timestamp, amount=$amount, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Schedule && + creditTypeId == other.creditTypeId && + doNotInvoice == other.doNotInvoice && + recurringSchedule == other.recurringSchedule && + scheduleItems == other.scheduleItems && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + creditTypeId, + doNotInvoice, + recurringSchedule, + scheduleItems, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Schedule{creditTypeId=$creditTypeId, doNotInvoice=$doNotInvoice, recurringSchedule=$recurringSchedule, scheduleItems=$scheduleItems, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateDiscount && + id == other.id && + customFields == other.customFields && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + schedule == other.schedule && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + customFields, + name, + netsuiteSalesOrderId, + schedule, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateDiscount{id=$id, customFields=$customFields, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, schedule=$schedule, additionalProperties=$additionalProperties}" + } + + class UpdatePrepaidBalanceThresholdConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val commit: JsonField, + private val customCreditTypeId: JsonField, + private val discountConfiguration: JsonField, + private val isEnabled: JsonField, + private val paymentGateConfig: JsonField, + private val rechargeToAmount: JsonField, + private val thresholdAmount: JsonField, + private val thresholdBalanceSpecifiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("commit") + @ExcludeMissing + commit: JsonField = JsonMissing.of(), + @JsonProperty("custom_credit_type_id") + @ExcludeMissing + customCreditTypeId: JsonField = JsonMissing.of(), + @JsonProperty("discount_configuration") + @ExcludeMissing + discountConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("is_enabled") + @ExcludeMissing + isEnabled: JsonField = JsonMissing.of(), + @JsonProperty("payment_gate_config") + @ExcludeMissing + paymentGateConfig: JsonField = JsonMissing.of(), + @JsonProperty("recharge_to_amount") + @ExcludeMissing + rechargeToAmount: JsonField = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + thresholdBalanceSpecifiers: JsonField> = + JsonMissing.of(), + ) : this( + commit, + customCreditTypeId, + discountConfiguration, + isEnabled, + paymentGateConfig, + rechargeToAmount, + thresholdAmount, + thresholdBalanceSpecifiers, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun commit(): Optional = commit.getOptional("commit") + + /** + * If provided, the threshold, recharge-to amount, and the resulting threshold + * commit amount will be in terms of this credit type instead of the fiat currency. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun customCreditTypeId(): Optional = + customCreditTypeId.getOptional("custom_credit_type_id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun discountConfiguration(): Optional = + discountConfiguration.getOptional("discount_configuration") + + /** + * When set to false, the contract will not be evaluated against the + * threshold_amount. Toggling to true will result an immediate evaluation, + * regardless of prior state. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun isEnabled(): Optional = isEnabled.getOptional("is_enabled") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun paymentGateConfig(): Optional = + paymentGateConfig.getOptional("payment_gate_config") + + /** + * Specify the amount the balance should be recharged to. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rechargeToAmount(): Optional = + rechargeToAmount.getOptional("recharge_to_amount") + + /** + * Specify the threshold amount for the contract. Each time the contract's balance + * lowers to this amount, a threshold charge will be initiated. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun thresholdAmount(): Optional = + thresholdAmount.getOptional("threshold_amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun thresholdBalanceSpecifiers(): Optional> = + thresholdBalanceSpecifiers.getOptional("threshold_balance_specifiers") + + /** + * Returns the raw JSON value of [commit]. + * + * Unlike [commit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("commit") @ExcludeMissing fun _commit(): JsonField = commit + + /** + * Returns the raw JSON value of [customCreditTypeId]. + * + * Unlike [customCreditTypeId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("custom_credit_type_id") + @ExcludeMissing + fun _customCreditTypeId(): JsonField = customCreditTypeId + + /** + * Returns the raw JSON value of [discountConfiguration]. + * + * Unlike [discountConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("discount_configuration") + @ExcludeMissing + fun _discountConfiguration(): JsonField = + discountConfiguration + + /** + * Returns the raw JSON value of [isEnabled]. + * + * Unlike [isEnabled], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("is_enabled") + @ExcludeMissing + fun _isEnabled(): JsonField = isEnabled + + /** + * Returns the raw JSON value of [paymentGateConfig]. + * + * Unlike [paymentGateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_gate_config") + @ExcludeMissing + fun _paymentGateConfig(): JsonField = paymentGateConfig + + /** + * Returns the raw JSON value of [rechargeToAmount]. + * + * Unlike [rechargeToAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("recharge_to_amount") + @ExcludeMissing + fun _rechargeToAmount(): JsonField = rechargeToAmount + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + /** + * Returns the raw JSON value of [thresholdBalanceSpecifiers]. + * + * Unlike [thresholdBalanceSpecifiers], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + fun _thresholdBalanceSpecifiers(): JsonField> = + thresholdBalanceSpecifiers + + @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 + * [UpdatePrepaidBalanceThresholdConfiguration]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdatePrepaidBalanceThresholdConfiguration]. */ + class Builder internal constructor() { + + private var commit: JsonField = JsonMissing.of() + private var customCreditTypeId: JsonField = JsonMissing.of() + private var discountConfiguration: JsonField = + JsonMissing.of() + private var isEnabled: JsonField = JsonMissing.of() + private var paymentGateConfig: JsonField = JsonMissing.of() + private var rechargeToAmount: JsonField = JsonMissing.of() + private var thresholdAmount: JsonField = JsonMissing.of() + private var thresholdBalanceSpecifiers: + JsonField>? = + null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + updatePrepaidBalanceThresholdConfiguration: + UpdatePrepaidBalanceThresholdConfiguration + ) = apply { + commit = updatePrepaidBalanceThresholdConfiguration.commit + customCreditTypeId = + updatePrepaidBalanceThresholdConfiguration.customCreditTypeId + discountConfiguration = + updatePrepaidBalanceThresholdConfiguration.discountConfiguration + isEnabled = updatePrepaidBalanceThresholdConfiguration.isEnabled + paymentGateConfig = + updatePrepaidBalanceThresholdConfiguration.paymentGateConfig + rechargeToAmount = + updatePrepaidBalanceThresholdConfiguration.rechargeToAmount + thresholdAmount = updatePrepaidBalanceThresholdConfiguration.thresholdAmount + thresholdBalanceSpecifiers = + updatePrepaidBalanceThresholdConfiguration.thresholdBalanceSpecifiers + .map { it.toMutableList() } + additionalProperties = + updatePrepaidBalanceThresholdConfiguration.additionalProperties + .toMutableMap() + } + + fun commit(commit: Commit) = commit(JsonField.of(commit)) + + /** + * Sets [Builder.commit] to an arbitrary JSON value. + * + * You should usually call [Builder.commit] with a well-typed [Commit] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun commit(commit: JsonField) = apply { this.commit = commit } + + /** + * If provided, the threshold, recharge-to amount, and the resulting threshold + * commit amount will be in terms of this credit type instead of the fiat + * currency. + */ + fun customCreditTypeId(customCreditTypeId: String?) = + customCreditTypeId(JsonField.ofNullable(customCreditTypeId)) + + /** + * Alias for calling [Builder.customCreditTypeId] with + * `customCreditTypeId.orElse(null)`. + */ + fun customCreditTypeId(customCreditTypeId: Optional) = + customCreditTypeId(customCreditTypeId.getOrNull()) + + /** + * Sets [Builder.customCreditTypeId] to an arbitrary JSON value. + * + * You should usually call [Builder.customCreditTypeId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun customCreditTypeId(customCreditTypeId: JsonField) = apply { + this.customCreditTypeId = customCreditTypeId + } + + fun discountConfiguration(discountConfiguration: DiscountConfiguration?) = + discountConfiguration(JsonField.ofNullable(discountConfiguration)) + + /** + * Alias for calling [Builder.discountConfiguration] with + * `discountConfiguration.orElse(null)`. + */ + fun discountConfiguration( + discountConfiguration: Optional + ) = discountConfiguration(discountConfiguration.getOrNull()) + + /** + * Sets [Builder.discountConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.discountConfiguration] with a well-typed + * [DiscountConfiguration] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun discountConfiguration( + discountConfiguration: JsonField + ) = apply { this.discountConfiguration = discountConfiguration } + + /** + * When set to false, the contract will not be evaluated against the + * threshold_amount. Toggling to true will result an immediate evaluation, + * regardless of prior state. + */ + fun isEnabled(isEnabled: Boolean) = isEnabled(JsonField.of(isEnabled)) + + /** + * Sets [Builder.isEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.isEnabled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun isEnabled(isEnabled: JsonField) = apply { + this.isEnabled = isEnabled + } + + fun paymentGateConfig(paymentGateConfig: PaymentGateConfigV2) = + paymentGateConfig(JsonField.of(paymentGateConfig)) + + /** + * Sets [Builder.paymentGateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentGateConfig] with a well-typed + * [PaymentGateConfigV2] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun paymentGateConfig(paymentGateConfig: JsonField) = + apply { + this.paymentGateConfig = paymentGateConfig + } + + /** Specify the amount the balance should be recharged to. */ + fun rechargeToAmount(rechargeToAmount: Double) = + rechargeToAmount(JsonField.of(rechargeToAmount)) + + /** + * Sets [Builder.rechargeToAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.rechargeToAmount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun rechargeToAmount(rechargeToAmount: JsonField) = apply { + this.rechargeToAmount = rechargeToAmount + } + + /** + * Specify the threshold amount for the contract. Each time the contract's + * balance lowers to this amount, a threshold charge will be initiated. + */ + fun thresholdAmount(thresholdAmount: Double) = + thresholdAmount(JsonField.of(thresholdAmount)) + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } + + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: List? + ) = thresholdBalanceSpecifiers(JsonField.ofNullable(thresholdBalanceSpecifiers)) + + /** + * Alias for calling [Builder.thresholdBalanceSpecifiers] with + * `thresholdBalanceSpecifiers.orElse(null)`. + */ + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: Optional> + ) = thresholdBalanceSpecifiers(thresholdBalanceSpecifiers.getOrNull()) + + /** + * Sets [Builder.thresholdBalanceSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdBalanceSpecifiers] with a + * well-typed `List` value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: JsonField> + ) = apply { + this.thresholdBalanceSpecifiers = + thresholdBalanceSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ThresholdBalanceSpecifier] to [thresholdBalanceSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addThresholdBalanceSpecifier( + thresholdBalanceSpecifier: ThresholdBalanceSpecifier + ) = apply { + thresholdBalanceSpecifiers = + (thresholdBalanceSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("thresholdBalanceSpecifiers", it) + .add(thresholdBalanceSpecifier) + } + } + + 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 + * [UpdatePrepaidBalanceThresholdConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): UpdatePrepaidBalanceThresholdConfiguration = + UpdatePrepaidBalanceThresholdConfiguration( + commit, + customCreditTypeId, + discountConfiguration, + isEnabled, + paymentGateConfig, + rechargeToAmount, + thresholdAmount, + (thresholdBalanceSpecifiers ?: JsonMissing.of()).map { + it.toImmutable() + }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdatePrepaidBalanceThresholdConfiguration = apply { + if (validated) { + return@apply + } + + commit().ifPresent { it.validate() } + customCreditTypeId() + discountConfiguration().ifPresent { it.validate() } + isEnabled() + paymentGateConfig().ifPresent { it.validate() } + rechargeToAmount() + thresholdAmount() + thresholdBalanceSpecifiers().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (commit.asKnown().getOrNull()?.validity() ?: 0) + + (if (customCreditTypeId.asKnown().isPresent) 1 else 0) + + (discountConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (isEnabled.asKnown().isPresent) 1 else 0) + + (paymentGateConfig.asKnown().getOrNull()?.validity() ?: 0) + + (if (rechargeToAmount.asKnown().isPresent) 1 else 0) + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + (thresholdBalanceSpecifiers.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + class Commit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val description: JsonField, + private val name: JsonField, + private val priority: JsonField, + private val productId: JsonField, + private val applicableProductIds: JsonField>, + private val applicableProductTags: JsonField>, + private val specifiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("priority") + @ExcludeMissing + priority: JsonField = JsonMissing.of(), + @JsonProperty("product_id") + @ExcludeMissing + productId: JsonField = JsonMissing.of(), + @JsonProperty("applicable_product_ids") + @ExcludeMissing + applicableProductIds: JsonField> = JsonMissing.of(), + @JsonProperty("applicable_product_tags") + @ExcludeMissing + applicableProductTags: JsonField> = JsonMissing.of(), + @JsonProperty("specifiers") + @ExcludeMissing + specifiers: JsonField> = JsonMissing.of(), + ) : this( + description, + name, + priority, + productId, + applicableProductIds, + applicableProductTags, + specifiers, + mutableMapOf(), + ) + + fun toUpdateBaseThresholdCommit(): UpdateBaseThresholdCommit = + UpdateBaseThresholdCommit.builder() + .description(description) + .name(name) + .priority(priority) + .productId(productId) + .build() + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Specify the name of the line item for the threshold charge. If left blank, it + * will default to the commit product name. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * The priority of the commit, used to determine drawdown order. Lower priority + * commits are consumed first. Defaults to 100 if not specified. On updates, set + * to null to clear a previously configured priority. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun priority(): Optional = priority.getOptional("priority") + + /** + * The commit product that will be used to generate the line item for commit + * payment. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun productId(): Optional = productId.getOptional("product_id") + + /** + * Which products the threshold commit applies to. If both + * applicable_product_ids and applicable_product_tags are not provided, the + * commit applies to all products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun applicableProductIds(): Optional> = + applicableProductIds.getOptional("applicable_product_ids") + + /** + * Which tags the threshold commit applies to. If both applicable_product_ids + * and applicable_product_tags are not provided, the commit applies to all + * products. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun applicableProductTags(): Optional> = + applicableProductTags.getOptional("applicable_product_tags") + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at least + * one of the specifiers to contribute to a commit's or credit's drawdown. This + * field cannot be used together with `applicable_product_ids` or + * `applicable_product_tags`. Instead, to target usage by product or product + * tag, pass those values in the body of `specifiers`. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun specifiers(): Optional> = + specifiers.getOptional("specifiers") + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [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 [priority]. + * + * Unlike [priority], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("priority") + @ExcludeMissing + fun _priority(): JsonField = priority + + /** + * Returns the raw JSON value of [productId]. + * + * Unlike [productId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("product_id") + @ExcludeMissing + fun _productId(): JsonField = productId + + /** + * Returns the raw JSON value of [applicableProductIds]. + * + * Unlike [applicableProductIds], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("applicable_product_ids") + @ExcludeMissing + fun _applicableProductIds(): JsonField> = applicableProductIds + + /** + * Returns the raw JSON value of [applicableProductTags]. + * + * Unlike [applicableProductTags], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("applicable_product_tags") + @ExcludeMissing + fun _applicableProductTags(): JsonField> = applicableProductTags + + /** + * Returns the raw JSON value of [specifiers]. + * + * Unlike [specifiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("specifiers") + @ExcludeMissing + fun _specifiers(): JsonField> = specifiers + + @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 [Commit]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Commit]. */ + class Builder internal constructor() { + + private var description: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var priority: JsonField = JsonMissing.of() + private var productId: JsonField = JsonMissing.of() + private var applicableProductIds: JsonField>? = null + private var applicableProductTags: JsonField>? = null + private var specifiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(commit: Commit) = apply { + description = commit.description + name = commit.name + priority = commit.priority + productId = commit.productId + applicableProductIds = + commit.applicableProductIds.map { it.toMutableList() } + applicableProductTags = + commit.applicableProductTags.map { it.toMutableList() } + specifiers = commit.specifiers.map { it.toMutableList() } + additionalProperties = commit.additionalProperties.toMutableMap() + } + + fun description(description: String) = + description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** + * Specify the name of the line item for the threshold charge. If left + * blank, it will default to the commit product name. + */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * The priority of the commit, used to determine drawdown order. Lower + * priority commits are consumed first. Defaults to 100 if not specified. On + * updates, set to null to clear a previously configured priority. + */ + fun priority(priority: Double?) = priority(JsonField.ofNullable(priority)) + + /** + * Alias for [Builder.priority]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun priority(priority: Double) = priority(priority as Double?) + + /** Alias for calling [Builder.priority] with `priority.orElse(null)`. */ + fun priority(priority: Optional) = priority(priority.getOrNull()) + + /** + * Sets [Builder.priority] to an arbitrary JSON value. + * + * You should usually call [Builder.priority] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun priority(priority: JsonField) = apply { + this.priority = priority + } + + /** + * The commit product that will be used to generate the line item for commit + * payment. + */ + fun productId(productId: String) = productId(JsonField.of(productId)) + + /** + * Sets [Builder.productId] to an arbitrary JSON value. + * + * You should usually call [Builder.productId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun productId(productId: JsonField) = apply { + this.productId = productId + } + + /** + * Which products the threshold commit applies to. If both + * applicable_product_ids and applicable_product_tags are not provided, the + * commit applies to all products. + */ + fun applicableProductIds(applicableProductIds: List?) = + applicableProductIds(JsonField.ofNullable(applicableProductIds)) + + /** + * Alias for calling [Builder.applicableProductIds] with + * `applicableProductIds.orElse(null)`. + */ + fun applicableProductIds(applicableProductIds: Optional>) = + applicableProductIds(applicableProductIds.getOrNull()) + + /** + * Sets [Builder.applicableProductIds] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductIds] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun applicableProductIds(applicableProductIds: JsonField>) = + apply { + this.applicableProductIds = + applicableProductIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addApplicableProductId(applicableProductId: String) = apply { + applicableProductIds = + (applicableProductIds ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductIds", it).add(applicableProductId) + } + } + + /** + * Which tags the threshold commit applies to. If both + * applicable_product_ids and applicable_product_tags are not provided, the + * commit applies to all products. + */ + fun applicableProductTags(applicableProductTags: List?) = + applicableProductTags(JsonField.ofNullable(applicableProductTags)) + + /** + * Alias for calling [Builder.applicableProductTags] with + * `applicableProductTags.orElse(null)`. + */ + fun applicableProductTags(applicableProductTags: Optional>) = + applicableProductTags(applicableProductTags.getOrNull()) + + /** + * Sets [Builder.applicableProductTags] to an arbitrary JSON value. + * + * You should usually call [Builder.applicableProductTags] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun applicableProductTags(applicableProductTags: JsonField>) = + apply { + this.applicableProductTags = + applicableProductTags.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [applicableProductTags]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addApplicableProductTag(applicableProductTag: String) = apply { + applicableProductTags = + (applicableProductTags ?: JsonField.of(mutableListOf())).also { + checkKnown("applicableProductTags", it) + .add(applicableProductTag) + } + } + + /** + * List of filters that determine what kind of customer usage draws down a + * commit or credit. A customer's usage needs to meet the condition of at + * least one of the specifiers to contribute to a commit's or credit's + * drawdown. This field cannot be used together with + * `applicable_product_ids` or `applicable_product_tags`. Instead, to target + * usage by product or product tag, pass those values in the body of + * `specifiers`. + */ + fun specifiers(specifiers: List?) = + specifiers(JsonField.ofNullable(specifiers)) + + /** + * Alias for calling [Builder.specifiers] with `specifiers.orElse(null)`. + */ + fun specifiers(specifiers: Optional>) = + specifiers(specifiers.getOrNull()) + + /** + * Sets [Builder.specifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.specifiers] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun specifiers(specifiers: JsonField>) = apply { + this.specifiers = specifiers.map { it.toMutableList() } + } + + /** + * Adds a single [CommitSpecifierInput] to [specifiers]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addSpecifier(specifier: CommitSpecifierInput) = apply { + specifiers = + (specifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("specifiers", it).add(specifier) + } + } + + 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 [Commit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Commit = + Commit( + description, + name, + priority, + productId, + (applicableProductIds ?: JsonMissing.of()).map { it.toImmutable() }, + (applicableProductTags ?: JsonMissing.of()).map { + it.toImmutable() + }, + (specifiers ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Commit = apply { + if (validated) { + return@apply + } + + description() + name() + priority() + productId() + applicableProductIds() + applicableProductTags() + specifiers().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (priority.asKnown().isPresent) 1 else 0) + + (if (productId.asKnown().isPresent) 1 else 0) + + (applicableProductIds.asKnown().getOrNull()?.size ?: 0) + + (applicableProductTags.asKnown().getOrNull()?.size ?: 0) + + (specifiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Commit && + description == other.description && + name == other.name && + priority == other.priority && + productId == other.productId && + applicableProductIds == other.applicableProductIds && + applicableProductTags == other.applicableProductTags && + specifiers == other.specifiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + description, + name, + priority, + productId, + applicableProductIds, + applicableProductTags, + specifiers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Commit{description=$description, name=$name, priority=$priority, productId=$productId, applicableProductIds=$applicableProductIds, applicableProductTags=$applicableProductTags, specifiers=$specifiers, additionalProperties=$additionalProperties}" + } + + class DiscountConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cap: JsonField, + private val paymentFraction: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), + @JsonProperty("payment_fraction") + @ExcludeMissing + paymentFraction: JsonField = JsonMissing.of(), + ) : this(cap, paymentFraction, mutableMapOf()) + + /** + * Update the discount cap. Set to null to remove an existing cap. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") + + /** + * The fraction of the original amount that the customer pays after applying the + * discount. Set to null to remove the discount fraction. For example, 0.85 + * means the customer pays 85% of the original amount (a 15% discount). + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun paymentFraction(): Optional = + paymentFraction.getOptional("payment_fraction") + + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + + /** + * Returns the raw JSON value of [paymentFraction]. + * + * Unlike [paymentFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_fraction") + @ExcludeMissing + fun _paymentFraction(): JsonField = paymentFraction + + @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 + * [DiscountConfiguration]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DiscountConfiguration]. */ + class Builder internal constructor() { + + private var cap: JsonField = JsonMissing.of() + private var paymentFraction: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(discountConfiguration: DiscountConfiguration) = apply { + cap = discountConfiguration.cap + paymentFraction = discountConfiguration.paymentFraction + additionalProperties = + discountConfiguration.additionalProperties.toMutableMap() + } + + /** Update the discount cap. Set to null to remove an existing cap. */ + fun cap(cap: Cap?) = cap(JsonField.ofNullable(cap)) + + /** Alias for calling [Builder.cap] with `cap.orElse(null)`. */ + fun cap(cap: Optional) = cap(cap.getOrNull()) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + + /** + * The fraction of the original amount that the customer pays after applying + * the discount. Set to null to remove the discount fraction. For example, + * 0.85 means the customer pays 85% of the original amount (a 15% discount). + */ + fun paymentFraction(paymentFraction: Double?) = + paymentFraction(JsonField.ofNullable(paymentFraction)) + + /** + * Alias for [Builder.paymentFraction]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun paymentFraction(paymentFraction: Double) = + paymentFraction(paymentFraction as Double?) + + /** + * Alias for calling [Builder.paymentFraction] with + * `paymentFraction.orElse(null)`. + */ + fun paymentFraction(paymentFraction: Optional) = + paymentFraction(paymentFraction.getOrNull()) + + /** + * Sets [Builder.paymentFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentFraction] with a well-typed + * [Double] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun paymentFraction(paymentFraction: JsonField) = apply { + this.paymentFraction = paymentFraction + } + + 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 [DiscountConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DiscountConfiguration = + DiscountConfiguration( + cap, + paymentFraction, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): DiscountConfiguration = apply { + if (validated) { + return@apply + } + + cap().ifPresent { it.validate() } + paymentFraction() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (cap.asKnown().getOrNull()?.validity() ?: 0) + + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + /** Update the discount cap. Set to null to remove an existing cap. */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = + spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** + * Accumulated spend ceiling above which the discount stops applying. + */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DiscountConfiguration && + cap == other.cap && + paymentFraction == other.paymentFraction && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(cap, paymentFraction, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DiscountConfiguration{cap=$cap, paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + } + + class ThresholdBalanceSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val exclude: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("exclude") + @ExcludeMissing + exclude: JsonField> = JsonMissing.of() + ) : this(exclude, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 exclude(): List = exclude.getRequired("exclude") + + /** + * Returns the raw JSON value of [exclude]. + * + * Unlike [exclude], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("exclude") + @ExcludeMissing + fun _exclude(): JsonField> = exclude + + @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 + * [ThresholdBalanceSpecifier]. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThresholdBalanceSpecifier]. */ + class Builder internal constructor() { + + private var exclude: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(thresholdBalanceSpecifier: ThresholdBalanceSpecifier) = + apply { + exclude = + thresholdBalanceSpecifier.exclude.map { it.toMutableList() } + additionalProperties = + thresholdBalanceSpecifier.additionalProperties.toMutableMap() + } + + fun exclude(exclude: List) = exclude(JsonField.of(exclude)) + + /** + * Sets [Builder.exclude] to an arbitrary JSON value. + * + * You should usually call [Builder.exclude] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun exclude(exclude: JsonField>) = apply { + this.exclude = exclude.map { it.toMutableList() } + } + + /** + * Adds a single [Exclude] to [Builder.exclude]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addExclude(exclude: Exclude) = apply { + this.exclude = + (this.exclude ?: JsonField.of(mutableListOf())).also { + checkKnown("exclude", it).add(exclude) + } + } + + 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 [ThresholdBalanceSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThresholdBalanceSpecifier = + ThresholdBalanceSpecifier( + checkRequired("exclude", exclude).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ThresholdBalanceSpecifier = apply { + if (validated) { + return@apply + } + + exclude().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (exclude.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Exclude + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val customFieldFilters: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("custom_field_filters") + @ExcludeMissing + customFieldFilters: JsonField> = + JsonMissing.of() + ) : this(customFieldFilters, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 customFieldFilters(): List = + customFieldFilters.getRequired("custom_field_filters") + + /** + * Returns the raw JSON value of [customFieldFilters]. + * + * Unlike [customFieldFilters], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("custom_field_filters") + @ExcludeMissing + fun _customFieldFilters(): JsonField> = + customFieldFilters + + @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 [Exclude]. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Exclude]. */ + class Builder internal constructor() { + + private var customFieldFilters: + JsonField>? = + null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(exclude: Exclude) = apply { + customFieldFilters = + exclude.customFieldFilters.map { it.toMutableList() } + additionalProperties = exclude.additionalProperties.toMutableMap() + } + + fun customFieldFilters(customFieldFilters: List) = + customFieldFilters(JsonField.of(customFieldFilters)) + + /** + * Sets [Builder.customFieldFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.customFieldFilters] with a + * well-typed `List` value instead. This method is + * primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun customFieldFilters( + customFieldFilters: JsonField> + ) = apply { + this.customFieldFilters = + customFieldFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CustomFieldFilter] to [customFieldFilters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addCustomFieldFilter(customFieldFilter: CustomFieldFilter) = apply { + customFieldFilters = + (customFieldFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("customFieldFilters", it).add(customFieldFilter) + } + } + + 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 [Exclude]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Exclude = + Exclude( + checkRequired("customFieldFilters", customFieldFilters).map { + it.toImmutable() + }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Exclude = apply { + if (validated) { + return@apply + } + + customFieldFilters().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (customFieldFilters.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + class CustomFieldFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val entity: JsonField, + private val key: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("entity") + @ExcludeMissing + entity: JsonField = JsonMissing.of(), + @JsonProperty("key") + @ExcludeMissing + key: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(entity, key, value, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 entity(): Entity = entity.getRequired("entity") + + /** + * @throws MetronomeInvalidDataException 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 key(): String = key.getRequired("key") + + /** + * @throws MetronomeInvalidDataException 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 [entity]. + * + * Unlike [entity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("entity") + @ExcludeMissing + fun _entity(): JsonField = entity + + /** + * Returns the raw JSON value of [key]. + * + * Unlike [key], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("key") @ExcludeMissing fun _key(): JsonField = key + + /** + * 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 + * [CustomFieldFilter]. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFieldFilter]. */ + class Builder internal constructor() { + + private var entity: JsonField? = null + private var key: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customFieldFilter: CustomFieldFilter) = apply { + entity = customFieldFilter.entity + key = customFieldFilter.key + value = customFieldFilter.value + additionalProperties = + customFieldFilter.additionalProperties.toMutableMap() + } + + fun entity(entity: Entity) = entity(JsonField.of(entity)) + + /** + * Sets [Builder.entity] to an arbitrary JSON value. + * + * You should usually call [Builder.entity] with a well-typed + * [Entity] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun entity(entity: JsonField) = apply { + this.entity = entity + } + + fun key(key: String) = key(JsonField.of(key)) + + /** + * Sets [Builder.key] to an arbitrary JSON value. + * + * You should usually call [Builder.key] with a well-typed [String] + * value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun key(key: JsonField) = apply { this.key = key } + + 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 [CustomFieldFilter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomFieldFilter = + CustomFieldFilter( + checkRequired("entity", entity), + checkRequired("key", key), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): CustomFieldFilter = apply { + if (validated) { + return@apply + } + + entity().validate() + key() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (entity.asKnown().getOrNull()?.validity() ?: 0) + + (if (key.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) + + class Entity + @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 COMMIT = of("Commit") + + @JvmField val CONTRACT_CREDIT = of("ContractCredit") + + @JvmField + val CONTRACT_CREDIT_OR_COMMIT = of("ContractCreditOrCommit") + + @JvmStatic fun of(value: String) = Entity(JsonField.of(value)) + } + + /** An enum containing [Entity]'s known values. */ + enum class Known { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + } + + /** + * An enum containing [Entity]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [Entity] 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 { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + /** + * An enum member indicating that [Entity] 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) { + COMMIT -> Value.COMMIT + CONTRACT_CREDIT -> Value.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Value.CONTRACT_CREDIT_OR_COMMIT + 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 MetronomeInvalidDataException if this class instance's + * value is a not a known member. + */ + fun known(): Known = + when (this) { + COMMIT -> Known.COMMIT + CONTRACT_CREDIT -> Known.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Known.CONTRACT_CREDIT_OR_COMMIT + else -> + throw MetronomeInvalidDataException( + "Unknown Entity: $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 MetronomeInvalidDataException if this class instance's + * value does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the + * API for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Entity = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Entity && 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 CustomFieldFilter && + entity == other.entity && + key == other.key && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(entity, key, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomFieldFilter{entity=$entity, key=$key, value=$value, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Exclude && + customFieldFilters == other.customFieldFilters && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(customFieldFilters, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Exclude{customFieldFilters=$customFieldFilters, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThresholdBalanceSpecifier && + exclude == other.exclude && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(exclude, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThresholdBalanceSpecifier{exclude=$exclude, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdatePrepaidBalanceThresholdConfiguration && + commit == other.commit && + customCreditTypeId == other.customCreditTypeId && + discountConfiguration == other.discountConfiguration && + isEnabled == other.isEnabled && + paymentGateConfig == other.paymentGateConfig && + rechargeToAmount == other.rechargeToAmount && + thresholdAmount == other.thresholdAmount && + thresholdBalanceSpecifiers == other.thresholdBalanceSpecifiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + commit, + customCreditTypeId, + discountConfiguration, + isEnabled, + paymentGateConfig, + rechargeToAmount, + thresholdAmount, + thresholdBalanceSpecifiers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdatePrepaidBalanceThresholdConfiguration{commit=$commit, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, thresholdBalanceSpecifiers=$thresholdBalanceSpecifiers, additionalProperties=$additionalProperties}" + } + + class UpdateRecurringCommit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val accessAmount: JsonField, + private val endingBefore: JsonField, + private val invoiceAmount: JsonField, + private val rateType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("access_amount") + @ExcludeMissing + accessAmount: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("invoice_amount") + @ExcludeMissing + invoiceAmount: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + ) : this(id, accessAmount, endingBefore, invoiceAmount, rateType, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun accessAmount(): Optional = + accessAmount.getOptional("access_amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun invoiceAmount(): Optional = + invoiceAmount.getOptional("invoice_amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rateType(): Optional = rateType.getOptional("rate_type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [accessAmount]. + * + * Unlike [accessAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_amount") + @ExcludeMissing + fun _accessAmount(): JsonField = accessAmount + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [invoiceAmount]. + * + * Unlike [invoiceAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_amount") + @ExcludeMissing + fun _invoiceAmount(): JsonField = invoiceAmount + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + @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 + * [UpdateRecurringCommit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateRecurringCommit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var accessAmount: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var invoiceAmount: JsonField = JsonMissing.of() + private var rateType: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateRecurringCommit: UpdateRecurringCommit) = apply { + id = updateRecurringCommit.id + accessAmount = updateRecurringCommit.accessAmount + endingBefore = updateRecurringCommit.endingBefore + invoiceAmount = updateRecurringCommit.invoiceAmount + rateType = updateRecurringCommit.rateType + additionalProperties = + updateRecurringCommit.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 accessAmount(accessAmount: AccessAmount) = + accessAmount(JsonField.of(accessAmount)) + + /** + * Sets [Builder.accessAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.accessAmount] with a well-typed + * [AccessAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun accessAmount(accessAmount: JsonField) = apply { + this.accessAmount = accessAmount + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun invoiceAmount(invoiceAmount: InvoiceAmount) = + invoiceAmount(JsonField.of(invoiceAmount)) + + /** + * Sets [Builder.invoiceAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceAmount] with a well-typed + * [InvoiceAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun invoiceAmount(invoiceAmount: JsonField) = apply { + this.invoiceAmount = invoiceAmount + } + + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + 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 [UpdateRecurringCommit]. + * + * 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(): UpdateRecurringCommit = + UpdateRecurringCommit( + checkRequired("id", id), + accessAmount, + endingBefore, + invoiceAmount, + rateType, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateRecurringCommit = apply { + if (validated) { + return@apply + } + + id() + accessAmount().ifPresent { it.validate() } + endingBefore() + invoiceAmount().ifPresent { it.validate() } + rateType().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (accessAmount.asKnown().getOrNull()?.validity() ?: 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (invoiceAmount.asKnown().getOrNull()?.validity() ?: 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + class AccessAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(quantity, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 [AccessAmount]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccessAmount]. */ + class Builder internal constructor() { + + private var quantity: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(accessAmount: AccessAmount) = apply { + quantity = accessAmount.quantity + unitPrice = accessAmount.unitPrice + additionalProperties = accessAmount.additionalProperties.toMutableMap() + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [AccessAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AccessAmount = + AccessAmount(quantity, unitPrice, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AccessAmount = apply { + if (validated) { + return@apply + } + + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccessAmount && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(quantity, unitPrice, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessAmount{quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + class InvoiceAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(quantity, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [InvoiceAmount]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InvoiceAmount]. */ + class Builder internal constructor() { + + private var quantity: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(invoiceAmount: InvoiceAmount) = apply { + quantity = invoiceAmount.quantity + unitPrice = invoiceAmount.unitPrice + additionalProperties = invoiceAmount.additionalProperties.toMutableMap() + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [InvoiceAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InvoiceAmount = + InvoiceAmount(quantity, unitPrice, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InvoiceAmount = apply { + if (validated) { + return@apply + } + + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InvoiceAmount && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(quantity, unitPrice, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InvoiceAmount{quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + class RateType + @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 LIST_RATE = of("LIST_RATE") + + @JvmField val COMMIT_RATE = of("COMMIT_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + LIST_RATE, + COMMIT_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + LIST_RATE, + COMMIT_RATE, + /** + * An enum member indicating that [RateType] 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) { + LIST_RATE -> Value.LIST_RATE + COMMIT_RATE -> Value.COMMIT_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + LIST_RATE -> Known.LIST_RATE + COMMIT_RATE -> Known.COMMIT_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && 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 UpdateRecurringCommit && + id == other.id && + accessAmount == other.accessAmount && + endingBefore == other.endingBefore && + invoiceAmount == other.invoiceAmount && + rateType == other.rateType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + accessAmount, + endingBefore, + invoiceAmount, + rateType, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateRecurringCommit{id=$id, accessAmount=$accessAmount, endingBefore=$endingBefore, invoiceAmount=$invoiceAmount, rateType=$rateType, additionalProperties=$additionalProperties}" + } + + class UpdateRecurringCredit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val accessAmount: JsonField, + private val endingBefore: JsonField, + private val rateType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("access_amount") + @ExcludeMissing + accessAmount: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("rate_type") + @ExcludeMissing + rateType: JsonField = JsonMissing.of(), + ) : this(id, accessAmount, endingBefore, rateType, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun accessAmount(): Optional = + accessAmount.getOptional("access_amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun rateType(): Optional = rateType.getOptional("rate_type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [accessAmount]. + * + * Unlike [accessAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("access_amount") + @ExcludeMissing + fun _accessAmount(): JsonField = accessAmount + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [rateType]. + * + * Unlike [rateType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rate_type") + @ExcludeMissing + fun _rateType(): JsonField = rateType + + @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 + * [UpdateRecurringCredit]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateRecurringCredit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var accessAmount: JsonField = JsonMissing.of() + private var endingBefore: JsonField = JsonMissing.of() + private var rateType: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateRecurringCredit: UpdateRecurringCredit) = apply { + id = updateRecurringCredit.id + accessAmount = updateRecurringCredit.accessAmount + endingBefore = updateRecurringCredit.endingBefore + rateType = updateRecurringCredit.rateType + additionalProperties = + updateRecurringCredit.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 accessAmount(accessAmount: AccessAmount) = + accessAmount(JsonField.of(accessAmount)) + + /** + * Sets [Builder.accessAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.accessAmount] with a well-typed + * [AccessAmount] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun accessAmount(accessAmount: JsonField) = apply { + this.accessAmount = accessAmount + } + + fun endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun rateType(rateType: RateType) = rateType(JsonField.of(rateType)) + + /** + * Sets [Builder.rateType] to an arbitrary JSON value. + * + * You should usually call [Builder.rateType] with a well-typed [RateType] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun rateType(rateType: JsonField) = apply { this.rateType = rateType } + + 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 [UpdateRecurringCredit]. + * + * 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(): UpdateRecurringCredit = + UpdateRecurringCredit( + checkRequired("id", id), + accessAmount, + endingBefore, + rateType, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateRecurringCredit = apply { + if (validated) { + return@apply + } + + id() + accessAmount().ifPresent { it.validate() } + endingBefore() + rateType().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (accessAmount.asKnown().getOrNull()?.validity() ?: 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (rateType.asKnown().getOrNull()?.validity() ?: 0) + + class AccessAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(quantity, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 [AccessAmount]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AccessAmount]. */ + class Builder internal constructor() { + + private var quantity: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(accessAmount: AccessAmount) = apply { + quantity = accessAmount.quantity + unitPrice = accessAmount.unitPrice + additionalProperties = accessAmount.additionalProperties.toMutableMap() + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [AccessAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AccessAmount = + AccessAmount(quantity, unitPrice, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AccessAmount = apply { + if (validated) { + return@apply + } + + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AccessAmount && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(quantity, unitPrice, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AccessAmount{quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + class RateType + @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 LIST_RATE = of("LIST_RATE") + + @JvmField val COMMIT_RATE = of("COMMIT_RATE") + + @JvmStatic fun of(value: String) = RateType(JsonField.of(value)) + } + + /** An enum containing [RateType]'s known values. */ + enum class Known { + LIST_RATE, + COMMIT_RATE, + } + + /** + * An enum containing [RateType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [RateType] 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 { + LIST_RATE, + COMMIT_RATE, + /** + * An enum member indicating that [RateType] 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) { + LIST_RATE -> Value.LIST_RATE + COMMIT_RATE -> Value.COMMIT_RATE + 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 MetronomeInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + LIST_RATE -> Known.LIST_RATE + COMMIT_RATE -> Known.COMMIT_RATE + else -> throw MetronomeInvalidDataException("Unknown RateType: $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 MetronomeInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RateType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RateType && 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 UpdateRecurringCredit && + id == other.id && + accessAmount == other.accessAmount && + endingBefore == other.endingBefore && + rateType == other.rateType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, accessAmount, endingBefore, rateType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateRecurringCredit{id=$id, accessAmount=$accessAmount, endingBefore=$endingBefore, rateType=$rateType, additionalProperties=$additionalProperties}" + } + + class UpdateRefundInvoice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val date: JsonField, + private val invoiceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("date") + @ExcludeMissing + date: JsonField = JsonMissing.of(), + @JsonProperty("invoice_id") + @ExcludeMissing + invoiceId: JsonField = JsonMissing.of(), + ) : this(date, invoiceId, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 date(): OffsetDateTime = date.getRequired("date") + + /** + * @throws MetronomeInvalidDataException 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 invoiceId(): String = invoiceId.getRequired("invoice_id") + + /** + * Returns the raw JSON value of [date]. + * + * Unlike [date], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("date") @ExcludeMissing fun _date(): JsonField = date + + /** + * Returns the raw JSON value of [invoiceId]. + * + * Unlike [invoiceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("invoice_id") + @ExcludeMissing + fun _invoiceId(): JsonField = invoiceId + + @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 + * [UpdateRefundInvoice]. + * + * The following fields are required: + * ```java + * .date() + * .invoiceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateRefundInvoice]. */ + class Builder internal constructor() { + + private var date: JsonField? = null + private var invoiceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateRefundInvoice: UpdateRefundInvoice) = apply { + date = updateRefundInvoice.date + invoiceId = updateRefundInvoice.invoiceId + additionalProperties = + updateRefundInvoice.additionalProperties.toMutableMap() + } + + fun date(date: OffsetDateTime) = date(JsonField.of(date)) + + /** + * Sets [Builder.date] to an arbitrary JSON value. + * + * You should usually call [Builder.date] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun date(date: JsonField) = apply { this.date = date } + + fun invoiceId(invoiceId: String) = invoiceId(JsonField.of(invoiceId)) + + /** + * Sets [Builder.invoiceId] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun invoiceId(invoiceId: JsonField) = apply { + this.invoiceId = invoiceId + } + + 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 [UpdateRefundInvoice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .date() + * .invoiceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UpdateRefundInvoice = + UpdateRefundInvoice( + checkRequired("date", date), + checkRequired("invoiceId", invoiceId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateRefundInvoice = apply { + if (validated) { + return@apply + } + + date() + invoiceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (date.asKnown().isPresent) 1 else 0) + + (if (invoiceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateRefundInvoice && + date == other.date && + invoiceId == other.invoiceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(date, invoiceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateRefundInvoice{date=$date, invoiceId=$invoiceId, additionalProperties=$additionalProperties}" + } + + class UpdateScheduledCharge + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val invoiceSchedule: JsonField, + private val name: JsonField, + private val netsuiteSalesOrderId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("invoice_schedule") + @ExcludeMissing + invoiceSchedule: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + netsuiteSalesOrderId: JsonField = JsonMissing.of(), + ) : this(id, invoiceSchedule, name, netsuiteSalesOrderId, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun invoiceSchedule(): Optional = + invoiceSchedule.getOptional("invoice_schedule") + + /** + * @throws MetronomeInvalidDataException 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 MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun netsuiteSalesOrderId(): Optional = + netsuiteSalesOrderId.getOptional("netsuite_sales_order_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 + + /** + * Returns the raw JSON value of [invoiceSchedule]. + * + * Unlike [invoiceSchedule], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_schedule") + @ExcludeMissing + fun _invoiceSchedule(): JsonField = invoiceSchedule + + /** + * 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 [netsuiteSalesOrderId]. + * + * Unlike [netsuiteSalesOrderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("netsuite_sales_order_id") + @ExcludeMissing + fun _netsuiteSalesOrderId(): JsonField = netsuiteSalesOrderId + + @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 + * [UpdateScheduledCharge]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateScheduledCharge]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var invoiceSchedule: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var netsuiteSalesOrderId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateScheduledCharge: UpdateScheduledCharge) = apply { + id = updateScheduledCharge.id + invoiceSchedule = updateScheduledCharge.invoiceSchedule + name = updateScheduledCharge.name + netsuiteSalesOrderId = updateScheduledCharge.netsuiteSalesOrderId + additionalProperties = + updateScheduledCharge.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 invoiceSchedule(invoiceSchedule: InvoiceSchedule) = + invoiceSchedule(JsonField.of(invoiceSchedule)) + + /** + * Sets [Builder.invoiceSchedule] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceSchedule] with a well-typed + * [InvoiceSchedule] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun invoiceSchedule(invoiceSchedule: JsonField) = apply { + this.invoiceSchedule = invoiceSchedule + } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun netsuiteSalesOrderId(netsuiteSalesOrderId: String?) = + netsuiteSalesOrderId(JsonField.ofNullable(netsuiteSalesOrderId)) + + /** + * Alias for calling [Builder.netsuiteSalesOrderId] with + * `netsuiteSalesOrderId.orElse(null)`. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: Optional) = + netsuiteSalesOrderId(netsuiteSalesOrderId.getOrNull()) + + /** + * Sets [Builder.netsuiteSalesOrderId] to an arbitrary JSON value. + * + * You should usually call [Builder.netsuiteSalesOrderId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun netsuiteSalesOrderId(netsuiteSalesOrderId: JsonField) = apply { + this.netsuiteSalesOrderId = netsuiteSalesOrderId + } + + 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 [UpdateScheduledCharge]. + * + * 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(): UpdateScheduledCharge = + UpdateScheduledCharge( + checkRequired("id", id), + invoiceSchedule, + name, + netsuiteSalesOrderId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateScheduledCharge = apply { + if (validated) { + return@apply + } + + id() + invoiceSchedule().ifPresent { it.validate() } + name() + netsuiteSalesOrderId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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) + + (invoiceSchedule.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (netsuiteSalesOrderId.asKnown().isPresent) 1 else 0) + + class InvoiceSchedule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val addScheduleItems: JsonField>, + private val removeScheduleItems: JsonField>, + private val updateScheduleItems: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("add_schedule_items") + @ExcludeMissing + addScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("remove_schedule_items") + @ExcludeMissing + removeScheduleItems: JsonField> = JsonMissing.of(), + @JsonProperty("update_schedule_items") + @ExcludeMissing + updateScheduleItems: JsonField> = JsonMissing.of(), + ) : this( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun addScheduleItems(): Optional> = + addScheduleItems.getOptional("add_schedule_items") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun removeScheduleItems(): Optional> = + removeScheduleItems.getOptional("remove_schedule_items") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun updateScheduleItems(): Optional> = + updateScheduleItems.getOptional("update_schedule_items") + + /** + * Returns the raw JSON value of [addScheduleItems]. + * + * Unlike [addScheduleItems], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_schedule_items") + @ExcludeMissing + fun _addScheduleItems(): JsonField> = addScheduleItems + + /** + * Returns the raw JSON value of [removeScheduleItems]. + * + * Unlike [removeScheduleItems], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("remove_schedule_items") + @ExcludeMissing + fun _removeScheduleItems(): JsonField> = + removeScheduleItems + + /** + * Returns the raw JSON value of [updateScheduleItems]. + * + * Unlike [updateScheduleItems], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("update_schedule_items") + @ExcludeMissing + fun _updateScheduleItems(): JsonField> = + updateScheduleItems + + @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 + * [InvoiceSchedule]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InvoiceSchedule]. */ + class Builder internal constructor() { + + private var addScheduleItems: JsonField>? = + null + private var removeScheduleItems: + JsonField>? = + null + private var updateScheduleItems: + JsonField>? = + null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(invoiceSchedule: InvoiceSchedule) = apply { + addScheduleItems = + invoiceSchedule.addScheduleItems.map { it.toMutableList() } + removeScheduleItems = + invoiceSchedule.removeScheduleItems.map { it.toMutableList() } + updateScheduleItems = + invoiceSchedule.updateScheduleItems.map { it.toMutableList() } + additionalProperties = + invoiceSchedule.additionalProperties.toMutableMap() + } + + fun addScheduleItems(addScheduleItems: List) = + addScheduleItems(JsonField.of(addScheduleItems)) + + /** + * Sets [Builder.addScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.addScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun addScheduleItems(addScheduleItems: JsonField>) = + apply { + this.addScheduleItems = addScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [AddScheduleItem] to [addScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addAddScheduleItem(addScheduleItem: AddScheduleItem) = apply { + addScheduleItems = + (addScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("addScheduleItems", it).add(addScheduleItem) + } + } + + fun removeScheduleItems(removeScheduleItems: List) = + removeScheduleItems(JsonField.of(removeScheduleItems)) + + /** + * Sets [Builder.removeScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.removeScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun removeScheduleItems( + removeScheduleItems: JsonField> + ) = apply { + this.removeScheduleItems = + removeScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [RemoveScheduleItem] to [removeScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addRemoveScheduleItem(removeScheduleItem: RemoveScheduleItem) = apply { + removeScheduleItems = + (removeScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("removeScheduleItems", it).add(removeScheduleItem) + } + } + + fun updateScheduleItems(updateScheduleItems: List) = + updateScheduleItems(JsonField.of(updateScheduleItems)) + + /** + * Sets [Builder.updateScheduleItems] to an arbitrary JSON value. + * + * You should usually call [Builder.updateScheduleItems] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun updateScheduleItems( + updateScheduleItems: JsonField> + ) = apply { + this.updateScheduleItems = + updateScheduleItems.map { it.toMutableList() } + } + + /** + * Adds a single [UpdateScheduleItem] to [updateScheduleItems]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addUpdateScheduleItem(updateScheduleItem: UpdateScheduleItem) = apply { + updateScheduleItems = + (updateScheduleItems ?: JsonField.of(mutableListOf())).also { + checkKnown("updateScheduleItems", it).add(updateScheduleItem) + } + } + + 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 [InvoiceSchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InvoiceSchedule = + InvoiceSchedule( + (addScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (removeScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + (updateScheduleItems ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): InvoiceSchedule = apply { + if (validated) { + return@apply + } + + addScheduleItems().ifPresent { it.forEach { it.validate() } } + removeScheduleItems().ifPresent { it.forEach { it.validate() } } + updateScheduleItems().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (addScheduleItems.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (removeScheduleItems.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + (updateScheduleItems.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + class AddScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val timestamp: JsonField, + private val amount: JsonField, + private val quantity: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(timestamp, amount, quantity, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 timestamp(): OffsetDateTime = timestamp.getRequired("timestamp") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [AddScheduleItem]. + * + * The following fields are required: + * ```java + * .timestamp() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddScheduleItem]. */ + class Builder internal constructor() { + + private var timestamp: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(addScheduleItem: AddScheduleItem) = apply { + timestamp = addScheduleItem.timestamp + amount = addScheduleItem.amount + quantity = addScheduleItem.quantity + unitPrice = addScheduleItem.unitPrice + additionalProperties = + addScheduleItem.additionalProperties.toMutableMap() + } + + fun timestamp(timestamp: OffsetDateTime) = + timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed + * [Double] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [AddScheduleItem]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .timestamp() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddScheduleItem = + AddScheduleItem( + checkRequired("timestamp", timestamp), + amount, + quantity, + unitPrice, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AddScheduleItem = apply { + if (validated) { + return@apply + } + + timestamp() + amount() + quantity() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (timestamp.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddScheduleItem && + timestamp == other.timestamp && + amount == other.amount && + quantity == other.quantity && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + timestamp, + amount, + quantity, + unitPrice, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddScheduleItem{timestamp=$timestamp, amount=$amount, quantity=$quantity, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + class RemoveScheduleItem + @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 MetronomeInvalidDataException 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 + * [RemoveScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(removeScheduleItem: RemoveScheduleItem) = apply { + id = removeScheduleItem.id + additionalProperties = + removeScheduleItem.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 [RemoveScheduleItem]. + * + * 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(): RemoveScheduleItem = + RemoveScheduleItem( + checkRequired("id", id), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RemoveScheduleItem = apply { + if (validated) { + return@apply + } + + id() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 RemoveScheduleItem && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveScheduleItem{id=$id, additionalProperties=$additionalProperties}" + } + + class UpdateScheduleItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val amount: JsonField, + private val quantity: JsonField, + private val timestamp: JsonField, + private val unitPrice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") + @ExcludeMissing + id: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + ) : this(id, amount, quantity, timestamp, unitPrice, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun timestamp(): Optional = + timestamp.getOptional("timestamp") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun unitPrice(): Optional = unitPrice.getOptional("unit_price") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [unitPrice]. + * + * Unlike [unitPrice], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_price") + @ExcludeMissing + fun _unitPrice(): JsonField = unitPrice + + @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 + * [UpdateScheduleItem]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateScheduleItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var timestamp: JsonField = JsonMissing.of() + private var unitPrice: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(updateScheduleItem: UpdateScheduleItem) = apply { + id = updateScheduleItem.id + amount = updateScheduleItem.amount + quantity = updateScheduleItem.quantity + timestamp = updateScheduleItem.timestamp + unitPrice = updateScheduleItem.unitPrice + additionalProperties = + updateScheduleItem.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 amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun timestamp(timestamp: OffsetDateTime) = + timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + fun unitPrice(unitPrice: Double) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed + * [Double] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitPrice(unitPrice: JsonField) = apply { + this.unitPrice = unitPrice + } + + 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 [UpdateScheduleItem]. + * + * 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(): UpdateScheduleItem = + UpdateScheduleItem( + checkRequired("id", id), + amount, + quantity, + timestamp, + unitPrice, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): UpdateScheduleItem = apply { + if (validated) { + return@apply + } + + id() + amount() + quantity() + timestamp() + unitPrice() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (amount.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (timestamp.asKnown().isPresent) 1 else 0) + + (if (unitPrice.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateScheduleItem && + id == other.id && + amount == other.amount && + quantity == other.quantity && + timestamp == other.timestamp && + unitPrice == other.unitPrice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + quantity, + timestamp, + unitPrice, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateScheduleItem{id=$id, amount=$amount, quantity=$quantity, timestamp=$timestamp, unitPrice=$unitPrice, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InvoiceSchedule && + addScheduleItems == other.addScheduleItems && + removeScheduleItems == other.removeScheduleItems && + updateScheduleItems == other.updateScheduleItems && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + addScheduleItems, + removeScheduleItems, + updateScheduleItems, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InvoiceSchedule{addScheduleItems=$addScheduleItems, removeScheduleItems=$removeScheduleItems, updateScheduleItems=$updateScheduleItems, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateScheduledCharge && + id == other.id && + invoiceSchedule == other.invoiceSchedule && + name == other.name && + netsuiteSalesOrderId == other.netsuiteSalesOrderId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + invoiceSchedule, + name, + netsuiteSalesOrderId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateScheduledCharge{id=$id, invoiceSchedule=$invoiceSchedule, name=$name, netsuiteSalesOrderId=$netsuiteSalesOrderId, additionalProperties=$additionalProperties}" + } + + class UpdateSpendThresholdConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val commit: JsonField, + private val discountConfiguration: JsonField, + private val isEnabled: JsonField, + private val paymentGateConfig: JsonField, + private val thresholdAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("commit") + @ExcludeMissing + commit: JsonField = JsonMissing.of(), + @JsonProperty("discount_configuration") + @ExcludeMissing + discountConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("is_enabled") + @ExcludeMissing + isEnabled: JsonField = JsonMissing.of(), + @JsonProperty("payment_gate_config") + @ExcludeMissing + paymentGateConfig: JsonField = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + ) : this( + commit, + discountConfiguration, + isEnabled, + paymentGateConfig, + thresholdAmount, + mutableMapOf(), + ) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun commit(): Optional = commit.getOptional("commit") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun discountConfiguration(): Optional = + discountConfiguration.getOptional("discount_configuration") + + /** + * When set to false, the contract will not be evaluated against the + * threshold_amount. Toggling to true will result an immediate evaluation, + * regardless of prior state. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun isEnabled(): Optional = isEnabled.getOptional("is_enabled") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun paymentGateConfig(): Optional = + paymentGateConfig.getOptional("payment_gate_config") + + /** + * Specify the threshold amount for the contract. Each time the contract's usage + * hits this amount, a threshold charge will be initiated. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun thresholdAmount(): Optional = + thresholdAmount.getOptional("threshold_amount") + + /** + * Returns the raw JSON value of [commit]. + * + * Unlike [commit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("commit") + @ExcludeMissing + fun _commit(): JsonField = commit + + /** + * Returns the raw JSON value of [discountConfiguration]. + * + * Unlike [discountConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("discount_configuration") + @ExcludeMissing + fun _discountConfiguration(): JsonField = + discountConfiguration + + /** + * Returns the raw JSON value of [isEnabled]. + * + * Unlike [isEnabled], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("is_enabled") + @ExcludeMissing + fun _isEnabled(): JsonField = isEnabled + + /** + * Returns the raw JSON value of [paymentGateConfig]. + * + * Unlike [paymentGateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_gate_config") + @ExcludeMissing + fun _paymentGateConfig(): JsonField = paymentGateConfig + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + @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 + * [UpdateSpendThresholdConfiguration]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateSpendThresholdConfiguration]. */ + class Builder internal constructor() { + + private var commit: JsonField = JsonMissing.of() + private var discountConfiguration: JsonField = + JsonMissing.of() + private var isEnabled: JsonField = JsonMissing.of() + private var paymentGateConfig: JsonField = JsonMissing.of() + private var thresholdAmount: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + updateSpendThresholdConfiguration: UpdateSpendThresholdConfiguration + ) = apply { + commit = updateSpendThresholdConfiguration.commit + discountConfiguration = + updateSpendThresholdConfiguration.discountConfiguration + isEnabled = updateSpendThresholdConfiguration.isEnabled + paymentGateConfig = updateSpendThresholdConfiguration.paymentGateConfig + thresholdAmount = updateSpendThresholdConfiguration.thresholdAmount + additionalProperties = + updateSpendThresholdConfiguration.additionalProperties.toMutableMap() + } + + fun commit(commit: UpdateBaseThresholdCommit) = commit(JsonField.of(commit)) + + /** + * Sets [Builder.commit] to an arbitrary JSON value. + * + * You should usually call [Builder.commit] with a well-typed + * [UpdateBaseThresholdCommit] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun commit(commit: JsonField) = apply { + this.commit = commit + } + + fun discountConfiguration(discountConfiguration: DiscountConfiguration?) = + discountConfiguration(JsonField.ofNullable(discountConfiguration)) + + /** + * Alias for calling [Builder.discountConfiguration] with + * `discountConfiguration.orElse(null)`. + */ + fun discountConfiguration( + discountConfiguration: Optional + ) = discountConfiguration(discountConfiguration.getOrNull()) + + /** + * Sets [Builder.discountConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.discountConfiguration] with a well-typed + * [DiscountConfiguration] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun discountConfiguration( + discountConfiguration: JsonField + ) = apply { this.discountConfiguration = discountConfiguration } + + /** + * When set to false, the contract will not be evaluated against the + * threshold_amount. Toggling to true will result an immediate evaluation, + * regardless of prior state. + */ + fun isEnabled(isEnabled: Boolean) = isEnabled(JsonField.of(isEnabled)) + + /** + * Sets [Builder.isEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.isEnabled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun isEnabled(isEnabled: JsonField) = apply { + this.isEnabled = isEnabled + } + + fun paymentGateConfig(paymentGateConfig: PaymentGateConfigV2) = + paymentGateConfig(JsonField.of(paymentGateConfig)) + + /** + * Sets [Builder.paymentGateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentGateConfig] with a well-typed + * [PaymentGateConfigV2] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun paymentGateConfig(paymentGateConfig: JsonField) = + apply { + this.paymentGateConfig = paymentGateConfig + } + + /** + * Specify the threshold amount for the contract. Each time the contract's usage + * hits this amount, a threshold charge will be initiated. + */ + fun thresholdAmount(thresholdAmount: Double) = + thresholdAmount(JsonField.of(thresholdAmount)) + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } + + 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 [UpdateSpendThresholdConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): UpdateSpendThresholdConfiguration = + UpdateSpendThresholdConfiguration( + commit, + discountConfiguration, + isEnabled, + paymentGateConfig, + thresholdAmount, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateSpendThresholdConfiguration = apply { + if (validated) { + return@apply + } + + commit().ifPresent { it.validate() } + discountConfiguration().ifPresent { it.validate() } + isEnabled() + paymentGateConfig().ifPresent { it.validate() } + thresholdAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (commit.asKnown().getOrNull()?.validity() ?: 0) + + (discountConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (isEnabled.asKnown().isPresent) 1 else 0) + + (paymentGateConfig.asKnown().getOrNull()?.validity() ?: 0) + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + class DiscountConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cap: JsonField, + private val paymentFraction: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), + @JsonProperty("payment_fraction") + @ExcludeMissing + paymentFraction: JsonField = JsonMissing.of(), + ) : this(cap, paymentFraction, mutableMapOf()) + + /** + * Update the discount cap. Set to null to remove an existing cap. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") + + /** + * The fraction of the original amount that the customer pays after applying the + * discount. Set to null to remove the discount fraction. For example, 0.85 + * means the customer pays 85% of the original amount (a 15% discount). + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun paymentFraction(): Optional = + paymentFraction.getOptional("payment_fraction") + + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + + /** + * Returns the raw JSON value of [paymentFraction]. + * + * Unlike [paymentFraction], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_fraction") + @ExcludeMissing + fun _paymentFraction(): JsonField = paymentFraction + + @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 + * [DiscountConfiguration]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DiscountConfiguration]. */ + class Builder internal constructor() { + + private var cap: JsonField = JsonMissing.of() + private var paymentFraction: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(discountConfiguration: DiscountConfiguration) = apply { + cap = discountConfiguration.cap + paymentFraction = discountConfiguration.paymentFraction + additionalProperties = + discountConfiguration.additionalProperties.toMutableMap() + } + + /** Update the discount cap. Set to null to remove an existing cap. */ + fun cap(cap: Cap?) = cap(JsonField.ofNullable(cap)) + + /** Alias for calling [Builder.cap] with `cap.orElse(null)`. */ + fun cap(cap: Optional) = cap(cap.getOrNull()) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + + /** + * The fraction of the original amount that the customer pays after applying + * the discount. Set to null to remove the discount fraction. For example, + * 0.85 means the customer pays 85% of the original amount (a 15% discount). + */ + fun paymentFraction(paymentFraction: Double?) = + paymentFraction(JsonField.ofNullable(paymentFraction)) + + /** + * Alias for [Builder.paymentFraction]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun paymentFraction(paymentFraction: Double) = + paymentFraction(paymentFraction as Double?) + + /** + * Alias for calling [Builder.paymentFraction] with + * `paymentFraction.orElse(null)`. + */ + fun paymentFraction(paymentFraction: Optional) = + paymentFraction(paymentFraction.getOrNull()) + + /** + * Sets [Builder.paymentFraction] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentFraction] with a well-typed + * [Double] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun paymentFraction(paymentFraction: JsonField) = apply { + this.paymentFraction = paymentFraction + } + + 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 [DiscountConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DiscountConfiguration = + DiscountConfiguration( + cap, + paymentFraction, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): DiscountConfiguration = apply { + if (validated) { + return@apply + } + + cap().ifPresent { it.validate() } + paymentFraction() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (cap.asKnown().getOrNull()?.validity() ?: 0) + + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + /** Update the discount cap. Set to null to remove an existing cap. */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = + spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** + * Accumulated spend ceiling above which the discount stops applying. + */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DiscountConfiguration && + cap == other.cap && + paymentFraction == other.paymentFraction && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(cap, paymentFraction, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DiscountConfiguration{cap=$cap, paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateSpendThresholdConfiguration && + commit == other.commit && + discountConfiguration == other.discountConfiguration && + isEnabled == other.isEnabled && + paymentGateConfig == other.paymentGateConfig && + thresholdAmount == other.thresholdAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + commit, + discountConfiguration, + isEnabled, + paymentGateConfig, + thresholdAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateSpendThresholdConfiguration{commit=$commit, discountConfiguration=$discountConfiguration, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" + } + + class UpdateSubscription + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val endingBefore: JsonField, + private val quantityUpdates: JsonField>, + private val seatUpdates: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("ending_before") + @ExcludeMissing + endingBefore: JsonField = JsonMissing.of(), + @JsonProperty("quantity_updates") + @ExcludeMissing + quantityUpdates: JsonField> = JsonMissing.of(), + @JsonProperty("seat_updates") + @ExcludeMissing + seatUpdates: JsonField = JsonMissing.of(), + ) : this(id, endingBefore, quantityUpdates, seatUpdates, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun endingBefore(): Optional = + endingBefore.getOptional("ending_before") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun quantityUpdates(): Optional> = + quantityUpdates.getOptional("quantity_updates") + + /** + * Manage subscription seats for subscriptions in SEAT_BASED mode. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun seatUpdates(): Optional = seatUpdates.getOptional("seat_updates") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [endingBefore]. + * + * Unlike [endingBefore], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("ending_before") + @ExcludeMissing + fun _endingBefore(): JsonField = endingBefore + + /** + * Returns the raw JSON value of [quantityUpdates]. + * + * Unlike [quantityUpdates], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity_updates") + @ExcludeMissing + fun _quantityUpdates(): JsonField> = quantityUpdates + + /** + * Returns the raw JSON value of [seatUpdates]. + * + * Unlike [seatUpdates], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("seat_updates") + @ExcludeMissing + fun _seatUpdates(): JsonField = seatUpdates + + @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 + * [UpdateSubscription]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateSubscription]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var endingBefore: JsonField = JsonMissing.of() + private var quantityUpdates: JsonField>? = null + private var seatUpdates: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateSubscription: UpdateSubscription) = apply { + id = updateSubscription.id + endingBefore = updateSubscription.endingBefore + quantityUpdates = + updateSubscription.quantityUpdates.map { it.toMutableList() } + seatUpdates = updateSubscription.seatUpdates + additionalProperties = + updateSubscription.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 endingBefore(endingBefore: OffsetDateTime) = + endingBefore(JsonField.of(endingBefore)) + + /** + * Sets [Builder.endingBefore] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBefore] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun endingBefore(endingBefore: JsonField) = apply { + this.endingBefore = endingBefore + } + + fun quantityUpdates(quantityUpdates: List) = + quantityUpdates(JsonField.of(quantityUpdates)) + + /** + * Sets [Builder.quantityUpdates] to an arbitrary JSON value. + * + * You should usually call [Builder.quantityUpdates] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun quantityUpdates(quantityUpdates: JsonField>) = apply { + this.quantityUpdates = quantityUpdates.map { it.toMutableList() } + } + + /** + * Adds a single [QuantityUpdate] to [quantityUpdates]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addQuantityUpdate(quantityUpdate: QuantityUpdate) = apply { + quantityUpdates = + (quantityUpdates ?: JsonField.of(mutableListOf())).also { + checkKnown("quantityUpdates", it).add(quantityUpdate) + } + } + + /** Manage subscription seats for subscriptions in SEAT_BASED mode. */ + fun seatUpdates(seatUpdates: SeatUpdates) = + seatUpdates(JsonField.of(seatUpdates)) + + /** + * Sets [Builder.seatUpdates] to an arbitrary JSON value. + * + * You should usually call [Builder.seatUpdates] with a well-typed [SeatUpdates] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun seatUpdates(seatUpdates: JsonField) = apply { + this.seatUpdates = seatUpdates + } + + 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 [UpdateSubscription]. + * + * 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(): UpdateSubscription = + UpdateSubscription( + checkRequired("id", id), + endingBefore, + (quantityUpdates ?: JsonMissing.of()).map { it.toImmutable() }, + seatUpdates, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): UpdateSubscription = apply { + if (validated) { + return@apply + } + + id() + endingBefore() + quantityUpdates().ifPresent { it.forEach { it.validate() } } + seatUpdates().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (endingBefore.asKnown().isPresent) 1 else 0) + + (quantityUpdates.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (seatUpdates.asKnown().getOrNull()?.validity() ?: 0) + + class QuantityUpdate + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val startingAt: JsonField, + private val quantity: JsonField, + private val quantityDelta: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("quantity_delta") + @ExcludeMissing + quantityDelta: JsonField = JsonMissing.of(), + ) : this(startingAt, quantity, quantityDelta, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun quantityDelta(): Optional = + quantityDelta.getOptional("quantity_delta") + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [quantityDelta]. + * + * Unlike [quantityDelta], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity_delta") + @ExcludeMissing + fun _quantityDelta(): JsonField = quantityDelta + + @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 + * [QuantityUpdate]. + * + * The following fields are required: + * ```java + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [QuantityUpdate]. */ + class Builder internal constructor() { + + private var startingAt: JsonField? = null + private var quantity: JsonField = JsonMissing.of() + private var quantityDelta: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(quantityUpdate: QuantityUpdate) = apply { + startingAt = quantityUpdate.startingAt + quantity = quantityUpdate.quantity + quantityDelta = quantityUpdate.quantityDelta + additionalProperties = + quantityUpdate.additionalProperties.toMutableMap() + } + + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + fun quantityDelta(quantityDelta: Double) = + quantityDelta(JsonField.of(quantityDelta)) + + /** + * Sets [Builder.quantityDelta] to an arbitrary JSON value. + * + * You should usually call [Builder.quantityDelta] with a well-typed + * [Double] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun quantityDelta(quantityDelta: JsonField) = apply { + this.quantityDelta = quantityDelta + } + + 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 [QuantityUpdate]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): QuantityUpdate = + QuantityUpdate( + checkRequired("startingAt", startingAt), + quantity, + quantityDelta, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): QuantityUpdate = apply { + if (validated) { + return@apply + } + + startingAt() + quantity() + quantityDelta() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (startingAt.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + (if (quantityDelta.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is QuantityUpdate && + startingAt == other.startingAt && + quantity == other.quantity && + quantityDelta == other.quantityDelta && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(startingAt, quantity, quantityDelta, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "QuantityUpdate{startingAt=$startingAt, quantity=$quantity, quantityDelta=$quantityDelta, additionalProperties=$additionalProperties}" + } + + /** Manage subscription seats for subscriptions in SEAT_BASED mode. */ + class SeatUpdates + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val addSeatIds: JsonField>, + private val addUnassignedSeats: JsonField>, + private val removeSeatIds: JsonField>, + private val removeUnassignedSeats: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("add_seat_ids") + @ExcludeMissing + addSeatIds: JsonField> = JsonMissing.of(), + @JsonProperty("add_unassigned_seats") + @ExcludeMissing + addUnassignedSeats: JsonField> = JsonMissing.of(), + @JsonProperty("remove_seat_ids") + @ExcludeMissing + removeSeatIds: JsonField> = JsonMissing.of(), + @JsonProperty("remove_unassigned_seats") + @ExcludeMissing + removeUnassignedSeats: JsonField> = + JsonMissing.of(), + ) : this( + addSeatIds, + addUnassignedSeats, + removeSeatIds, + removeUnassignedSeats, + mutableMapOf(), + ) + + /** + * Adds seat IDs to the subscription. If there are unassigned seats, the new + * seat IDs will fill these unassigned seats and not increase the total + * subscription quantity. Otherwise, if there are more new seat IDs than + * unassigned seats, the total subscription quantity will increase. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun addSeatIds(): Optional> = + addSeatIds.getOptional("add_seat_ids") + + /** + * Adds unassigned seats to the subscription. This will increase the total + * subscription quantity. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun addUnassignedSeats(): Optional> = + addUnassignedSeats.getOptional("add_unassigned_seats") + + /** + * Removes seat IDs from the subscription, if possible. If a seat ID is removed, + * the total subscription quantity will decrease. Otherwise, if the seat ID is + * not found on the subscription, this is a no-op. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun removeSeatIds(): Optional> = + removeSeatIds.getOptional("remove_seat_ids") + + /** + * Removes unassigned seats from the subscription. This will decrease the total + * subscription quantity if there are are unassigned seats. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun removeUnassignedSeats(): Optional> = + removeUnassignedSeats.getOptional("remove_unassigned_seats") + + /** + * Returns the raw JSON value of [addSeatIds]. + * + * Unlike [addSeatIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("add_seat_ids") + @ExcludeMissing + fun _addSeatIds(): JsonField> = addSeatIds + + /** + * Returns the raw JSON value of [addUnassignedSeats]. + * + * Unlike [addUnassignedSeats], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("add_unassigned_seats") + @ExcludeMissing + fun _addUnassignedSeats(): JsonField> = + addUnassignedSeats + + /** + * Returns the raw JSON value of [removeSeatIds]. + * + * Unlike [removeSeatIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("remove_seat_ids") + @ExcludeMissing + fun _removeSeatIds(): JsonField> = removeSeatIds + + /** + * Returns the raw JSON value of [removeUnassignedSeats]. + * + * Unlike [removeUnassignedSeats], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("remove_unassigned_seats") + @ExcludeMissing + fun _removeUnassignedSeats(): JsonField> = + removeUnassignedSeats + + @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 [SeatUpdates]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SeatUpdates]. */ + class Builder internal constructor() { + + private var addSeatIds: JsonField>? = null + private var addUnassignedSeats: JsonField>? = + null + private var removeSeatIds: JsonField>? = null + private var removeUnassignedSeats: + JsonField>? = + null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(seatUpdates: SeatUpdates) = apply { + addSeatIds = seatUpdates.addSeatIds.map { it.toMutableList() } + addUnassignedSeats = + seatUpdates.addUnassignedSeats.map { it.toMutableList() } + removeSeatIds = seatUpdates.removeSeatIds.map { it.toMutableList() } + removeUnassignedSeats = + seatUpdates.removeUnassignedSeats.map { it.toMutableList() } + additionalProperties = seatUpdates.additionalProperties.toMutableMap() + } + + /** + * Adds seat IDs to the subscription. If there are unassigned seats, the new + * seat IDs will fill these unassigned seats and not increase the total + * subscription quantity. Otherwise, if there are more new seat IDs than + * unassigned seats, the total subscription quantity will increase. + */ + fun addSeatIds(addSeatIds: List) = + addSeatIds(JsonField.of(addSeatIds)) + + /** + * Sets [Builder.addSeatIds] to an arbitrary JSON value. + * + * You should usually call [Builder.addSeatIds] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun addSeatIds(addSeatIds: JsonField>) = apply { + this.addSeatIds = addSeatIds.map { it.toMutableList() } + } + + /** + * Adds a single [AddSeatId] to [addSeatIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addAddSeatId(addSeatId: AddSeatId) = apply { + addSeatIds = + (addSeatIds ?: JsonField.of(mutableListOf())).also { + checkKnown("addSeatIds", it).add(addSeatId) + } + } + + /** + * Adds unassigned seats to the subscription. This will increase the total + * subscription quantity. + */ + fun addUnassignedSeats(addUnassignedSeats: List) = + addUnassignedSeats(JsonField.of(addUnassignedSeats)) + + /** + * Sets [Builder.addUnassignedSeats] to an arbitrary JSON value. + * + * You should usually call [Builder.addUnassignedSeats] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun addUnassignedSeats( + addUnassignedSeats: JsonField> + ) = apply { + this.addUnassignedSeats = addUnassignedSeats.map { it.toMutableList() } + } + + /** + * Adds a single [AddUnassignedSeat] to [addUnassignedSeats]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addAddUnassignedSeat(addUnassignedSeat: AddUnassignedSeat) = apply { + addUnassignedSeats = + (addUnassignedSeats ?: JsonField.of(mutableListOf())).also { + checkKnown("addUnassignedSeats", it).add(addUnassignedSeat) + } + } + + /** + * Removes seat IDs from the subscription, if possible. If a seat ID is + * removed, the total subscription quantity will decrease. Otherwise, if the + * seat ID is not found on the subscription, this is a no-op. + */ + fun removeSeatIds(removeSeatIds: List) = + removeSeatIds(JsonField.of(removeSeatIds)) + + /** + * Sets [Builder.removeSeatIds] to an arbitrary JSON value. + * + * You should usually call [Builder.removeSeatIds] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun removeSeatIds(removeSeatIds: JsonField>) = apply { + this.removeSeatIds = removeSeatIds.map { it.toMutableList() } + } + + /** + * Adds a single [RemoveSeatId] to [removeSeatIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addRemoveSeatId(removeSeatId: RemoveSeatId) = apply { + removeSeatIds = + (removeSeatIds ?: JsonField.of(mutableListOf())).also { + checkKnown("removeSeatIds", it).add(removeSeatId) + } + } + + /** + * Removes unassigned seats from the subscription. This will decrease the + * total subscription quantity if there are are unassigned seats. + */ + fun removeUnassignedSeats( + removeUnassignedSeats: List + ) = removeUnassignedSeats(JsonField.of(removeUnassignedSeats)) + + /** + * Sets [Builder.removeUnassignedSeats] to an arbitrary JSON value. + * + * You should usually call [Builder.removeUnassignedSeats] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun removeUnassignedSeats( + removeUnassignedSeats: JsonField> + ) = apply { + this.removeUnassignedSeats = + removeUnassignedSeats.map { it.toMutableList() } + } + + /** + * Adds a single [RemoveUnassignedSeat] to [removeUnassignedSeats]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addRemoveUnassignedSeat(removeUnassignedSeat: RemoveUnassignedSeat) = + apply { + removeUnassignedSeats = + (removeUnassignedSeats ?: JsonField.of(mutableListOf())).also { + checkKnown("removeUnassignedSeats", it) + .add(removeUnassignedSeat) + } + } + + 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 [SeatUpdates]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SeatUpdates = + SeatUpdates( + (addSeatIds ?: JsonMissing.of()).map { it.toImmutable() }, + (addUnassignedSeats ?: JsonMissing.of()).map { it.toImmutable() }, + (removeSeatIds ?: JsonMissing.of()).map { it.toImmutable() }, + (removeUnassignedSeats ?: JsonMissing.of()).map { + it.toImmutable() + }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): SeatUpdates = apply { + if (validated) { + return@apply + } + + addSeatIds().ifPresent { it.forEach { it.validate() } } + addUnassignedSeats().ifPresent { it.forEach { it.validate() } } + removeSeatIds().ifPresent { it.forEach { it.validate() } } + removeUnassignedSeats().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (addSeatIds.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (addUnassignedSeats.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + (removeSeatIds.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (removeUnassignedSeats.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) + + class AddSeatId + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val seatIds: JsonField>, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("seat_ids") + @ExcludeMissing + seatIds: JsonField> = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(seatIds, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 seatIds(): List = seatIds.getRequired("seat_ids") + + /** + * Assigned seats will be added/removed starting at this date. + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [seatIds]. + * + * Unlike [seatIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("seat_ids") + @ExcludeMissing + fun _seatIds(): JsonField> = seatIds + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [AddSeatId]. + * + * The following fields are required: + * ```java + * .seatIds() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddSeatId]. */ + class Builder internal constructor() { + + private var seatIds: JsonField>? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(addSeatId: AddSeatId) = apply { + seatIds = addSeatId.seatIds.map { it.toMutableList() } + startingAt = addSeatId.startingAt + additionalProperties = addSeatId.additionalProperties.toMutableMap() + } + + fun seatIds(seatIds: List) = seatIds(JsonField.of(seatIds)) + + /** + * Sets [Builder.seatIds] to an arbitrary JSON value. + * + * You should usually call [Builder.seatIds] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun seatIds(seatIds: JsonField>) = apply { + this.seatIds = seatIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [seatIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addSeatId(seatId: String) = apply { + seatIds = + (seatIds ?: JsonField.of(mutableListOf())).also { + checkKnown("seatIds", it).add(seatId) + } + } + + /** Assigned seats will be added/removed starting at this date. */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [AddSeatId]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .seatIds() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddSeatId = + AddSeatId( + checkRequired("seatIds", seatIds).map { it.toImmutable() }, + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AddSeatId = apply { + if (validated) { + return@apply + } + + seatIds() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (seatIds.asKnown().getOrNull()?.size ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddSeatId && + seatIds == other.seatIds && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(seatIds, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddSeatId{seatIds=$seatIds, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + class AddUnassignedSeat + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val quantity: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(quantity, startingAt, mutableMapOf()) + + /** + * The number of unassigned seats on the subscription will increase/decrease + * by this delta. Must be greater than 0. + * + * @throws MetronomeInvalidDataException 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 quantity(): Double = quantity.getRequired("quantity") + + /** + * Unassigned seats will be updated starting at this date. + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [AddUnassignedSeat]. + * + * The following fields are required: + * ```java + * .quantity() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddUnassignedSeat]. */ + class Builder internal constructor() { + + private var quantity: JsonField? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(addUnassignedSeat: AddUnassignedSeat) = apply { + quantity = addUnassignedSeat.quantity + startingAt = addUnassignedSeat.startingAt + additionalProperties = + addUnassignedSeat.additionalProperties.toMutableMap() + } + + /** + * The number of unassigned seats on the subscription will + * increase/decrease by this delta. Must be greater than 0. + */ + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + /** Unassigned seats will be updated starting at this date. */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [AddUnassignedSeat]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .quantity() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddUnassignedSeat = + AddUnassignedSeat( + checkRequired("quantity", quantity), + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): AddUnassignedSeat = apply { + if (validated) { + return@apply + } + + quantity() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (quantity.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddUnassignedSeat && + quantity == other.quantity && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(quantity, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddUnassignedSeat{quantity=$quantity, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + class RemoveSeatId + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val seatIds: JsonField>, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("seat_ids") + @ExcludeMissing + seatIds: JsonField> = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(seatIds, startingAt, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 seatIds(): List = seatIds.getRequired("seat_ids") + + /** + * Assigned seats will be added/removed starting at this date. + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [seatIds]. + * + * Unlike [seatIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("seat_ids") + @ExcludeMissing + fun _seatIds(): JsonField> = seatIds + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [RemoveSeatId]. + * + * The following fields are required: + * ```java + * .seatIds() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveSeatId]. */ + class Builder internal constructor() { + + private var seatIds: JsonField>? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(removeSeatId: RemoveSeatId) = apply { + seatIds = removeSeatId.seatIds.map { it.toMutableList() } + startingAt = removeSeatId.startingAt + additionalProperties = + removeSeatId.additionalProperties.toMutableMap() + } + + fun seatIds(seatIds: List) = seatIds(JsonField.of(seatIds)) + + /** + * Sets [Builder.seatIds] to an arbitrary JSON value. + * + * You should usually call [Builder.seatIds] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun seatIds(seatIds: JsonField>) = apply { + this.seatIds = seatIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [seatIds]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addSeatId(seatId: String) = apply { + seatIds = + (seatIds ?: JsonField.of(mutableListOf())).also { + checkKnown("seatIds", it).add(seatId) + } + } + + /** Assigned seats will be added/removed starting at this date. */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [RemoveSeatId]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .seatIds() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RemoveSeatId = + RemoveSeatId( + checkRequired("seatIds", seatIds).map { it.toImmutable() }, + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RemoveSeatId = apply { + if (validated) { + return@apply + } + + seatIds() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (seatIds.asKnown().getOrNull()?.size ?: 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemoveSeatId && + seatIds == other.seatIds && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(seatIds, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveSeatId{seatIds=$seatIds, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + class RemoveUnassignedSeat + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val quantity: JsonField, + private val startingAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("starting_at") + @ExcludeMissing + startingAt: JsonField = JsonMissing.of(), + ) : this(quantity, startingAt, mutableMapOf()) + + /** + * The number of unassigned seats on the subscription will increase/decrease + * by this delta. Must be greater than 0. + * + * @throws MetronomeInvalidDataException 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 quantity(): Double = quantity.getRequired("quantity") + + /** + * Unassigned seats will be updated starting at this date. + * + * @throws MetronomeInvalidDataException 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 startingAt(): OffsetDateTime = startingAt.getRequired("starting_at") + + /** + * Returns the raw JSON value of [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + /** + * Returns the raw JSON value of [startingAt]. + * + * Unlike [startingAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_at") + @ExcludeMissing + fun _startingAt(): JsonField = startingAt + + @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 + * [RemoveUnassignedSeat]. + * + * The following fields are required: + * ```java + * .quantity() + * .startingAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RemoveUnassignedSeat]. */ + class Builder internal constructor() { + + private var quantity: JsonField? = null + private var startingAt: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(removeUnassignedSeat: RemoveUnassignedSeat) = apply { + quantity = removeUnassignedSeat.quantity + startingAt = removeUnassignedSeat.startingAt + additionalProperties = + removeUnassignedSeat.additionalProperties.toMutableMap() + } + + /** + * The number of unassigned seats on the subscription will + * increase/decrease by this delta. Must be greater than 0. + */ + fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { + this.quantity = quantity + } + + /** Unassigned seats will be updated starting at this date. */ + fun startingAt(startingAt: OffsetDateTime) = + startingAt(JsonField.of(startingAt)) + + /** + * Sets [Builder.startingAt] to an arbitrary JSON value. + * + * You should usually call [Builder.startingAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun startingAt(startingAt: JsonField) = apply { + this.startingAt = startingAt + } + + 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 [RemoveUnassignedSeat]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .quantity() + * .startingAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RemoveUnassignedSeat = + RemoveUnassignedSeat( + checkRequired("quantity", quantity), + checkRequired("startingAt", startingAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): RemoveUnassignedSeat = apply { + if (validated) { + return@apply + } + + quantity() + startingAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (quantity.asKnown().isPresent) 1 else 0) + + (if (startingAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemoveUnassignedSeat && + quantity == other.quantity && + startingAt == other.startingAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(quantity, startingAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveUnassignedSeat{quantity=$quantity, startingAt=$startingAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SeatUpdates && + addSeatIds == other.addSeatIds && + addUnassignedSeats == other.addUnassignedSeats && + removeSeatIds == other.removeSeatIds && + removeUnassignedSeats == other.removeUnassignedSeats && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + addSeatIds, + addUnassignedSeats, + removeSeatIds, + removeUnassignedSeats, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SeatUpdates{addSeatIds=$addSeatIds, addUnassignedSeats=$addUnassignedSeats, removeSeatIds=$removeSeatIds, removeUnassignedSeats=$removeUnassignedSeats, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateSubscription && + id == other.id && + endingBefore == other.endingBefore && + quantityUpdates == other.quantityUpdates && + seatUpdates == other.seatUpdates && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + endingBefore, + quantityUpdates, + seatUpdates, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateSubscription{id=$id, endingBefore=$endingBefore, quantityUpdates=$quantityUpdates, seatUpdates=$seatUpdates, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Edit && + id == other.id && + addCommits == other.addCommits && + addCredits == other.addCredits && + addDiscounts == other.addDiscounts && + addOverrides == other.addOverrides && + addPrepaidBalanceThresholdConfiguration == + other.addPrepaidBalanceThresholdConfiguration && + addProServices == other.addProServices && + addRecurringCommits == other.addRecurringCommits && + addRecurringCredits == other.addRecurringCredits && + addResellerRoyalties == other.addResellerRoyalties && + addScheduledCharges == other.addScheduledCharges && + addSpendThresholdConfiguration == other.addSpendThresholdConfiguration && + addSubscriptions == other.addSubscriptions && + addUsageFilters == other.addUsageFilters && + archiveCommits == other.archiveCommits && + archiveCredits == other.archiveCredits && + archiveScheduledCharges == other.archiveScheduledCharges && + removeOverrides == other.removeOverrides && + timestamp == other.timestamp && + uniquenessKey == other.uniquenessKey && + updateCommits == other.updateCommits && + updateContractEndDate == other.updateContractEndDate && + updateContractName == other.updateContractName && + updateCredits == other.updateCredits && + updateDiscounts == other.updateDiscounts && + updatePrepaidBalanceThresholdConfiguration == + other.updatePrepaidBalanceThresholdConfiguration && + updateRecurringCommits == other.updateRecurringCommits && + updateRecurringCredits == other.updateRecurringCredits && + updateRefundInvoices == other.updateRefundInvoices && + updateScheduledCharges == other.updateScheduledCharges && + updateSpendThresholdConfiguration == other.updateSpendThresholdConfiguration && + updateSubscriptions == other.updateSubscriptions && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + addCommits, + addCredits, + addDiscounts, + addOverrides, + addPrepaidBalanceThresholdConfiguration, + addProServices, + addRecurringCommits, + addRecurringCredits, + addResellerRoyalties, + addScheduledCharges, + addSpendThresholdConfiguration, + addSubscriptions, + addUsageFilters, + archiveCommits, + archiveCredits, + archiveScheduledCharges, + removeOverrides, + timestamp, + uniquenessKey, + updateCommits, + updateContractEndDate, + updateContractName, + updateCredits, + updateDiscounts, + updatePrepaidBalanceThresholdConfiguration, + updateRecurringCommits, + updateRecurringCredits, + updateRefundInvoices, + updateScheduledCharges, + updateSpendThresholdConfiguration, + updateSubscriptions, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Edit{id=$id, addCommits=$addCommits, addCredits=$addCredits, addDiscounts=$addDiscounts, addOverrides=$addOverrides, addPrepaidBalanceThresholdConfiguration=$addPrepaidBalanceThresholdConfiguration, addProServices=$addProServices, addRecurringCommits=$addRecurringCommits, addRecurringCredits=$addRecurringCredits, addResellerRoyalties=$addResellerRoyalties, addScheduledCharges=$addScheduledCharges, addSpendThresholdConfiguration=$addSpendThresholdConfiguration, addSubscriptions=$addSubscriptions, addUsageFilters=$addUsageFilters, archiveCommits=$archiveCommits, archiveCredits=$archiveCredits, archiveScheduledCharges=$archiveScheduledCharges, removeOverrides=$removeOverrides, timestamp=$timestamp, uniquenessKey=$uniquenessKey, updateCommits=$updateCommits, updateContractEndDate=$updateContractEndDate, updateContractName=$updateContractName, updateCredits=$updateCredits, updateDiscounts=$updateDiscounts, updatePrepaidBalanceThresholdConfiguration=$updatePrepaidBalanceThresholdConfiguration, updateRecurringCommits=$updateRecurringCommits, updateRecurringCredits=$updateRecurringCredits, updateRefundInvoices=$updateRefundInvoices, updateScheduledCharges=$updateScheduledCharges, updateSpendThresholdConfiguration=$updateSpendThresholdConfiguration, updateSubscriptions=$updateSubscriptions, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && + id == other.id && + edit == other.edit && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, edit, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Data{id=$id, edit=$edit, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractGetEditHistoryResponse.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractGetEditHistoryResponse.kt index 0973d885..8fe88304 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractGetEditHistoryResponse.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/models/v2/contracts/ContractGetEditHistoryResponse.kt @@ -26919,6 +26919,7 @@ private constructor( private val paymentGateConfig: JsonField, private val rechargeToAmount: JsonField, private val thresholdAmount: JsonField, + private val thresholdBalanceSpecifiers: JsonField>, private val additionalProperties: MutableMap, ) { @@ -26945,6 +26946,10 @@ private constructor( @JsonProperty("threshold_amount") @ExcludeMissing thresholdAmount: JsonField = JsonMissing.of(), + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + thresholdBalanceSpecifiers: JsonField> = + JsonMissing.of(), ) : this( commit, customCreditTypeId, @@ -26953,6 +26958,7 @@ private constructor( paymentGateConfig, rechargeToAmount, thresholdAmount, + thresholdBalanceSpecifiers, mutableMapOf(), ) @@ -27014,6 +27020,13 @@ private constructor( fun thresholdAmount(): Optional = thresholdAmount.getOptional("threshold_amount") + /** + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun thresholdBalanceSpecifiers(): Optional> = + thresholdBalanceSpecifiers.getOptional("threshold_balance_specifiers") + /** * Returns the raw JSON value of [commit]. * @@ -27081,6 +27094,17 @@ private constructor( @ExcludeMissing fun _thresholdAmount(): JsonField = thresholdAmount + /** + * Returns the raw JSON value of [thresholdBalanceSpecifiers]. + * + * Unlike [thresholdBalanceSpecifiers], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("threshold_balance_specifiers") + @ExcludeMissing + fun _thresholdBalanceSpecifiers(): JsonField> = + thresholdBalanceSpecifiers + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -27113,6 +27137,9 @@ private constructor( private var paymentGateConfig: JsonField = JsonMissing.of() private var rechargeToAmount: JsonField = JsonMissing.of() private var thresholdAmount: JsonField = JsonMissing.of() + private var thresholdBalanceSpecifiers: + JsonField>? = + null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -27129,6 +27156,10 @@ private constructor( paymentGateConfig = updatePrepaidBalanceThresholdConfiguration.paymentGateConfig rechargeToAmount = updatePrepaidBalanceThresholdConfiguration.rechargeToAmount thresholdAmount = updatePrepaidBalanceThresholdConfiguration.thresholdAmount + thresholdBalanceSpecifiers = + updatePrepaidBalanceThresholdConfiguration.thresholdBalanceSpecifiers.map { + it.toMutableList() + } additionalProperties = updatePrepaidBalanceThresholdConfiguration.additionalProperties .toMutableMap() @@ -27255,6 +27286,47 @@ private constructor( this.thresholdAmount = thresholdAmount } + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: List? + ) = thresholdBalanceSpecifiers(JsonField.ofNullable(thresholdBalanceSpecifiers)) + + /** + * Alias for calling [Builder.thresholdBalanceSpecifiers] with + * `thresholdBalanceSpecifiers.orElse(null)`. + */ + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: Optional> + ) = thresholdBalanceSpecifiers(thresholdBalanceSpecifiers.getOrNull()) + + /** + * Sets [Builder.thresholdBalanceSpecifiers] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdBalanceSpecifiers] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun thresholdBalanceSpecifiers( + thresholdBalanceSpecifiers: JsonField> + ) = apply { + this.thresholdBalanceSpecifiers = + thresholdBalanceSpecifiers.map { it.toMutableList() } + } + + /** + * Adds a single [ThresholdBalanceSpecifier] to [thresholdBalanceSpecifiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addThresholdBalanceSpecifier( + thresholdBalanceSpecifier: ThresholdBalanceSpecifier + ) = apply { + thresholdBalanceSpecifiers = + (thresholdBalanceSpecifiers ?: JsonField.of(mutableListOf())).also { + checkKnown("thresholdBalanceSpecifiers", it) + .add(thresholdBalanceSpecifier) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -27291,6 +27363,7 @@ private constructor( paymentGateConfig, rechargeToAmount, thresholdAmount, + (thresholdBalanceSpecifiers ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -27319,6 +27392,7 @@ private constructor( paymentGateConfig().ifPresent { it.validate() } rechargeToAmount() thresholdAmount() + thresholdBalanceSpecifiers().ifPresent { it.forEach { it.validate() } } validated = true } @@ -27344,7 +27418,10 @@ private constructor( (if (isEnabled.asKnown().isPresent) 1 else 0) + (paymentGateConfig.asKnown().getOrNull()?.validity() ?: 0) + (if (rechargeToAmount.asKnown().isPresent) 1 else 0) + - (if (thresholdAmount.asKnown().isPresent) 1 else 0) + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + (thresholdBalanceSpecifiers.asKnown().getOrNull()?.sumOf { + it.validity().toInt() + } ?: 0) class Commit @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -27899,16 +27976,26 @@ private constructor( class DiscountConfiguration @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val cap: JsonField, private val paymentFraction: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), @JsonProperty("payment_fraction") @ExcludeMissing - paymentFraction: JsonField = JsonMissing.of() - ) : this(paymentFraction, mutableMapOf()) + paymentFraction: JsonField = JsonMissing.of(), + ) : this(cap, paymentFraction, mutableMapOf()) + + /** + * Update the discount cap. Set to null to remove an existing cap. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") /** * The fraction of the original amount that the customer pays after applying the @@ -27921,6 +28008,13 @@ private constructor( fun paymentFraction(): Optional = paymentFraction.getOptional("payment_fraction") + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + /** * Returns the raw JSON value of [paymentFraction]. * @@ -27955,16 +28049,33 @@ private constructor( /** A builder for [DiscountConfiguration]. */ class Builder internal constructor() { + private var cap: JsonField = JsonMissing.of() private var paymentFraction: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(discountConfiguration: DiscountConfiguration) = apply { + cap = discountConfiguration.cap paymentFraction = discountConfiguration.paymentFraction additionalProperties = discountConfiguration.additionalProperties.toMutableMap() } + /** Update the discount cap. Set to null to remove an existing cap. */ + fun cap(cap: Cap?) = cap(JsonField.ofNullable(cap)) + + /** Alias for calling [Builder.cap] with `cap.orElse(null)`. */ + fun cap(cap: Optional) = cap(cap.getOrNull()) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + /** * The fraction of the original amount that the customer pays after applying the * discount. Set to null to remove the discount fraction. For example, 0.85 @@ -28027,65 +28138,1121 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): DiscountConfiguration = - DiscountConfiguration(paymentFraction, additionalProperties.toMutableMap()) + DiscountConfiguration( + cap, + paymentFraction, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DiscountConfiguration = apply { + if (validated) { + return@apply + } + + cap().ifPresent { it.validate() } + paymentFraction() + validated = true } - private var validated: Boolean = false + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (cap.asKnown().getOrNull()?.validity() ?: 0) + + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + /** Update the discount cap. Set to null to remove an existing cap. */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = + spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** Accumulated spend ceiling above which the discount stops applying. */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DiscountConfiguration && + cap == other.cap && + paymentFraction == other.paymentFraction && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(cap, paymentFraction, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DiscountConfiguration{cap=$cap, paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + } + + class ThresholdBalanceSpecifier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val exclude: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("exclude") + @ExcludeMissing + exclude: JsonField> = JsonMissing.of() + ) : this(exclude, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 exclude(): List = exclude.getRequired("exclude") + + /** + * Returns the raw JSON value of [exclude]. + * + * Unlike [exclude], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("exclude") + @ExcludeMissing + fun _exclude(): JsonField> = exclude + + @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 + * [ThresholdBalanceSpecifier]. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThresholdBalanceSpecifier]. */ + class Builder internal constructor() { + + private var exclude: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(thresholdBalanceSpecifier: ThresholdBalanceSpecifier) = + apply { + exclude = thresholdBalanceSpecifier.exclude.map { it.toMutableList() } + additionalProperties = + thresholdBalanceSpecifier.additionalProperties.toMutableMap() + } + + fun exclude(exclude: List) = exclude(JsonField.of(exclude)) + + /** + * Sets [Builder.exclude] to an arbitrary JSON value. + * + * You should usually call [Builder.exclude] with a well-typed `List` + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun exclude(exclude: JsonField>) = apply { + this.exclude = exclude.map { it.toMutableList() } + } + + /** + * Adds a single [Exclude] to [Builder.exclude]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExclude(exclude: Exclude) = apply { + this.exclude = + (this.exclude ?: JsonField.of(mutableListOf())).also { + checkKnown("exclude", it).add(exclude) + } + } + + 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 [ThresholdBalanceSpecifier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .exclude() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThresholdBalanceSpecifier = + ThresholdBalanceSpecifier( + checkRequired("exclude", exclude).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws MetronomeInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ThresholdBalanceSpecifier = apply { + if (validated) { + return@apply + } + + exclude().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (exclude.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Exclude + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val customFieldFilters: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("custom_field_filters") + @ExcludeMissing + customFieldFilters: JsonField> = JsonMissing.of() + ) : this(customFieldFilters, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 customFieldFilters(): List = + customFieldFilters.getRequired("custom_field_filters") + + /** + * Returns the raw JSON value of [customFieldFilters]. + * + * Unlike [customFieldFilters], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("custom_field_filters") + @ExcludeMissing + fun _customFieldFilters(): JsonField> = + customFieldFilters + + @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 [Exclude]. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Exclude]. */ + class Builder internal constructor() { + + private var customFieldFilters: JsonField>? = + null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(exclude: Exclude) = apply { + customFieldFilters = + exclude.customFieldFilters.map { it.toMutableList() } + additionalProperties = exclude.additionalProperties.toMutableMap() + } + + fun customFieldFilters(customFieldFilters: List) = + customFieldFilters(JsonField.of(customFieldFilters)) + + /** + * Sets [Builder.customFieldFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.customFieldFilters] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun customFieldFilters( + customFieldFilters: JsonField> + ) = apply { + this.customFieldFilters = customFieldFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CustomFieldFilter] to [customFieldFilters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addCustomFieldFilter(customFieldFilter: CustomFieldFilter) = apply { + customFieldFilters = + (customFieldFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("customFieldFilters", it).add(customFieldFilter) + } + } + + 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 [Exclude]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .customFieldFilters() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Exclude = + Exclude( + checkRequired("customFieldFilters", customFieldFilters).map { + it.toImmutable() + }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Exclude = apply { + if (validated) { + return@apply + } + + customFieldFilters().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (customFieldFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + class CustomFieldFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val entity: JsonField, + private val key: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("entity") + @ExcludeMissing + entity: JsonField = JsonMissing.of(), + @JsonProperty("key") + @ExcludeMissing + key: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(entity, key, value, mutableMapOf()) + + /** + * @throws MetronomeInvalidDataException 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 entity(): Entity = entity.getRequired("entity") + + /** + * @throws MetronomeInvalidDataException 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 key(): String = key.getRequired("key") + + /** + * @throws MetronomeInvalidDataException 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 [entity]. + * + * Unlike [entity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("entity") + @ExcludeMissing + fun _entity(): JsonField = entity + + /** + * Returns the raw JSON value of [key]. + * + * Unlike [key], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("key") @ExcludeMissing fun _key(): JsonField = key + + /** + * 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 + * [CustomFieldFilter]. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFieldFilter]. */ + class Builder internal constructor() { + + private var entity: JsonField? = null + private var key: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(customFieldFilter: CustomFieldFilter) = apply { + entity = customFieldFilter.entity + key = customFieldFilter.key + value = customFieldFilter.value + additionalProperties = + customFieldFilter.additionalProperties.toMutableMap() + } + + fun entity(entity: Entity) = entity(JsonField.of(entity)) + + /** + * Sets [Builder.entity] to an arbitrary JSON value. + * + * You should usually call [Builder.entity] with a well-typed [Entity] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun entity(entity: JsonField) = apply { this.entity = entity } + + fun key(key: String) = key(JsonField.of(key)) + + /** + * Sets [Builder.key] to an arbitrary JSON value. + * + * You should usually call [Builder.key] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun key(key: JsonField) = apply { this.key = key } + + 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 [CustomFieldFilter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .entity() + * .key() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomFieldFilter = + CustomFieldFilter( + checkRequired("entity", entity), + checkRequired("key", key), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): CustomFieldFilter = apply { + if (validated) { + return@apply + } + + entity().validate() + key() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 = + (entity.asKnown().getOrNull()?.validity() ?: 0) + + (if (key.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) + + class Entity + @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 COMMIT = of("Commit") + + @JvmField val CONTRACT_CREDIT = of("ContractCredit") + + @JvmField + val CONTRACT_CREDIT_OR_COMMIT = of("ContractCreditOrCommit") + + @JvmStatic fun of(value: String) = Entity(JsonField.of(value)) + } + + /** An enum containing [Entity]'s known values. */ + enum class Known { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + } + + /** + * An enum containing [Entity]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Entity] 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 { + COMMIT, + CONTRACT_CREDIT, + CONTRACT_CREDIT_OR_COMMIT, + /** + * An enum member indicating that [Entity] 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) { + COMMIT -> Value.COMMIT + CONTRACT_CREDIT -> Value.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Value.CONTRACT_CREDIT_OR_COMMIT + 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 MetronomeInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + COMMIT -> Known.COMMIT + CONTRACT_CREDIT -> Known.CONTRACT_CREDIT + CONTRACT_CREDIT_OR_COMMIT -> Known.CONTRACT_CREDIT_OR_COMMIT + else -> + throw MetronomeInvalidDataException( + "Unknown Entity: $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 MetronomeInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + MetronomeInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Entity = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 Entity && 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 CustomFieldFilter && + entity == other.entity && + key == other.key && + value == other.value && + additionalProperties == other.additionalProperties + } - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws MetronomeInvalidDataException if any value type in this object doesn't - * match its expected type. - */ - fun validate(): DiscountConfiguration = apply { - if (validated) { - return@apply + private val hashCode: Int by lazy { + Objects.hash(entity, key, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomFieldFilter{entity=$entity, key=$key, value=$value, additionalProperties=$additionalProperties}" } - paymentFraction() - validated = true - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: MetronomeInvalidDataException) { - false + return other is Exclude && + customFieldFilters == other.customFieldFilters && + additionalProperties == other.additionalProperties } - /** - * 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 (paymentFraction.asKnown().isPresent) 1 else 0) + private val hashCode: Int by lazy { + Objects.hash(customFieldFilters, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Exclude{customFieldFilters=$customFieldFilters, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is DiscountConfiguration && - paymentFraction == other.paymentFraction && + return other is ThresholdBalanceSpecifier && + exclude == other.exclude && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { - Objects.hash(paymentFraction, additionalProperties) - } + private val hashCode: Int by lazy { Objects.hash(exclude, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "DiscountConfiguration{paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + "ThresholdBalanceSpecifier{exclude=$exclude, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -28101,6 +29268,7 @@ private constructor( paymentGateConfig == other.paymentGateConfig && rechargeToAmount == other.rechargeToAmount && thresholdAmount == other.thresholdAmount && + thresholdBalanceSpecifiers == other.thresholdBalanceSpecifiers && additionalProperties == other.additionalProperties } @@ -28113,6 +29281,7 @@ private constructor( paymentGateConfig, rechargeToAmount, thresholdAmount, + thresholdBalanceSpecifiers, additionalProperties, ) } @@ -28120,7 +29289,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "UpdatePrepaidBalanceThresholdConfiguration{commit=$commit, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" + "UpdatePrepaidBalanceThresholdConfiguration{commit=$commit, customCreditTypeId=$customCreditTypeId, discountConfiguration=$discountConfiguration, isEnabled=$isEnabled, paymentGateConfig=$paymentGateConfig, rechargeToAmount=$rechargeToAmount, thresholdAmount=$thresholdAmount, thresholdBalanceSpecifiers=$thresholdBalanceSpecifiers, additionalProperties=$additionalProperties}" } class UpdateRecurringCommit @@ -31613,16 +32782,26 @@ private constructor( class DiscountConfiguration @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val cap: JsonField, private val paymentFraction: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( + @JsonProperty("cap") @ExcludeMissing cap: JsonField = JsonMissing.of(), @JsonProperty("payment_fraction") @ExcludeMissing - paymentFraction: JsonField = JsonMissing.of() - ) : this(paymentFraction, mutableMapOf()) + paymentFraction: JsonField = JsonMissing.of(), + ) : this(cap, paymentFraction, mutableMapOf()) + + /** + * Update the discount cap. Set to null to remove an existing cap. + * + * @throws MetronomeInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun cap(): Optional = cap.getOptional("cap") /** * The fraction of the original amount that the customer pays after applying the @@ -31635,6 +32814,13 @@ private constructor( fun paymentFraction(): Optional = paymentFraction.getOptional("payment_fraction") + /** + * Returns the raw JSON value of [cap]. + * + * Unlike [cap], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cap") @ExcludeMissing fun _cap(): JsonField = cap + /** * Returns the raw JSON value of [paymentFraction]. * @@ -31669,16 +32855,33 @@ private constructor( /** A builder for [DiscountConfiguration]. */ class Builder internal constructor() { + private var cap: JsonField = JsonMissing.of() private var paymentFraction: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(discountConfiguration: DiscountConfiguration) = apply { + cap = discountConfiguration.cap paymentFraction = discountConfiguration.paymentFraction additionalProperties = discountConfiguration.additionalProperties.toMutableMap() } + /** Update the discount cap. Set to null to remove an existing cap. */ + fun cap(cap: Cap?) = cap(JsonField.ofNullable(cap)) + + /** Alias for calling [Builder.cap] with `cap.orElse(null)`. */ + fun cap(cap: Optional) = cap(cap.getOrNull()) + + /** + * Sets [Builder.cap] to an arbitrary JSON value. + * + * You should usually call [Builder.cap] with a well-typed [Cap] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cap(cap: JsonField) = apply { this.cap = cap } + /** * The fraction of the original amount that the customer pays after applying the * discount. Set to null to remove the discount fraction. For example, 0.85 @@ -31741,7 +32944,11 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): DiscountConfiguration = - DiscountConfiguration(paymentFraction, additionalProperties.toMutableMap()) + DiscountConfiguration( + cap, + paymentFraction, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -31761,6 +32968,7 @@ private constructor( return@apply } + cap().ifPresent { it.validate() } paymentFraction() validated = true } @@ -31780,7 +32988,240 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = (if (paymentFraction.asKnown().isPresent) 1 else 0) + internal fun validity(): Int = + (cap.asKnown().getOrNull()?.validity() ?: 0) + + (if (paymentFraction.asKnown().isPresent) 1 else 0) + + /** Update the discount cap. Set to null to remove an existing cap. */ + class Cap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val spendTrackerAlias: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + spendTrackerAlias: JsonField = JsonMissing.of(), + ) : this(amount, spendTrackerAlias, mutableMapOf()) + + /** + * Accumulated spend ceiling above which the discount stops applying. + * + * @throws MetronomeInvalidDataException 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 amount(): Double = amount.getRequired("amount") + + /** + * Alias of the spend tracker this cap is measured against. + * + * @throws MetronomeInvalidDataException 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 spendTrackerAlias(): String = + spendTrackerAlias.getRequired("spend_tracker_alias") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("amount") + @ExcludeMissing + fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [spendTrackerAlias]. + * + * Unlike [spendTrackerAlias], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("spend_tracker_alias") + @ExcludeMissing + fun _spendTrackerAlias(): JsonField = spendTrackerAlias + + @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 [Cap]. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Cap]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var spendTrackerAlias: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(cap: Cap) = apply { + amount = cap.amount + spendTrackerAlias = cap.spendTrackerAlias + additionalProperties = cap.additionalProperties.toMutableMap() + } + + /** Accumulated spend ceiling above which the discount stops applying. */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** Alias of the spend tracker this cap is measured against. */ + fun spendTrackerAlias(spendTrackerAlias: String) = + spendTrackerAlias(JsonField.of(spendTrackerAlias)) + + /** + * Sets [Builder.spendTrackerAlias] to an arbitrary JSON value. + * + * You should usually call [Builder.spendTrackerAlias] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun spendTrackerAlias(spendTrackerAlias: JsonField) = apply { + this.spendTrackerAlias = spendTrackerAlias + } + + 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 [Cap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .spendTrackerAlias() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Cap = + Cap( + checkRequired("amount", amount), + checkRequired("spendTrackerAlias", spendTrackerAlias), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws MetronomeInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Cap = apply { + if (validated) { + return@apply + } + + amount() + spendTrackerAlias() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: MetronomeInvalidDataException) { + 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 (amount.asKnown().isPresent) 1 else 0) + + (if (spendTrackerAlias.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Cap && + amount == other.amount && + spendTrackerAlias == other.spendTrackerAlias && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(amount, spendTrackerAlias, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Cap{amount=$amount, spendTrackerAlias=$spendTrackerAlias, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -31788,18 +33229,19 @@ private constructor( } return other is DiscountConfiguration && + cap == other.cap && paymentFraction == other.paymentFraction && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(paymentFraction, additionalProperties) + Objects.hash(cap, paymentFraction, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "DiscountConfiguration{paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" + "DiscountConfiguration{cap=$cap, paymentFraction=$paymentFraction, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/V1ServiceAsync.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/V1ServiceAsync.kt index 6277b28a..a8322e0b 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/V1ServiceAsync.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/V1ServiceAsync.kt @@ -13,7 +13,6 @@ import com.metronome.api.services.async.v1.CustomerServiceAsync import com.metronome.api.services.async.v1.DashboardServiceAsync import com.metronome.api.services.async.v1.InvoiceServiceAsync import com.metronome.api.services.async.v1.PackageServiceAsync -import com.metronome.api.services.async.v1.PaymentServiceAsync import com.metronome.api.services.async.v1.PlanServiceAsync import com.metronome.api.services.async.v1.PricingUnitServiceAsync import com.metronome.api.services.async.v1.ServiceServiceAsync @@ -118,8 +117,6 @@ interface V1ServiceAsync { fun packages(): PackageServiceAsync - fun payments(): PaymentServiceAsync - /** * Use these endpoints to configure a billing API key, a webhook secret, or invoice finalization * behavior. @@ -220,8 +217,6 @@ interface V1ServiceAsync { fun packages(): PackageServiceAsync.WithRawResponse - fun payments(): PaymentServiceAsync.WithRawResponse - /** * Use these endpoints to configure a billing API key, a webhook secret, or invoice * finalization behavior. diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/V1ServiceAsyncImpl.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/V1ServiceAsyncImpl.kt index f337abc8..d654568b 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/V1ServiceAsyncImpl.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/V1ServiceAsyncImpl.kt @@ -23,8 +23,6 @@ import com.metronome.api.services.async.v1.InvoiceServiceAsync import com.metronome.api.services.async.v1.InvoiceServiceAsyncImpl import com.metronome.api.services.async.v1.PackageServiceAsync import com.metronome.api.services.async.v1.PackageServiceAsyncImpl -import com.metronome.api.services.async.v1.PaymentServiceAsync -import com.metronome.api.services.async.v1.PaymentServiceAsyncImpl import com.metronome.api.services.async.v1.PlanServiceAsync import com.metronome.api.services.async.v1.PlanServiceAsyncImpl import com.metronome.api.services.async.v1.PricingUnitServiceAsync @@ -82,8 +80,6 @@ class V1ServiceAsyncImpl internal constructor(private val clientOptions: ClientO private val packages: PackageServiceAsync by lazy { PackageServiceAsyncImpl(clientOptions) } - private val payments: PaymentServiceAsync by lazy { PaymentServiceAsyncImpl(clientOptions) } - private val settings: SettingServiceAsync by lazy { SettingServiceAsyncImpl(clientOptions) } override fun withRawResponse(): V1ServiceAsync.WithRawResponse = withRawResponse @@ -174,8 +170,6 @@ class V1ServiceAsyncImpl internal constructor(private val clientOptions: ClientO override fun packages(): PackageServiceAsync = packages - override fun payments(): PaymentServiceAsync = payments - /** * Use these endpoints to configure a billing API key, a webhook secret, or invoice finalization * behavior. @@ -241,10 +235,6 @@ class V1ServiceAsyncImpl internal constructor(private val clientOptions: ClientO PackageServiceAsyncImpl.WithRawResponseImpl(clientOptions) } - private val payments: PaymentServiceAsync.WithRawResponse by lazy { - PaymentServiceAsyncImpl.WithRawResponseImpl(clientOptions) - } - private val settings: SettingServiceAsync.WithRawResponse by lazy { SettingServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -340,8 +330,6 @@ class V1ServiceAsyncImpl internal constructor(private val clientOptions: ClientO override fun packages(): PackageServiceAsync.WithRawResponse = packages - override fun payments(): PaymentServiceAsync.WithRawResponse = payments - /** * Use these endpoints to configure a billing API key, a webhook secret, or invoice * finalization behavior. diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PackageServiceAsync.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PackageServiceAsync.kt index 589549aa..342fc1dc 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PackageServiceAsync.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PackageServiceAsync.kt @@ -145,9 +145,9 @@ interface PackageServiceAsync { * package. * * ### **Usage guidelines:** - * Use the **`starting_at`**, **`covering_date`**, and **`include_archived`** parameters to + * Use the **`starting_at`**, **`covering_date`**, and **`include_archived`** parameters to * filter the list of returned contracts. For example, to list only currently active contracts, - * pass **`covering_date`** equal to the current time. + * pass **`covering_date`** equal to the current time. */ fun listContractsOnPackage( params: PackageListContractsOnPackageParams diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsync.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsync.kt deleted file mode 100644 index e7b9810a..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsync.kt +++ /dev/null @@ -1,129 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.services.async.v1 - -import com.metronome.api.core.ClientOptions -import com.metronome.api.core.RequestOptions -import com.metronome.api.core.http.HttpResponseFor -import com.metronome.api.models.v1.payments.PaymentAttemptParams -import com.metronome.api.models.v1.payments.PaymentAttemptResponse -import com.metronome.api.models.v1.payments.PaymentCancelParams -import com.metronome.api.models.v1.payments.PaymentCancelResponse -import com.metronome.api.models.v1.payments.PaymentListPageAsync -import com.metronome.api.models.v1.payments.PaymentListParams -import java.util.concurrent.CompletableFuture -import java.util.function.Consumer - -interface PaymentServiceAsync { - - /** - * Returns a view of this service that provides access to raw HTTP responses for each method. - */ - fun withRawResponse(): WithRawResponse - - /** - * Returns a view of this service with the given option modifications applied. - * - * The original service is not modified. - */ - fun withOptions(modifier: Consumer): PaymentServiceAsync - - /** Fetch all payment attempts for the given invoice. */ - fun list(params: PaymentListParams): CompletableFuture = - list(params, RequestOptions.none()) - - /** @see list */ - fun list( - params: PaymentListParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture - - /** - * Trigger a new attempt by canceling any existing attempts for this invoice and creating a new - * Payment. This will trigger another attempt to charge the Customer's configured Payment - * Gateway. Payment can only be attempted if all of the following are true: - * - The Metronome Invoice is finalized - * - PLG Invoicing is configured for the Customer - * - You cannot attempt payments for invoices that have already been `paid` or `voided`. - * - * Attempting to payment on an ineligible Invoice or Customer will result in a `400` response. - */ - fun attempt(params: PaymentAttemptParams): CompletableFuture = - attempt(params, RequestOptions.none()) - - /** @see attempt */ - fun attempt( - params: PaymentAttemptParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture - - /** Cancel an existing payment attempt for an invoice. */ - fun cancel(params: PaymentCancelParams): CompletableFuture = - cancel(params, RequestOptions.none()) - - /** @see cancel */ - fun cancel( - params: PaymentCancelParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture - - /** - * A view of [PaymentServiceAsync] that provides access to raw HTTP responses for each method. - */ - interface WithRawResponse { - - /** - * Returns a view of this service with the given option modifications applied. - * - * The original service is not modified. - */ - fun withOptions( - modifier: Consumer - ): PaymentServiceAsync.WithRawResponse - - /** - * Returns a raw HTTP response for `post /v1/payments/list`, but is otherwise the same as - * [PaymentServiceAsync.list]. - */ - fun list( - params: PaymentListParams - ): CompletableFuture> = - list(params, RequestOptions.none()) - - /** @see list */ - fun list( - params: PaymentListParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture> - - /** - * Returns a raw HTTP response for `post /v1/payments/attempt`, but is otherwise the same as - * [PaymentServiceAsync.attempt]. - */ - fun attempt( - params: PaymentAttemptParams - ): CompletableFuture> = - attempt(params, RequestOptions.none()) - - /** @see attempt */ - fun attempt( - params: PaymentAttemptParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture> - - /** - * Returns a raw HTTP response for `post /v1/payments/cancel`, but is otherwise the same as - * [PaymentServiceAsync.cancel]. - */ - fun cancel( - params: PaymentCancelParams - ): CompletableFuture> = - cancel(params, RequestOptions.none()) - - /** @see cancel */ - fun cancel( - params: PaymentCancelParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture> - } -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsyncImpl.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsyncImpl.kt deleted file mode 100644 index d7379708..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsyncImpl.kt +++ /dev/null @@ -1,175 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.services.async.v1 - -import com.metronome.api.core.ClientOptions -import com.metronome.api.core.RequestOptions -import com.metronome.api.core.handlers.errorBodyHandler -import com.metronome.api.core.handlers.errorHandler -import com.metronome.api.core.handlers.jsonHandler -import com.metronome.api.core.http.HttpMethod -import com.metronome.api.core.http.HttpRequest -import com.metronome.api.core.http.HttpResponse -import com.metronome.api.core.http.HttpResponse.Handler -import com.metronome.api.core.http.HttpResponseFor -import com.metronome.api.core.http.json -import com.metronome.api.core.http.parseable -import com.metronome.api.core.prepareAsync -import com.metronome.api.models.v1.payments.PaymentAttemptParams -import com.metronome.api.models.v1.payments.PaymentAttemptResponse -import com.metronome.api.models.v1.payments.PaymentCancelParams -import com.metronome.api.models.v1.payments.PaymentCancelResponse -import com.metronome.api.models.v1.payments.PaymentListPageAsync -import com.metronome.api.models.v1.payments.PaymentListPageResponse -import com.metronome.api.models.v1.payments.PaymentListParams -import java.util.concurrent.CompletableFuture -import java.util.function.Consumer - -class PaymentServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : - PaymentServiceAsync { - - private val withRawResponse: PaymentServiceAsync.WithRawResponse by lazy { - WithRawResponseImpl(clientOptions) - } - - override fun withRawResponse(): PaymentServiceAsync.WithRawResponse = withRawResponse - - override fun withOptions(modifier: Consumer): PaymentServiceAsync = - PaymentServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) - - override fun list( - params: PaymentListParams, - requestOptions: RequestOptions, - ): CompletableFuture = - // post /v1/payments/list - withRawResponse().list(params, requestOptions).thenApply { it.parse() } - - override fun attempt( - params: PaymentAttemptParams, - requestOptions: RequestOptions, - ): CompletableFuture = - // post /v1/payments/attempt - withRawResponse().attempt(params, requestOptions).thenApply { it.parse() } - - override fun cancel( - params: PaymentCancelParams, - requestOptions: RequestOptions, - ): CompletableFuture = - // post /v1/payments/cancel - withRawResponse().cancel(params, requestOptions).thenApply { it.parse() } - - class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : - PaymentServiceAsync.WithRawResponse { - - private val errorHandler: Handler = - errorHandler(errorBodyHandler(clientOptions.jsonMapper)) - - override fun withOptions( - modifier: Consumer - ): PaymentServiceAsync.WithRawResponse = - PaymentServiceAsyncImpl.WithRawResponseImpl( - clientOptions.toBuilder().apply(modifier::accept).build() - ) - - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - - override fun list( - params: PaymentListParams, - requestOptions: RequestOptions, - ): CompletableFuture> { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .baseUrl(clientOptions.baseUrl()) - .addPathSegments("v1", "payments", "list") - .body(json(clientOptions.jsonMapper, params._body())) - .build() - .prepareAsync(clientOptions, params) - val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) - return request - .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } - .thenApply { response -> - errorHandler.handle(response).parseable { - response - .use { listHandler.handle(it) } - .also { - if (requestOptions.responseValidation!!) { - it.validate() - } - } - .let { - PaymentListPageAsync.builder() - .service(PaymentServiceAsyncImpl(clientOptions)) - .streamHandlerExecutor(clientOptions.streamHandlerExecutor) - .params(params) - .response(it) - .build() - } - } - } - } - - private val attemptHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - - override fun attempt( - params: PaymentAttemptParams, - requestOptions: RequestOptions, - ): CompletableFuture> { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .baseUrl(clientOptions.baseUrl()) - .addPathSegments("v1", "payments", "attempt") - .body(json(clientOptions.jsonMapper, params._body())) - .build() - .prepareAsync(clientOptions, params) - val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) - return request - .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } - .thenApply { response -> - errorHandler.handle(response).parseable { - response - .use { attemptHandler.handle(it) } - .also { - if (requestOptions.responseValidation!!) { - it.validate() - } - } - } - } - } - - private val cancelHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - - override fun cancel( - params: PaymentCancelParams, - requestOptions: RequestOptions, - ): CompletableFuture> { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .baseUrl(clientOptions.baseUrl()) - .addPathSegments("v1", "payments", "cancel") - .body(json(clientOptions.jsonMapper, params._body())) - .build() - .prepareAsync(clientOptions, params) - val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) - return request - .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } - .thenApply { response -> - errorHandler.handle(response).parseable { - response - .use { cancelHandler.handle(it) } - .also { - if (requestOptions.responseValidation!!) { - it.validate() - } - } - } - } - } - } -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/V1Service.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/V1Service.kt index fefc3ece..0c4816d1 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/V1Service.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/V1Service.kt @@ -13,7 +13,6 @@ import com.metronome.api.services.blocking.v1.CustomerService import com.metronome.api.services.blocking.v1.DashboardService import com.metronome.api.services.blocking.v1.InvoiceService import com.metronome.api.services.blocking.v1.PackageService -import com.metronome.api.services.blocking.v1.PaymentService import com.metronome.api.services.blocking.v1.PlanService import com.metronome.api.services.blocking.v1.PricingUnitService import com.metronome.api.services.blocking.v1.ServiceService @@ -118,8 +117,6 @@ interface V1Service { fun packages(): PackageService - fun payments(): PaymentService - /** * Use these endpoints to configure a billing API key, a webhook secret, or invoice finalization * behavior. @@ -220,8 +217,6 @@ interface V1Service { fun packages(): PackageService.WithRawResponse - fun payments(): PaymentService.WithRawResponse - /** * Use these endpoints to configure a billing API key, a webhook secret, or invoice * finalization behavior. diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/V1ServiceImpl.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/V1ServiceImpl.kt index ba8e329e..13b8a2e4 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/V1ServiceImpl.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/V1ServiceImpl.kt @@ -23,8 +23,6 @@ import com.metronome.api.services.blocking.v1.InvoiceService import com.metronome.api.services.blocking.v1.InvoiceServiceImpl import com.metronome.api.services.blocking.v1.PackageService import com.metronome.api.services.blocking.v1.PackageServiceImpl -import com.metronome.api.services.blocking.v1.PaymentService -import com.metronome.api.services.blocking.v1.PaymentServiceImpl import com.metronome.api.services.blocking.v1.PlanService import com.metronome.api.services.blocking.v1.PlanServiceImpl import com.metronome.api.services.blocking.v1.PricingUnitService @@ -73,8 +71,6 @@ class V1ServiceImpl internal constructor(private val clientOptions: ClientOption private val packages: PackageService by lazy { PackageServiceImpl(clientOptions) } - private val payments: PaymentService by lazy { PaymentServiceImpl(clientOptions) } - private val settings: SettingService by lazy { SettingServiceImpl(clientOptions) } override fun withRawResponse(): V1Service.WithRawResponse = withRawResponse @@ -165,8 +161,6 @@ class V1ServiceImpl internal constructor(private val clientOptions: ClientOption override fun packages(): PackageService = packages - override fun payments(): PaymentService = payments - /** * Use these endpoints to configure a billing API key, a webhook secret, or invoice finalization * behavior. @@ -232,10 +226,6 @@ class V1ServiceImpl internal constructor(private val clientOptions: ClientOption PackageServiceImpl.WithRawResponseImpl(clientOptions) } - private val payments: PaymentService.WithRawResponse by lazy { - PaymentServiceImpl.WithRawResponseImpl(clientOptions) - } - private val settings: SettingService.WithRawResponse by lazy { SettingServiceImpl.WithRawResponseImpl(clientOptions) } @@ -331,8 +321,6 @@ class V1ServiceImpl internal constructor(private val clientOptions: ClientOption override fun packages(): PackageService.WithRawResponse = packages - override fun payments(): PaymentService.WithRawResponse = payments - /** * Use these endpoints to configure a billing API key, a webhook secret, or invoice * finalization behavior. diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PackageService.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PackageService.kt index f5ec9ef7..f887945b 100644 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PackageService.kt +++ b/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PackageService.kt @@ -144,9 +144,9 @@ interface PackageService { * package. * * ### **Usage guidelines:** - * Use the **`starting_at`**, **`covering_date`**, and **`include_archived`** parameters to + * Use the **`starting_at`**, **`covering_date`**, and **`include_archived`** parameters to * filter the list of returned contracts. For example, to list only currently active contracts, - * pass **`covering_date`** equal to the current time. + * pass **`covering_date`** equal to the current time. */ fun listContractsOnPackage( params: PackageListContractsOnPackageParams diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PaymentService.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PaymentService.kt deleted file mode 100644 index 99457ec4..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PaymentService.kt +++ /dev/null @@ -1,124 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.services.blocking.v1 - -import com.google.errorprone.annotations.MustBeClosed -import com.metronome.api.core.ClientOptions -import com.metronome.api.core.RequestOptions -import com.metronome.api.core.http.HttpResponseFor -import com.metronome.api.models.v1.payments.PaymentAttemptParams -import com.metronome.api.models.v1.payments.PaymentAttemptResponse -import com.metronome.api.models.v1.payments.PaymentCancelParams -import com.metronome.api.models.v1.payments.PaymentCancelResponse -import com.metronome.api.models.v1.payments.PaymentListPage -import com.metronome.api.models.v1.payments.PaymentListParams -import java.util.function.Consumer - -interface PaymentService { - - /** - * Returns a view of this service that provides access to raw HTTP responses for each method. - */ - fun withRawResponse(): WithRawResponse - - /** - * Returns a view of this service with the given option modifications applied. - * - * The original service is not modified. - */ - fun withOptions(modifier: Consumer): PaymentService - - /** Fetch all payment attempts for the given invoice. */ - fun list(params: PaymentListParams): PaymentListPage = list(params, RequestOptions.none()) - - /** @see list */ - fun list( - params: PaymentListParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): PaymentListPage - - /** - * Trigger a new attempt by canceling any existing attempts for this invoice and creating a new - * Payment. This will trigger another attempt to charge the Customer's configured Payment - * Gateway. Payment can only be attempted if all of the following are true: - * - The Metronome Invoice is finalized - * - PLG Invoicing is configured for the Customer - * - You cannot attempt payments for invoices that have already been `paid` or `voided`. - * - * Attempting to payment on an ineligible Invoice or Customer will result in a `400` response. - */ - fun attempt(params: PaymentAttemptParams): PaymentAttemptResponse = - attempt(params, RequestOptions.none()) - - /** @see attempt */ - fun attempt( - params: PaymentAttemptParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): PaymentAttemptResponse - - /** Cancel an existing payment attempt for an invoice. */ - fun cancel(params: PaymentCancelParams): PaymentCancelResponse = - cancel(params, RequestOptions.none()) - - /** @see cancel */ - fun cancel( - params: PaymentCancelParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): PaymentCancelResponse - - /** A view of [PaymentService] that provides access to raw HTTP responses for each method. */ - interface WithRawResponse { - - /** - * Returns a view of this service with the given option modifications applied. - * - * The original service is not modified. - */ - fun withOptions(modifier: Consumer): PaymentService.WithRawResponse - - /** - * Returns a raw HTTP response for `post /v1/payments/list`, but is otherwise the same as - * [PaymentService.list]. - */ - @MustBeClosed - fun list(params: PaymentListParams): HttpResponseFor = - list(params, RequestOptions.none()) - - /** @see list */ - @MustBeClosed - fun list( - params: PaymentListParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): HttpResponseFor - - /** - * Returns a raw HTTP response for `post /v1/payments/attempt`, but is otherwise the same as - * [PaymentService.attempt]. - */ - @MustBeClosed - fun attempt(params: PaymentAttemptParams): HttpResponseFor = - attempt(params, RequestOptions.none()) - - /** @see attempt */ - @MustBeClosed - fun attempt( - params: PaymentAttemptParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): HttpResponseFor - - /** - * Returns a raw HTTP response for `post /v1/payments/cancel`, but is otherwise the same as - * [PaymentService.cancel]. - */ - @MustBeClosed - fun cancel(params: PaymentCancelParams): HttpResponseFor = - cancel(params, RequestOptions.none()) - - /** @see cancel */ - @MustBeClosed - fun cancel( - params: PaymentCancelParams, - requestOptions: RequestOptions = RequestOptions.none(), - ): HttpResponseFor - } -} diff --git a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PaymentServiceImpl.kt b/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PaymentServiceImpl.kt deleted file mode 100644 index c4e9da11..00000000 --- a/metronome-java-core/src/main/kotlin/com/metronome/api/services/blocking/v1/PaymentServiceImpl.kt +++ /dev/null @@ -1,161 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.services.blocking.v1 - -import com.metronome.api.core.ClientOptions -import com.metronome.api.core.RequestOptions -import com.metronome.api.core.handlers.errorBodyHandler -import com.metronome.api.core.handlers.errorHandler -import com.metronome.api.core.handlers.jsonHandler -import com.metronome.api.core.http.HttpMethod -import com.metronome.api.core.http.HttpRequest -import com.metronome.api.core.http.HttpResponse -import com.metronome.api.core.http.HttpResponse.Handler -import com.metronome.api.core.http.HttpResponseFor -import com.metronome.api.core.http.json -import com.metronome.api.core.http.parseable -import com.metronome.api.core.prepare -import com.metronome.api.models.v1.payments.PaymentAttemptParams -import com.metronome.api.models.v1.payments.PaymentAttemptResponse -import com.metronome.api.models.v1.payments.PaymentCancelParams -import com.metronome.api.models.v1.payments.PaymentCancelResponse -import com.metronome.api.models.v1.payments.PaymentListPage -import com.metronome.api.models.v1.payments.PaymentListPageResponse -import com.metronome.api.models.v1.payments.PaymentListParams -import java.util.function.Consumer - -class PaymentServiceImpl internal constructor(private val clientOptions: ClientOptions) : - PaymentService { - - private val withRawResponse: PaymentService.WithRawResponse by lazy { - WithRawResponseImpl(clientOptions) - } - - override fun withRawResponse(): PaymentService.WithRawResponse = withRawResponse - - override fun withOptions(modifier: Consumer): PaymentService = - PaymentServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) - - override fun list(params: PaymentListParams, requestOptions: RequestOptions): PaymentListPage = - // post /v1/payments/list - withRawResponse().list(params, requestOptions).parse() - - override fun attempt( - params: PaymentAttemptParams, - requestOptions: RequestOptions, - ): PaymentAttemptResponse = - // post /v1/payments/attempt - withRawResponse().attempt(params, requestOptions).parse() - - override fun cancel( - params: PaymentCancelParams, - requestOptions: RequestOptions, - ): PaymentCancelResponse = - // post /v1/payments/cancel - withRawResponse().cancel(params, requestOptions).parse() - - class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : - PaymentService.WithRawResponse { - - private val errorHandler: Handler = - errorHandler(errorBodyHandler(clientOptions.jsonMapper)) - - override fun withOptions( - modifier: Consumer - ): PaymentService.WithRawResponse = - PaymentServiceImpl.WithRawResponseImpl( - clientOptions.toBuilder().apply(modifier::accept).build() - ) - - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - - override fun list( - params: PaymentListParams, - requestOptions: RequestOptions, - ): HttpResponseFor { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .baseUrl(clientOptions.baseUrl()) - .addPathSegments("v1", "payments", "list") - .body(json(clientOptions.jsonMapper, params._body())) - .build() - .prepare(clientOptions, params) - val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) - val response = clientOptions.httpClient.execute(request, requestOptions) - return errorHandler.handle(response).parseable { - response - .use { listHandler.handle(it) } - .also { - if (requestOptions.responseValidation!!) { - it.validate() - } - } - .let { - PaymentListPage.builder() - .service(PaymentServiceImpl(clientOptions)) - .params(params) - .response(it) - .build() - } - } - } - - private val attemptHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - - override fun attempt( - params: PaymentAttemptParams, - requestOptions: RequestOptions, - ): HttpResponseFor { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .baseUrl(clientOptions.baseUrl()) - .addPathSegments("v1", "payments", "attempt") - .body(json(clientOptions.jsonMapper, params._body())) - .build() - .prepare(clientOptions, params) - val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) - val response = clientOptions.httpClient.execute(request, requestOptions) - return errorHandler.handle(response).parseable { - response - .use { attemptHandler.handle(it) } - .also { - if (requestOptions.responseValidation!!) { - it.validate() - } - } - } - } - - private val cancelHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - - override fun cancel( - params: PaymentCancelParams, - requestOptions: RequestOptions, - ): HttpResponseFor { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .baseUrl(clientOptions.baseUrl()) - .addPathSegments("v1", "payments", "cancel") - .body(json(clientOptions.jsonMapper, params._body())) - .build() - .prepare(clientOptions, params) - val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) - val response = clientOptions.httpClient.execute(request, requestOptions) - return errorHandler.handle(response).parseable { - response - .use { cancelHandler.handle(it) } - .also { - if (requestOptions.responseValidation!!) { - it.validate() - } - } - } - } - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/CommitTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/CommitTest.kt index 126a73bf..d5ed64fe 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/CommitTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/CommitTest.kt @@ -139,6 +139,9 @@ internal class CommitTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -286,6 +289,8 @@ internal class CommitTest { .addProductTag("string") .build() ) + assertThat(commit.spendTrackerAttributes()) + .contains(Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build()) assertThat(commit.subscriptionConfig()) .contains( Commit.SubscriptionConfig.builder() @@ -429,6 +434,9 @@ internal class CommitTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractTest.kt index 1efcc6c4..68432c2c 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractTest.kt @@ -160,6 +160,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -654,6 +659,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -1089,6 +1099,45 @@ internal class ContractTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1393,6 +1442,58 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -1574,6 +1675,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -2009,6 +2115,45 @@ internal class ContractTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2313,6 +2458,58 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -2445,6 +2642,41 @@ internal class ContractTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2492,6 +2724,43 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier.Discounted.ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() @@ -2720,6 +2989,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -3191,6 +3465,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -3600,6 +3879,44 @@ internal class ContractTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -3886,6 +4203,56 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -4056,6 +4423,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -4465,6 +4837,44 @@ internal class ContractTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -4751,6 +5161,56 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -4869,6 +5329,41 @@ internal class ContractTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -4913,6 +5408,42 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + assertThat(contract.spendTrackers().getOrNull()) + .containsExactly( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier.Discounted.ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() @@ -5140,6 +5671,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -5634,6 +6170,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -6069,6 +6610,45 @@ internal class ContractTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -6373,6 +6953,58 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -6554,6 +7186,11 @@ internal class ContractTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -6989,6 +7626,45 @@ internal class ContractTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -7293,6 +7969,58 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -7425,6 +8153,41 @@ internal class ContractTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -7472,6 +8235,43 @@ internal class ContractTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier.Discounted.ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractV2Test.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractV2Test.kt index 199e6f04..a67a48fc 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractV2Test.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractV2Test.kt @@ -149,6 +149,11 @@ internal class ContractV2Test { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation(RecurringCommitSubscriptionConfig.Allocation.INDIVIDUAL) @@ -573,6 +578,42 @@ internal class ContractV2Test { .discountConfiguration( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -839,6 +880,44 @@ internal class ContractV2Test { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Discounted.ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() @@ -1064,6 +1143,11 @@ internal class ContractV2Test { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation(RecurringCommitSubscriptionConfig.Allocation.INDIVIDUAL) @@ -1488,6 +1572,41 @@ internal class ContractV2Test { .discountConfiguration( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1754,6 +1873,42 @@ internal class ContractV2Test { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + assertThat(contractV2.spendTrackers().getOrNull()) + .containsExactly( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Discounted.ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() @@ -1975,6 +2130,11 @@ internal class ContractV2Test { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation(RecurringCommitSubscriptionConfig.Allocation.INDIVIDUAL) @@ -2399,6 +2559,42 @@ internal class ContractV2Test { .discountConfiguration( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2665,6 +2861,44 @@ internal class ContractV2Test { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Discounted.ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractWithoutAmendmentsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractWithoutAmendmentsTest.kt index 8e0113d6..34d0e98e 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractWithoutAmendmentsTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/ContractWithoutAmendmentsTest.kt @@ -148,6 +148,9 @@ internal class ContractWithoutAmendmentsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -547,6 +550,41 @@ internal class ContractWithoutAmendmentsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -818,6 +856,50 @@ internal class ContractWithoutAmendmentsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() @@ -977,6 +1059,9 @@ internal class ContractWithoutAmendmentsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -1369,6 +1454,41 @@ internal class ContractWithoutAmendmentsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1639,6 +1759,48 @@ internal class ContractWithoutAmendmentsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + assertThat(contractWithoutAmendments.spendTrackers().getOrNull()) + .containsExactly( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() @@ -1809,6 +1971,9 @@ internal class ContractWithoutAmendmentsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -2208,6 +2373,41 @@ internal class ContractWithoutAmendmentsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2479,6 +2679,50 @@ internal class ContractWithoutAmendmentsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationTest.kt index 8e0a6321..aa17b14b 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationTest.kt @@ -5,6 +5,7 @@ package com.metronome.api.models import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.metronome.api.core.JsonValue import com.metronome.api.core.jsonMapper +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -69,6 +70,38 @@ internal class PrepaidBalanceThresholdConfigurationTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -132,6 +165,39 @@ internal class PrepaidBalanceThresholdConfigurationTest { .contains( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + assertThat(prepaidBalanceThresholdConfiguration.thresholdBalanceSpecifiers().getOrNull()) + .containsExactly( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) } @@ -196,6 +262,38 @@ internal class PrepaidBalanceThresholdConfigurationTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationV2Test.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationV2Test.kt index cbd6740b..8abdc3dd 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationV2Test.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/PrepaidBalanceThresholdConfigurationV2Test.kt @@ -5,6 +5,7 @@ package com.metronome.api.models import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.metronome.api.core.JsonValue import com.metronome.api.core.jsonMapper +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -69,6 +70,39 @@ internal class PrepaidBalanceThresholdConfigurationV2Test { .discountConfiguration( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -132,6 +166,39 @@ internal class PrepaidBalanceThresholdConfigurationV2Test { .contains( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + assertThat(prepaidBalanceThresholdConfigurationV2.thresholdBalanceSpecifiers().getOrNull()) + .containsExactly( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) } @@ -196,6 +263,39 @@ internal class PrepaidBalanceThresholdConfigurationV2Test { .discountConfiguration( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/SpendThresholdConfigurationTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/SpendThresholdConfigurationTest.kt index f906eca9..e6ebc924 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/SpendThresholdConfigurationTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/SpendThresholdConfigurationTest.kt @@ -49,6 +49,12 @@ internal class SpendThresholdConfigurationTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() @@ -91,6 +97,12 @@ internal class SpendThresholdConfigurationTest { .contains( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) } @@ -135,6 +147,12 @@ internal class SpendThresholdConfigurationTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/SpendThresholdConfigurationV2Test.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/SpendThresholdConfigurationV2Test.kt index 28c679e4..b730cf71 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/SpendThresholdConfigurationV2Test.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/SpendThresholdConfigurationV2Test.kt @@ -49,6 +49,12 @@ internal class SpendThresholdConfigurationV2Test { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() @@ -91,6 +97,12 @@ internal class SpendThresholdConfigurationV2Test { .contains( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) } @@ -135,6 +147,12 @@ internal class SpendThresholdConfigurationV2Test { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractAmendParamsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractAmendParamsTest.kt index 4c9f86e1..34007da7 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractAmendParamsTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractAmendParamsTest.kt @@ -114,6 +114,11 @@ internal class ContractAmendParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractAmendParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -502,6 +507,11 @@ internal class ContractAmendParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractAmendParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -892,6 +902,11 @@ internal class ContractAmendParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractAmendParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractCreateParamsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractCreateParamsTest.kt index c6987e74..2ee73de5 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractCreateParamsTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractCreateParamsTest.kt @@ -132,6 +132,11 @@ internal class ContractCreateParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -402,6 +407,41 @@ internal class ContractCreateParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -716,8 +756,38 @@ internal class ContractCreateParamsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD) .build() ) .addSubscription( @@ -925,6 +995,11 @@ internal class ContractCreateParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -1217,6 +1292,41 @@ internal class ContractCreateParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1547,8 +1657,42 @@ internal class ContractCreateParamsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -1749,6 +1893,11 @@ internal class ContractCreateParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -2024,6 +2173,41 @@ internal class ContractCreateParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2344,8 +2528,39 @@ internal class ContractCreateParamsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + assertThat(body.spendTrackers().getOrNull()) + .containsExactly( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD) .build() ) assertThat(body.subscriptions().getOrNull()) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractCreateResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractCreateResponseTest.kt index 87a244f6..9c16ce9c 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractCreateResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractCreateResponseTest.kt @@ -3,8 +3,28 @@ package com.metronome.api.models.v1.contracts import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.metronome.api.core.JsonValue import com.metronome.api.core.jsonMapper -import com.metronome.api.models.Id +import com.metronome.api.models.BaseThresholdCommit +import com.metronome.api.models.Commit +import com.metronome.api.models.CommitHierarchyConfiguration +import com.metronome.api.models.CommitSpecifier +import com.metronome.api.models.CommitSpecifierInput +import com.metronome.api.models.Credit +import com.metronome.api.models.CreditTypeData +import com.metronome.api.models.HierarchyConfiguration +import com.metronome.api.models.Override +import com.metronome.api.models.OverrideTier +import com.metronome.api.models.OverwriteRate +import com.metronome.api.models.PaymentGateConfig +import com.metronome.api.models.PrepaidBalanceThresholdConfiguration +import com.metronome.api.models.RecurringCommitSubscriptionConfig +import com.metronome.api.models.ScheduleDuration +import com.metronome.api.models.SchedulePointInTime +import com.metronome.api.models.ScheduledCharge +import com.metronome.api.models.SpendThresholdConfiguration +import com.metronome.api.models.Subscription +import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -14,11 +34,2283 @@ internal class ContractCreateResponseTest { fun create() { val contractCreateResponse = ContractCreateResponse.builder() - .data(Id.builder().id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build()) + .data( + ContractCreateResponse.Data.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .contract( + ContractCreateResponse.Data.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addCommit( + Commit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .product( + Commit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(Commit.Type.PREPAID) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .amount(0.0) + .addApplicableContractId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .archivedAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .balance(0.0) + .contract( + Commit.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .customFields( + Commit.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceContract( + Commit.InvoiceContract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .invoiceSchedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addLedger( + Commit.Ledger.PrepaidCommitSegmentStartLedgerEntry + .builder() + .amount(0.0) + .segmentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .type( + Commit.Ledger + .PrepaidCommitSegmentStartLedgerEntry + .Type + .PREPAID_COMMIT_SEGMENT_START + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType(Commit.RateType.COMMIT_RATE) + .recurringCommitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rolledOverFrom( + Commit.RolledOverFrom.builder() + .commitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) + .subscriptionConfig( + Commit.SubscriptionConfig.builder() + .allocation( + Commit.SubscriptionConfig.Allocation.INDIVIDUAL + ) + .applySeatIncreaseConfig( + Commit.SubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdBy("created_by") + .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addOverride( + Override.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductTag("string") + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .entitled(true) + .isCommitSpecific(true) + .isProrated(true) + .multiplier(0.0) + .addOverrideSpecifier( + Override.OverrideSpecifier.builder() + .billingFrequency( + Override.OverrideSpecifier.BillingFrequency + .MONTHLY + ) + .addCommitId("string") + .presentationGroupValues( + Override.OverrideSpecifier + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + Override.OverrideSpecifier.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .addRecurringCommitId("string") + .build() + ) + .addOverrideTier( + OverrideTier.builder().multiplier(0.0).size(0.0).build() + ) + .overwriteRate( + OverwriteRate.builder() + .rateType(OverwriteRate.RateType.FLAT) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .customRate( + OverwriteRate.CustomRate.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) + .isProrated(true) + .price(0.0) + .quantity(0.0) + .addTier( + OverwriteRate.Tier.builder() + .price(0.0) + .size(0.0) + .build() + ) + .build() + ) + .price(0.0) + .priority(0.0) + .product( + Override.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .quantity(0.0) + .rateType(Override.RateType.FLAT) + .target(Override.Target.COMMIT_RATE) + .addTier( + Override.Tier.builder().price(0.0).size(0.0).build() + ) + .type(Override.Type.OVERWRITE) + .value( + Override.Value.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .addScheduledCharge( + ScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ScheduledCharge.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .archivedAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .customFields( + ScheduledCharge.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addTransition( + ContractCreateResponse.Data.Contract.Transition.builder() + .fromContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .toContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .type( + ContractCreateResponse.Data.Contract.Transition.Type + .SUPERSEDE + ) + .build() + ) + .addUsageFilter( + ContractCreateResponse.Data.Contract.UsageFilter.builder() + .groupKey("group_key") + .addGroupValue("string") + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .usageStatementSchedule( + ContractCreateResponse.Data.Contract.UsageStatementSchedule + .builder() + .billingAnchorDate( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .frequency( + ContractCreateResponse.Data.Contract + .UsageStatementSchedule + .Frequency + .MONTHLY + ) + .build() + ) + .addCredit( + Credit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + Credit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(Credit.Type.CREDIT) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableContractId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .balance(0.0) + .contract( + Credit.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .customFields( + Credit.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .addLedger( + Credit.Ledger.CreditSegmentStartLedgerEntry.builder() + .amount(0.0) + .segmentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .type( + Credit.Ledger.CreditSegmentStartLedgerEntry.Type + .CREDIT_SEGMENT_START + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType(Credit.RateType.COMMIT_RATE) + .recurringCreditId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rolledOverFrom( + Credit.RolledOverFrom.builder() + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .creditId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + Credit.SubscriptionConfig.builder() + .allocation( + Credit.SubscriptionConfig.Allocation.INDIVIDUAL + ) + .applySeatIncreaseConfig( + Credit.SubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .customFields( + ContractCreateResponse.Data.Contract.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .customerBillingProviderConfiguration( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .billingProvider( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .BillingProvider + .AWS_MARKETPLACE + ) + .deliveryMethod( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .DeliveryMethod + .DIRECT_TO_BILLING_PROVIDER + ) + .build() + ) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hasMore( + ContractCreateResponse.Data.Contract.HasMore.builder() + .commits(true) + .credits(true) + .build() + ) + .hierarchyConfiguration( + HierarchyConfiguration.ParentHierarchyConfiguration.builder() + .addChild( + HierarchyConfiguration.ParentHierarchyConfiguration + .Child + .builder() + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .parentBehavior( + HierarchyConfiguration.ParentHierarchyConfiguration + .ParentBehavior + .builder() + .invoiceConsolidationType( + HierarchyConfiguration + .ParentHierarchyConfiguration + .ParentBehavior + .InvoiceConsolidationType + .CONCATENATE + ) + .build() + ) + .build() + ) + .multiplierOverridePrioritization( + ContractCreateResponse.Data.Contract + .MultiplierOverridePrioritization + .LOWEST_MULTIPLIER + ) + .name("name") + .netPaymentTermsDays(0.0) + .packageId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .prepaidBalanceThresholdConfiguration( + PrepaidBalanceThresholdConfiguration.builder() + .commit( + PrepaidBalanceThresholdConfiguration.Commit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfig.builder() + .paymentGateType( + PaymentGateConfig.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfig.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfig.StripeConfig.builder() + .paymentType( + PaymentGateConfig.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfig.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfig.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .rateCardId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addRecurringCommit( + ContractCreateResponse.Data.Contract.RecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractCreateResponse.Data.Contract.RecurringCommit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractCreateResponse.Data.Contract.RecurringCommit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractCreateResponse.Data.Contract + .RecurringCommit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractCreateResponse.Data.Contract.RecurringCommit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractCreateResponse.Data.Contract.RecurringCommit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractCreateResponse.Data.Contract.RecurringCommit + .InnerContract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceAmount( + ContractCreateResponse.Data.Contract.RecurringCommit + .InvoiceAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractCreateResponse.Data.Contract.RecurringCommit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractCreateResponse.Data.Contract.RecurringCommit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addRecurringCredit( + ContractCreateResponse.Data.Contract.RecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractCreateResponse.Data.Contract.RecurringCredit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractCreateResponse.Data.Contract.RecurringCredit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractCreateResponse.Data.Contract + .RecurringCredit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractCreateResponse.Data.Contract.RecurringCredit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractCreateResponse.Data.Contract.RecurringCredit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractCreateResponse.Data.Contract.RecurringCredit + .InnerContract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractCreateResponse.Data.Contract.RecurringCredit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractCreateResponse.Data.Contract.RecurringCredit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .scheduledChargesOnUsageInvoices( + ContractCreateResponse.Data.Contract + .ScheduledChargesOnUsageInvoices + .ALL + ) + .spendThresholdConfiguration( + SpendThresholdConfiguration.builder() + .commit( + BaseThresholdCommit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfig.builder() + .paymentGateType( + PaymentGateConfig.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfig.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfig.StripeConfig.builder() + .paymentType( + PaymentGateConfig.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfig.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfig.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .discountConfiguration( + SpendThresholdConfiguration.DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSubscription( + Subscription.builder() + .billingPeriods( + Subscription.BillingPeriods.builder() + .current( + Subscription.BillingPeriods.Current.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .next( + Subscription.BillingPeriods.Next.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .previous( + Subscription.BillingPeriods.Previous.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .collectionSchedule(Subscription.CollectionSchedule.ADVANCE) + .proration( + Subscription.Proration.builder() + .invoiceBehavior( + Subscription.Proration.InvoiceBehavior + .BILL_IMMEDIATELY + ) + .isProrated(true) + .build() + ) + .quantityManagementMode( + Subscription.QuantityManagementMode.SEAT_BASED + ) + .addQuantitySchedule( + Subscription.QuantitySchedule.builder() + .quantity(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .subscriptionRate( + Subscription.SubscriptionRate.builder() + .billingFrequency( + Subscription.SubscriptionRate.BillingFrequency + .MONTHLY + ) + .product( + Subscription.SubscriptionRate.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + Subscription.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .fiatCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .seatConfig( + Subscription.SeatConfig.builder() + .seatGroupKey("seat_group_key") + .build() + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .build() + ) .build() assertThat(contractCreateResponse.data()) - .isEqualTo(Id.builder().id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build()) + .isEqualTo( + ContractCreateResponse.Data.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .contract( + ContractCreateResponse.Data.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addCommit( + Commit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .product( + Commit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(Commit.Type.PREPAID) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .amount(0.0) + .addApplicableContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .balance(0.0) + .contract( + Commit.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .customFields( + Commit.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceContract( + Commit.InvoiceContract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .invoiceSchedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addLedger( + Commit.Ledger.PrepaidCommitSegmentStartLedgerEntry.builder() + .amount(0.0) + .segmentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .type( + Commit.Ledger.PrepaidCommitSegmentStartLedgerEntry + .Type + .PREPAID_COMMIT_SEGMENT_START + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType(Commit.RateType.COMMIT_RATE) + .recurringCommitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rolledOverFrom( + Commit.RolledOverFrom.builder() + .commitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) + .subscriptionConfig( + Commit.SubscriptionConfig.builder() + .allocation( + Commit.SubscriptionConfig.Allocation.INDIVIDUAL + ) + .applySeatIncreaseConfig( + Commit.SubscriptionConfig.ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .uniquenessKey("x") + .build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdBy("created_by") + .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addOverride( + Override.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addApplicableProductTag("string") + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .entitled(true) + .isCommitSpecific(true) + .isProrated(true) + .multiplier(0.0) + .addOverrideSpecifier( + Override.OverrideSpecifier.builder() + .billingFrequency( + Override.OverrideSpecifier.BillingFrequency.MONTHLY + ) + .addCommitId("string") + .presentationGroupValues( + Override.OverrideSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + Override.OverrideSpecifier.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .addRecurringCommitId("string") + .build() + ) + .addOverrideTier( + OverrideTier.builder().multiplier(0.0).size(0.0).build() + ) + .overwriteRate( + OverwriteRate.builder() + .rateType(OverwriteRate.RateType.FLAT) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .customRate( + OverwriteRate.CustomRate.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) + .isProrated(true) + .price(0.0) + .quantity(0.0) + .addTier( + OverwriteRate.Tier.builder() + .price(0.0) + .size(0.0) + .build() + ) + .build() + ) + .price(0.0) + .priority(0.0) + .product( + Override.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .quantity(0.0) + .rateType(Override.RateType.FLAT) + .target(Override.Target.COMMIT_RATE) + .addTier(Override.Tier.builder().price(0.0).size(0.0).build()) + .type(Override.Type.OVERWRITE) + .value( + Override.Value.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .addScheduledCharge( + ScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ScheduledCharge.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .customFields( + ScheduledCharge.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addTransition( + ContractCreateResponse.Data.Contract.Transition.builder() + .fromContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .toContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .type( + ContractCreateResponse.Data.Contract.Transition.Type + .SUPERSEDE + ) + .build() + ) + .addUsageFilter( + ContractCreateResponse.Data.Contract.UsageFilter.builder() + .groupKey("group_key") + .addGroupValue("string") + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .usageStatementSchedule( + ContractCreateResponse.Data.Contract.UsageStatementSchedule + .builder() + .billingAnchorDate( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .frequency( + ContractCreateResponse.Data.Contract.UsageStatementSchedule + .Frequency + .MONTHLY + ) + .build() + ) + .addCredit( + Credit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + Credit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(Credit.Type.CREDIT) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .balance(0.0) + .contract( + Credit.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .customFields( + Credit.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .addLedger( + Credit.Ledger.CreditSegmentStartLedgerEntry.builder() + .amount(0.0) + .segmentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .type( + Credit.Ledger.CreditSegmentStartLedgerEntry.Type + .CREDIT_SEGMENT_START + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType(Credit.RateType.COMMIT_RATE) + .recurringCreditId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rolledOverFrom( + Credit.RolledOverFrom.builder() + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .creditId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + Credit.SubscriptionConfig.builder() + .allocation( + Credit.SubscriptionConfig.Allocation.INDIVIDUAL + ) + .applySeatIncreaseConfig( + Credit.SubscriptionConfig.ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .uniquenessKey("x") + .build() + ) + .customFields( + ContractCreateResponse.Data.Contract.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .customerBillingProviderConfiguration( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .billingProvider( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .BillingProvider + .AWS_MARKETPLACE + ) + .deliveryMethod( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .DeliveryMethod + .DIRECT_TO_BILLING_PROVIDER + ) + .build() + ) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hasMore( + ContractCreateResponse.Data.Contract.HasMore.builder() + .commits(true) + .credits(true) + .build() + ) + .hierarchyConfiguration( + HierarchyConfiguration.ParentHierarchyConfiguration.builder() + .addChild( + HierarchyConfiguration.ParentHierarchyConfiguration.Child + .builder() + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .parentBehavior( + HierarchyConfiguration.ParentHierarchyConfiguration + .ParentBehavior + .builder() + .invoiceConsolidationType( + HierarchyConfiguration.ParentHierarchyConfiguration + .ParentBehavior + .InvoiceConsolidationType + .CONCATENATE + ) + .build() + ) + .build() + ) + .multiplierOverridePrioritization( + ContractCreateResponse.Data.Contract + .MultiplierOverridePrioritization + .LOWEST_MULTIPLIER + ) + .name("name") + .netPaymentTermsDays(0.0) + .packageId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .prepaidBalanceThresholdConfiguration( + PrepaidBalanceThresholdConfiguration.builder() + .commit( + PrepaidBalanceThresholdConfiguration.Commit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfig.builder() + .paymentGateType(PaymentGateConfig.PaymentGateType.NONE) + .precalculatedTaxConfig( + PaymentGateConfig.PrecalculatedTaxConfig.builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfig.StripeConfig.builder() + .paymentType( + PaymentGateConfig.StripeConfig.PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfig.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfig.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .rateCardId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addRecurringCommit( + ContractCreateResponse.Data.Contract.RecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractCreateResponse.Data.Contract.RecurringCommit + .AccessAmount + .builder() + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractCreateResponse.Data.Contract.RecurringCommit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractCreateResponse.Data.Contract.RecurringCommit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractCreateResponse.Data.Contract.RecurringCommit.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractCreateResponse.Data.Contract.RecurringCommit + .RateType + .COMMIT_RATE + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .contract( + ContractCreateResponse.Data.Contract.RecurringCommit + .InnerContract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceAmount( + ContractCreateResponse.Data.Contract.RecurringCommit + .InvoiceAmount + .builder() + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractCreateResponse.Data.Contract.RecurringCommit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractCreateResponse.Data.Contract.RecurringCommit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + ) + .addRecurringCredit( + ContractCreateResponse.Data.Contract.RecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractCreateResponse.Data.Contract.RecurringCredit + .AccessAmount + .builder() + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractCreateResponse.Data.Contract.RecurringCredit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractCreateResponse.Data.Contract.RecurringCredit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractCreateResponse.Data.Contract.RecurringCredit.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractCreateResponse.Data.Contract.RecurringCredit + .RateType + .COMMIT_RATE + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .contract( + ContractCreateResponse.Data.Contract.RecurringCredit + .InnerContract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractCreateResponse.Data.Contract.RecurringCredit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractCreateResponse.Data.Contract.RecurringCredit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + ) + .scheduledChargesOnUsageInvoices( + ContractCreateResponse.Data.Contract.ScheduledChargesOnUsageInvoices + .ALL + ) + .spendThresholdConfiguration( + SpendThresholdConfiguration.builder() + .commit( + BaseThresholdCommit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfig.builder() + .paymentGateType(PaymentGateConfig.PaymentGateType.NONE) + .precalculatedTaxConfig( + PaymentGateConfig.PrecalculatedTaxConfig.builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfig.StripeConfig.builder() + .paymentType( + PaymentGateConfig.StripeConfig.PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfig.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfig.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .discountConfiguration( + SpendThresholdConfiguration.DiscountConfiguration.builder() + .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSubscription( + Subscription.builder() + .billingPeriods( + Subscription.BillingPeriods.builder() + .current( + Subscription.BillingPeriods.Current.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .next( + Subscription.BillingPeriods.Next.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .previous( + Subscription.BillingPeriods.Previous.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .collectionSchedule(Subscription.CollectionSchedule.ADVANCE) + .proration( + Subscription.Proration.builder() + .invoiceBehavior( + Subscription.Proration.InvoiceBehavior + .BILL_IMMEDIATELY + ) + .isProrated(true) + .build() + ) + .quantityManagementMode( + Subscription.QuantityManagementMode.SEAT_BASED + ) + .addQuantitySchedule( + Subscription.QuantitySchedule.builder() + .quantity(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .subscriptionRate( + Subscription.SubscriptionRate.builder() + .billingFrequency( + Subscription.SubscriptionRate.BillingFrequency + .MONTHLY + ) + .product( + Subscription.SubscriptionRate.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + Subscription.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .description("description") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .fiatCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .seatConfig( + Subscription.SeatConfig.builder() + .seatGroupKey("seat_group_key") + .build() + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .build() + ) } @Test @@ -26,7 +2318,1190 @@ internal class ContractCreateResponseTest { val jsonMapper = jsonMapper() val contractCreateResponse = ContractCreateResponse.builder() - .data(Id.builder().id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build()) + .data( + ContractCreateResponse.Data.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .contract( + ContractCreateResponse.Data.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addCommit( + Commit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .product( + Commit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(Commit.Type.PREPAID) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .amount(0.0) + .addApplicableContractId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .archivedAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .balance(0.0) + .contract( + Commit.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .customFields( + Commit.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceContract( + Commit.InvoiceContract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .invoiceSchedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addLedger( + Commit.Ledger.PrepaidCommitSegmentStartLedgerEntry + .builder() + .amount(0.0) + .segmentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .type( + Commit.Ledger + .PrepaidCommitSegmentStartLedgerEntry + .Type + .PREPAID_COMMIT_SEGMENT_START + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType(Commit.RateType.COMMIT_RATE) + .recurringCommitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rolledOverFrom( + Commit.RolledOverFrom.builder() + .commitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) + .subscriptionConfig( + Commit.SubscriptionConfig.builder() + .allocation( + Commit.SubscriptionConfig.Allocation.INDIVIDUAL + ) + .applySeatIncreaseConfig( + Commit.SubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdBy("created_by") + .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addOverride( + Override.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductTag("string") + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .entitled(true) + .isCommitSpecific(true) + .isProrated(true) + .multiplier(0.0) + .addOverrideSpecifier( + Override.OverrideSpecifier.builder() + .billingFrequency( + Override.OverrideSpecifier.BillingFrequency + .MONTHLY + ) + .addCommitId("string") + .presentationGroupValues( + Override.OverrideSpecifier + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + Override.OverrideSpecifier.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .addRecurringCommitId("string") + .build() + ) + .addOverrideTier( + OverrideTier.builder().multiplier(0.0).size(0.0).build() + ) + .overwriteRate( + OverwriteRate.builder() + .rateType(OverwriteRate.RateType.FLAT) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .customRate( + OverwriteRate.CustomRate.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) + .isProrated(true) + .price(0.0) + .quantity(0.0) + .addTier( + OverwriteRate.Tier.builder() + .price(0.0) + .size(0.0) + .build() + ) + .build() + ) + .price(0.0) + .priority(0.0) + .product( + Override.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .quantity(0.0) + .rateType(Override.RateType.FLAT) + .target(Override.Target.COMMIT_RATE) + .addTier( + Override.Tier.builder().price(0.0).size(0.0).build() + ) + .type(Override.Type.OVERWRITE) + .value( + Override.Value.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .addScheduledCharge( + ScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ScheduledCharge.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .archivedAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .customFields( + ScheduledCharge.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addTransition( + ContractCreateResponse.Data.Contract.Transition.builder() + .fromContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .toContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .type( + ContractCreateResponse.Data.Contract.Transition.Type + .SUPERSEDE + ) + .build() + ) + .addUsageFilter( + ContractCreateResponse.Data.Contract.UsageFilter.builder() + .groupKey("group_key") + .addGroupValue("string") + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .usageStatementSchedule( + ContractCreateResponse.Data.Contract.UsageStatementSchedule + .builder() + .billingAnchorDate( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .frequency( + ContractCreateResponse.Data.Contract + .UsageStatementSchedule + .Frequency + .MONTHLY + ) + .build() + ) + .addCredit( + Credit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + Credit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(Credit.Type.CREDIT) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableContractId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .balance(0.0) + .contract( + Credit.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .customFields( + Credit.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .addLedger( + Credit.Ledger.CreditSegmentStartLedgerEntry.builder() + .amount(0.0) + .segmentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .type( + Credit.Ledger.CreditSegmentStartLedgerEntry.Type + .CREDIT_SEGMENT_START + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType(Credit.RateType.COMMIT_RATE) + .recurringCreditId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rolledOverFrom( + Credit.RolledOverFrom.builder() + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .creditId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + Credit.SubscriptionConfig.builder() + .allocation( + Credit.SubscriptionConfig.Allocation.INDIVIDUAL + ) + .applySeatIncreaseConfig( + Credit.SubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .customFields( + ContractCreateResponse.Data.Contract.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .customerBillingProviderConfiguration( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .billingProvider( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .BillingProvider + .AWS_MARKETPLACE + ) + .deliveryMethod( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .DeliveryMethod + .DIRECT_TO_BILLING_PROVIDER + ) + .build() + ) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hasMore( + ContractCreateResponse.Data.Contract.HasMore.builder() + .commits(true) + .credits(true) + .build() + ) + .hierarchyConfiguration( + HierarchyConfiguration.ParentHierarchyConfiguration.builder() + .addChild( + HierarchyConfiguration.ParentHierarchyConfiguration + .Child + .builder() + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .parentBehavior( + HierarchyConfiguration.ParentHierarchyConfiguration + .ParentBehavior + .builder() + .invoiceConsolidationType( + HierarchyConfiguration + .ParentHierarchyConfiguration + .ParentBehavior + .InvoiceConsolidationType + .CONCATENATE + ) + .build() + ) + .build() + ) + .multiplierOverridePrioritization( + ContractCreateResponse.Data.Contract + .MultiplierOverridePrioritization + .LOWEST_MULTIPLIER + ) + .name("name") + .netPaymentTermsDays(0.0) + .packageId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .prepaidBalanceThresholdConfiguration( + PrepaidBalanceThresholdConfiguration.builder() + .commit( + PrepaidBalanceThresholdConfiguration.Commit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfig.builder() + .paymentGateType( + PaymentGateConfig.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfig.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfig.StripeConfig.builder() + .paymentType( + PaymentGateConfig.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfig.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfig.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .rateCardId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addRecurringCommit( + ContractCreateResponse.Data.Contract.RecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractCreateResponse.Data.Contract.RecurringCommit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractCreateResponse.Data.Contract.RecurringCommit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractCreateResponse.Data.Contract + .RecurringCommit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractCreateResponse.Data.Contract.RecurringCommit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractCreateResponse.Data.Contract.RecurringCommit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractCreateResponse.Data.Contract.RecurringCommit + .InnerContract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceAmount( + ContractCreateResponse.Data.Contract.RecurringCommit + .InvoiceAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractCreateResponse.Data.Contract.RecurringCommit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractCreateResponse.Data.Contract.RecurringCommit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addRecurringCredit( + ContractCreateResponse.Data.Contract.RecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractCreateResponse.Data.Contract.RecurringCredit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractCreateResponse.Data.Contract.RecurringCredit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractCreateResponse.Data.Contract + .RecurringCredit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractCreateResponse.Data.Contract.RecurringCredit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractCreateResponse.Data.Contract.RecurringCredit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractCreateResponse.Data.Contract.RecurringCredit + .InnerContract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractCreateResponse.Data.Contract.RecurringCredit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractCreateResponse.Data.Contract.RecurringCredit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .scheduledChargesOnUsageInvoices( + ContractCreateResponse.Data.Contract + .ScheduledChargesOnUsageInvoices + .ALL + ) + .spendThresholdConfiguration( + SpendThresholdConfiguration.builder() + .commit( + BaseThresholdCommit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfig.builder() + .paymentGateType( + PaymentGateConfig.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfig.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfig.StripeConfig.builder() + .paymentType( + PaymentGateConfig.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfig.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfig.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .discountConfiguration( + SpendThresholdConfiguration.DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSubscription( + Subscription.builder() + .billingPeriods( + Subscription.BillingPeriods.builder() + .current( + Subscription.BillingPeriods.Current.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .next( + Subscription.BillingPeriods.Next.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .previous( + Subscription.BillingPeriods.Previous.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .collectionSchedule(Subscription.CollectionSchedule.ADVANCE) + .proration( + Subscription.Proration.builder() + .invoiceBehavior( + Subscription.Proration.InvoiceBehavior + .BILL_IMMEDIATELY + ) + .isProrated(true) + .build() + ) + .quantityManagementMode( + Subscription.QuantityManagementMode.SEAT_BASED + ) + .addQuantitySchedule( + Subscription.QuantitySchedule.builder() + .quantity(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .subscriptionRate( + Subscription.SubscriptionRate.builder() + .billingFrequency( + Subscription.SubscriptionRate.BillingFrequency + .MONTHLY + ) + .product( + Subscription.SubscriptionRate.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + Subscription.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .fiatCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .seatConfig( + Subscription.SeatConfig.builder() + .seatGroupKey("seat_group_key") + .build() + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .build() + ) .build() val roundtrippedContractCreateResponse = diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListBalancesPageResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListBalancesPageResponseTest.kt index 39c9cd69..cd1d27dc 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListBalancesPageResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListBalancesPageResponseTest.kt @@ -153,6 +153,9 @@ internal class ContractListBalancesPageResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -304,6 +307,9 @@ internal class ContractListBalancesPageResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -459,6 +465,9 @@ internal class ContractListBalancesPageResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListBalancesResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListBalancesResponseTest.kt index 63f8984c..1e667644 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListBalancesResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListBalancesResponseTest.kt @@ -149,6 +149,9 @@ internal class ContractListBalancesResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -299,6 +302,9 @@ internal class ContractListBalancesResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListResponseTest.kt index 09535a8e..e17f4eec 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractListResponseTest.kt @@ -208,6 +208,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -786,6 +791,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -1287,6 +1297,46 @@ internal class ContractListResponseTest { .DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1647,6 +1697,61 @@ internal class ContractListResponseTest { SpendThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -1851,6 +1956,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -2352,6 +2462,46 @@ internal class ContractListResponseTest { .DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2712,6 +2862,61 @@ internal class ContractListResponseTest { SpendThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -2852,6 +3057,45 @@ internal class ContractListResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2903,6 +3147,48 @@ internal class ContractListResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -3160,6 +3446,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -3689,6 +3980,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -4151,6 +4447,46 @@ internal class ContractListResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -4470,6 +4806,60 @@ internal class ContractListResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -4662,6 +5052,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -5124,6 +5519,46 @@ internal class ContractListResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -5443,6 +5878,60 @@ internal class ContractListResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -5578,6 +6067,44 @@ internal class ContractListResponseTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -5626,6 +6153,47 @@ internal class ContractListResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier.Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -5893,6 +6461,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -6471,6 +7044,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -6972,6 +7550,46 @@ internal class ContractListResponseTest { .DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -7332,6 +7950,61 @@ internal class ContractListResponseTest { SpendThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -7536,6 +8209,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -8037,6 +8715,46 @@ internal class ContractListResponseTest { .DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -8397,6 +9115,61 @@ internal class ContractListResponseTest { SpendThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -8537,6 +9310,45 @@ internal class ContractListResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -8588,6 +9400,48 @@ internal class ContractListResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractRetrieveResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractRetrieveResponseTest.kt index 906a2cc7..814c695d 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractRetrieveResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/contracts/ContractRetrieveResponseTest.kt @@ -208,6 +208,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -786,6 +791,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -1287,6 +1297,46 @@ internal class ContractRetrieveResponseTest { .DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1647,6 +1697,61 @@ internal class ContractRetrieveResponseTest { SpendThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -1851,6 +1956,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -2352,6 +2462,46 @@ internal class ContractRetrieveResponseTest { .DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2712,6 +2862,61 @@ internal class ContractRetrieveResponseTest { SpendThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -2852,6 +3057,45 @@ internal class ContractRetrieveResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2903,6 +3147,48 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -3160,6 +3446,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -3689,6 +3980,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -4151,6 +4447,46 @@ internal class ContractRetrieveResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -4470,6 +4806,60 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -4662,6 +5052,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -5124,6 +5519,46 @@ internal class ContractRetrieveResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -5443,6 +5878,60 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -5578,6 +6067,44 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -5626,6 +6153,47 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier.Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -5893,6 +6461,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -6471,6 +7044,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -6972,6 +7550,46 @@ internal class ContractRetrieveResponseTest { .DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -7332,6 +7950,61 @@ internal class ContractRetrieveResponseTest { SpendThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -7536,6 +8209,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation( @@ -8037,6 +8715,46 @@ internal class ContractRetrieveResponseTest { .DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -8397,6 +9115,61 @@ internal class ContractRetrieveResponseTest { SpendThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractWithoutAmendments.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractWithoutAmendments.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractWithoutAmendments.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .accumulatedSpend( + ContractWithoutAmendments.SpendTracker.AccumulatedSpend + .builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -8537,6 +9310,45 @@ internal class ContractRetrieveResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -8588,6 +9400,48 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + Contract.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + Contract.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + Contract.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + Contract.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + Contract.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(Contract.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + Contract.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/customers/commits/CommitListPageResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/customers/commits/CommitListPageResponseTest.kt index 3cb1ba33..f10afcac 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/customers/commits/CommitListPageResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/customers/commits/CommitListPageResponseTest.kt @@ -153,6 +153,9 @@ internal class CommitListPageResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -297,6 +300,9 @@ internal class CommitListPageResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -451,6 +457,9 @@ internal class CommitListPageResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageCreateParamsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageCreateParamsTest.kt index 3d7e06be..14acb1f2 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageCreateParamsTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageCreateParamsTest.kt @@ -338,6 +338,41 @@ internal class PackageCreateParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -575,8 +610,37 @@ internal class PackageCreateParamsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + PackageCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(PackageCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD) .build() ) .addSubscription( @@ -991,6 +1055,41 @@ internal class PackageCreateParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1245,8 +1344,41 @@ internal class PackageCreateParamsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + PackageCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -1655,6 +1787,41 @@ internal class PackageCreateParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1895,8 +2062,38 @@ internal class PackageCreateParamsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + assertThat(body.spendTrackers().getOrNull()) + .containsExactly( + PackageCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(PackageCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD) .build() ) assertThat(body.subscriptions().getOrNull()) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageListPageResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageListPageResponseTest.kt index 10c04972..67f80980 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageListPageResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageListPageResponseTest.kt @@ -505,6 +505,45 @@ internal class PackageListPageResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -758,8 +797,47 @@ internal class PackageListPageResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + PackageListResponse.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + PackageListResponse.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageListResponse.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageListResponse.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageListResponse.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -1279,6 +1357,44 @@ internal class PackageListPageResponseTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1509,8 +1625,43 @@ internal class PackageListPageResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + PackageListResponse.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageListResponse.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -2069,6 +2220,45 @@ internal class PackageListPageResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2322,10 +2512,49 @@ internal class PackageListPageResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + PackageListResponse.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + PackageListResponse.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageListResponse.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageListResponse.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageListResponse.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( PackageListResponse.Subscription.builder() .collectionSchedule( diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageListResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageListResponseTest.kt index dc5ab97b..845cb041 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageListResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageListResponseTest.kt @@ -451,6 +451,41 @@ internal class PackageListResponseTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -676,8 +711,41 @@ internal class PackageListResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + PackageListResponse.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageListResponse.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -1167,6 +1235,41 @@ internal class PackageListResponseTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1380,10 +1483,40 @@ internal class PackageListResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + assertThat(packageListResponse.spendTrackers().getOrNull()) + .containsExactly( + PackageListResponse.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(PackageListResponse.SpendTracker.ResetFrequency.BILLING_PERIOD) + .build() + ) assertThat(packageListResponse.subscriptions().getOrNull()) .containsExactly( PackageListResponse.Subscription.builder() @@ -1877,6 +2010,41 @@ internal class PackageListResponseTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2102,10 +2270,43 @@ internal class PackageListResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + PackageListResponse.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageListResponse.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageListResponse.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( PackageListResponse.Subscription.builder() .collectionSchedule( diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageRetrieveResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageRetrieveResponseTest.kt index 51570c22..855aaaf0 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageRetrieveResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/packages/PackageRetrieveResponseTest.kt @@ -528,6 +528,45 @@ internal class PackageRetrieveResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -816,8 +855,49 @@ internal class PackageRetrieveResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + PackageRetrieveResponse.Data.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageRetrieveResponse.Data.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) .build() ) .addSubscription( @@ -1369,6 +1449,44 @@ internal class PackageRetrieveResponseTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1627,10 +1745,50 @@ internal class PackageRetrieveResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + PackageRetrieveResponse.Data.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageRetrieveResponse.Data.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageRetrieveResponse.Data.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .build() + ) .addSubscription( PackageRetrieveResponse.Data.Subscription.builder() .collectionSchedule( @@ -2216,6 +2374,45 @@ internal class PackageRetrieveResponseTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2504,10 +2701,51 @@ internal class PackageRetrieveResponseTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + PackageRetrieveResponse.Data.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .builder() + .addSource( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageRetrieveResponse.Data.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageRetrieveResponse.Data.SpendTracker.ResetFrequency + .BILLING_PERIOD + ) + .build() + ) .addSubscription( PackageRetrieveResponse.Data.Subscription.builder() .collectionSchedule( diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptParamsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptParamsTest.kt deleted file mode 100644 index f94fbaaa..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptParamsTest.kt +++ /dev/null @@ -1,31 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class PaymentAttemptParamsTest { - - @Test - fun create() { - PaymentAttemptParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - } - - @Test - fun body() { - val params = - PaymentAttemptParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - - val body = params._body() - - assertThat(body.customerId()).isEqualTo("13117714-3f05-48e5-a6e9-a66093f13b4d") - assertThat(body.invoiceId()).isEqualTo("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptResponseTest.kt deleted file mode 100644 index dca1ce96..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentAttemptResponseTest.kt +++ /dev/null @@ -1,180 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.metronome.api.core.jsonMapper -import com.metronome.api.models.CreditTypeData -import java.time.OffsetDateTime -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class PaymentAttemptResponseTest { - - @Test - fun create() { - val paymentAttemptResponse = - PaymentAttemptResponse.builder() - .data( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId( - "revenue_system_external_payment_id" - ) - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - .build() - - assertThat(paymentAttemptResponse.data()) - .isEqualTo( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId("revenue_system_external_payment_id") - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val paymentAttemptResponse = - PaymentAttemptResponse.builder() - .data( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId( - "revenue_system_external_payment_id" - ) - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - .build() - - val roundtrippedPaymentAttemptResponse = - jsonMapper.readValue( - jsonMapper.writeValueAsString(paymentAttemptResponse), - jacksonTypeRef(), - ) - - assertThat(roundtrippedPaymentAttemptResponse).isEqualTo(paymentAttemptResponse) - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentCancelParamsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentCancelParamsTest.kt deleted file mode 100644 index efa211b3..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentCancelParamsTest.kt +++ /dev/null @@ -1,31 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class PaymentCancelParamsTest { - - @Test - fun create() { - PaymentCancelParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - } - - @Test - fun body() { - val params = - PaymentCancelParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - - val body = params._body() - - assertThat(body.customerId()).isEqualTo("13117714-3f05-48e5-a6e9-a66093f13b4d") - assertThat(body.invoiceId()).isEqualTo("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentCancelResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentCancelResponseTest.kt deleted file mode 100644 index ad7dd20a..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentCancelResponseTest.kt +++ /dev/null @@ -1,180 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.metronome.api.core.jsonMapper -import com.metronome.api.models.CreditTypeData -import java.time.OffsetDateTime -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class PaymentCancelResponseTest { - - @Test - fun create() { - val paymentCancelResponse = - PaymentCancelResponse.builder() - .data( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId( - "revenue_system_external_payment_id" - ) - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - .build() - - assertThat(paymentCancelResponse.data()) - .isEqualTo( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId("revenue_system_external_payment_id") - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val paymentCancelResponse = - PaymentCancelResponse.builder() - .data( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId( - "revenue_system_external_payment_id" - ) - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - .build() - - val roundtrippedPaymentCancelResponse = - jsonMapper.readValue( - jsonMapper.writeValueAsString(paymentCancelResponse), - jacksonTypeRef(), - ) - - assertThat(roundtrippedPaymentCancelResponse).isEqualTo(paymentCancelResponse) - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentListPageResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentListPageResponseTest.kt deleted file mode 100644 index d45cf36c..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentListPageResponseTest.kt +++ /dev/null @@ -1,183 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.metronome.api.core.jsonMapper -import com.metronome.api.models.CreditTypeData -import java.time.OffsetDateTime -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class PaymentListPageResponseTest { - - @Test - fun create() { - val paymentListPageResponse = - PaymentListPageResponse.builder() - .addData( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId( - "revenue_system_external_payment_id" - ) - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - .nextPage("next_page") - .build() - - assertThat(paymentListPageResponse.data()) - .containsExactly( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId("revenue_system_external_payment_id") - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - assertThat(paymentListPageResponse.nextPage()).contains("next_page") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val paymentListPageResponse = - PaymentListPageResponse.builder() - .addData( - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId( - "revenue_system_external_payment_id" - ) - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - ) - .nextPage("next_page") - .build() - - val roundtrippedPaymentListPageResponse = - jsonMapper.readValue( - jsonMapper.writeValueAsString(paymentListPageResponse), - jacksonTypeRef(), - ) - - assertThat(roundtrippedPaymentListPageResponse).isEqualTo(paymentListPageResponse) - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentListParamsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentListParamsTest.kt deleted file mode 100644 index 53cfcc17..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentListParamsTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import kotlin.jvm.optionals.getOrNull -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class PaymentListParamsTest { - - @Test - fun create() { - PaymentListParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .limit(1L) - .nextPage("next_page") - .addStatus(PaymentStatus.PENDING) - .addStatus(PaymentStatus.REQUIRES_INTERVENTION) - .build() - } - - @Test - fun body() { - val params = - PaymentListParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .limit(1L) - .nextPage("next_page") - .addStatus(PaymentStatus.PENDING) - .addStatus(PaymentStatus.REQUIRES_INTERVENTION) - .build() - - val body = params._body() - - assertThat(body.customerId()).isEqualTo("13117714-3f05-48e5-a6e9-a66093f13b4d") - assertThat(body.invoiceId()).isEqualTo("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - assertThat(body.limit()).contains(1L) - assertThat(body.nextPage()).contains("next_page") - assertThat(body.statuses().getOrNull()) - .containsExactly(PaymentStatus.PENDING, PaymentStatus.REQUIRES_INTERVENTION) - } - - @Test - fun bodyWithoutOptionalFields() { - val params = - PaymentListParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - - val body = params._body() - - assertThat(body.customerId()).isEqualTo("13117714-3f05-48e5-a6e9-a66093f13b4d") - assertThat(body.invoiceId()).isEqualTo("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentTest.kt deleted file mode 100644 index 5156464b..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v1/payments/PaymentTest.kt +++ /dev/null @@ -1,164 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.models.v1.payments - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.metronome.api.core.jsonMapper -import com.metronome.api.models.CreditTypeData -import java.time.OffsetDateTime -import kotlin.jvm.optionals.getOrNull -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class PaymentTest { - - @Test - fun create() { - val payment = - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId("revenue_system_external_payment_id") - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - - assertThat(payment.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(payment.amount()).contains(0.0) - assertThat(payment.amountPaid()).contains(0.0) - assertThat(payment.contractId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(payment.createdAt()).contains(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - assertThat(payment.customerId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(payment.errorMessage()).contains("error_message") - assertThat(payment.fiatCreditType()) - .contains( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - assertThat(payment.invoiceId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(payment.paymentGateway()) - .contains( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - assertThat(payment.revenueSystemPayments().getOrNull()) - .containsExactly( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId("revenue_system_external_payment_id") - .build() - ) - assertThat(payment.status()).contains(PaymentStatus.PENDING) - assertThat(payment.updatedAt()).contains(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val payment = - Payment.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .amount(0.0) - .amountPaid(0.0) - .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .createdAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .errorMessage("error_message") - .fiatCreditType( - CreditTypeData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .name("name") - .build() - ) - .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .paymentGateway( - Payment.PaymentGateway.builder() - .stripe( - Payment.PaymentGateway.Stripe.builder() - .paymentIntentId("payment_intent_id") - .error( - Payment.PaymentGateway.Stripe.Error.builder() - .code("code") - .declineCode("decline_code") - .type("type") - .build() - ) - .paymentMethodId("payment_method_id") - .build() - ) - .type(Payment.PaymentGateway.Type.STRIPE) - .build() - ) - .addRevenueSystemPayment( - Payment.RevenueSystemPayment.builder() - .revenueSystemProvider("revenue_system_provider") - .syncStatus("sync_status") - .errorMessage("error_message") - .revenueSystemExternalPaymentId("revenue_system_external_payment_id") - .build() - ) - .status(PaymentStatus.PENDING) - .updatedAt(OffsetDateTime.parse("2022-02-01T00:00:00Z")) - .build() - - val roundtrippedPayment = - jsonMapper.readValue(jsonMapper.writeValueAsString(payment), jacksonTypeRef()) - - assertThat(roundtrippedPayment).isEqualTo(payment) - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractEditParamsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractEditParamsTest.kt index 936b9591..b233f04c 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractEditParamsTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractEditParamsTest.kt @@ -186,6 +186,11 @@ internal class ContractEditParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractEditParams.AddCommit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -420,6 +425,41 @@ internal class ContractEditParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -753,10 +793,43 @@ internal class ContractEditParamsTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addAddSpendTracker( + ContractEditParams.AddSpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractEditParams.AddSpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addAddSubscription( ContractEditParams.AddSubscription.builder() .collectionSchedule( @@ -819,6 +892,7 @@ internal class ContractEditParamsTest { .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) + .addArchiveSpendTracker("string") .addRemoveOverride( ContractEditParams.RemoveOverride.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -1005,6 +1079,15 @@ internal class ContractEditParamsTest { ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -1035,6 +1118,39 @@ internal class ContractEditParamsTest { ) .rechargeToAmount(0.0) .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) .build() ) .addUpdateRecurringCommit( @@ -1120,6 +1236,15 @@ internal class ContractEditParamsTest { .discountConfiguration( ContractEditParams.UpdateSpendThresholdConfiguration.DiscountConfiguration .builder() + .cap( + ContractEditParams.UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -1408,6 +1533,11 @@ internal class ContractEditParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractEditParams.AddCommit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -1669,6 +1799,42 @@ internal class ContractEditParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2021,8 +2187,43 @@ internal class ContractEditParamsTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addAddSpendTracker( + ContractEditParams.AddSpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractEditParams.AddSpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addAddSubscription( @@ -2088,6 +2289,7 @@ internal class ContractEditParamsTest { .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) + .addArchiveSpendTracker("string") .addRemoveOverride( ContractEditParams.RemoveOverride.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -2302,6 +2504,15 @@ internal class ContractEditParamsTest { ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -2336,6 +2547,39 @@ internal class ContractEditParamsTest { ) .rechargeToAmount(0.0) .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) .build() ) .addUpdateRecurringCommit( @@ -2422,6 +2666,15 @@ internal class ContractEditParamsTest { ContractEditParams.UpdateSpendThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractEditParams.UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -2703,6 +2956,11 @@ internal class ContractEditParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractEditParams.AddCommit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -2941,6 +3199,41 @@ internal class ContractEditParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -3281,8 +3574,42 @@ internal class ContractEditParamsTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + assertThat(body.addSpendTrackers().getOrNull()) + .containsExactly( + ContractEditParams.AddSpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractEditParams.AddSpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) assertThat(body.addSubscriptions().getOrNull()) @@ -3351,6 +3678,7 @@ internal class ContractEditParamsTest { .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) + assertThat(body.archiveSpendTrackers().getOrNull()).containsExactly("string") assertThat(body.removeOverrides().getOrNull()) .containsExactly( ContractEditParams.RemoveOverride.builder() @@ -3542,6 +3870,15 @@ internal class ContractEditParamsTest { ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -3572,6 +3909,39 @@ internal class ContractEditParamsTest { ) .rechargeToAmount(0.0) .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) .build() ) assertThat(body.updateRecurringCommits().getOrNull()) @@ -3661,6 +4031,15 @@ internal class ContractEditParamsTest { .discountConfiguration( ContractEditParams.UpdateSpendThresholdConfiguration.DiscountConfiguration .builder() + .cap( + ContractEditParams.UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractEditResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractEditResponseTest.kt index fb17f97a..11aaa358 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractEditResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractEditResponseTest.kt @@ -3,8 +3,24 @@ package com.metronome.api.models.v2.contracts import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.metronome.api.core.JsonValue import com.metronome.api.core.jsonMapper -import com.metronome.api.models.Id +import com.metronome.api.models.BaseThresholdCommit +import com.metronome.api.models.CommitHierarchyConfiguration +import com.metronome.api.models.CommitSpecifier +import com.metronome.api.models.CommitSpecifierInput +import com.metronome.api.models.CreditTypeData +import com.metronome.api.models.Discount +import com.metronome.api.models.OverrideTier +import com.metronome.api.models.PaymentGateConfigV2 +import com.metronome.api.models.PrepaidBalanceThresholdConfigurationV2 +import com.metronome.api.models.ProService +import com.metronome.api.models.RecurringCommitSubscriptionConfig +import com.metronome.api.models.ScheduleDuration +import com.metronome.api.models.SchedulePointInTime +import com.metronome.api.models.SpendThresholdConfigurationV2 +import com.metronome.api.models.UpdateBaseThresholdCommit +import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -14,11 +30,3616 @@ internal class ContractEditResponseTest { fun create() { val contractEditResponse = ContractEditResponse.builder() - .data(Id.builder().id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build()) + .data( + ContractEditResponse.Data.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .edit( + ContractEditResponse.Data.Edit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addAddCommit( + ContractEditResponse.Data.Edit.AddCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddCommit.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(ContractEditResponse.Data.Edit.AddCommit.Type.PREPAID) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceSchedule( + ContractEditResponse.Data.Edit.AddCommit.InvoiceSchedule + .builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + ContractEditResponse.Data.Edit.AddCommit + .InvoiceSchedule + .ScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType( + ContractEditResponse.Data.Edit.AddCommit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addAddCredit( + ContractEditResponse.Data.Edit.AddCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddCredit.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(ContractEditResponse.Data.Edit.AddCredit.Type.CREDIT) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType( + ContractEditResponse.Data.Edit.AddCredit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addAddDiscount( + Discount.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + Discount.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .customFields( + Discount.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addAddOverride( + ContractEditResponse.Data.Edit.AddOverride.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductTag("string") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .entitled(true) + .isCommitSpecific(true) + .multiplier(0.0) + .addOverrideSpecifier( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .builder() + .billingFrequency( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .BillingFrequency + .MONTHLY + ) + .addCommitId("string") + .presentationGroupValues( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .addRecurringCommitId("string") + .build() + ) + .addOverrideTier( + OverrideTier.builder().multiplier(0.0).size(0.0).build() + ) + .overwriteRate( + ContractEditResponse.Data.Edit.AddOverride.OverwriteRate + .builder() + .rateType( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .RateType + .FLAT + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .customRate( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .CustomRate + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) + .isProrated(true) + .price(0.0) + .quantity(0.0) + .addTier( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .Tier + .builder() + .price(0.0) + .size(0.0) + .build() + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddOverride.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .target( + ContractEditResponse.Data.Edit.AddOverride.Target + .COMMIT_RATE + ) + .type( + ContractEditResponse.Data.Edit.AddOverride.Type + .OVERWRITE + ) + .build() + ) + .addPrepaidBalanceThresholdConfiguration( + PrepaidBalanceThresholdConfigurationV2.builder() + .commit( + PrepaidBalanceThresholdConfigurationV2.Commit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .addAddProService( + ProService.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .maxAmount(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .quantity(0.0) + .unitPrice(0.0) + .customFields( + ProService.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addAddRecurringCommit( + ContractEditResponse.Data.Edit.AddRecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.AddRecurringCommit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractEditResponse.Data.Edit.AddRecurringCommit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractEditResponse.Data.Edit + .AddRecurringCommit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddRecurringCommit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.AddRecurringCommit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractEditResponse.Data.Edit.AddRecurringCommit + .Contract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceAmount( + ContractEditResponse.Data.Edit.AddRecurringCommit + .InvoiceAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractEditResponse.Data.Edit.AddRecurringCommit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractEditResponse.Data.Edit.AddRecurringCommit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addAddRecurringCredit( + ContractEditResponse.Data.Edit.AddRecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.AddRecurringCredit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractEditResponse.Data.Edit.AddRecurringCredit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractEditResponse.Data.Edit + .AddRecurringCredit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddRecurringCredit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.AddRecurringCredit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractEditResponse.Data.Edit.AddRecurringCredit + .Contract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractEditResponse.Data.Edit.AddRecurringCredit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractEditResponse.Data.Edit.AddRecurringCredit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addAddResellerRoyalty( + ContractEditResponse.Data.Edit.AddResellerRoyalty.builder() + .resellerType( + ContractEditResponse.Data.Edit.AddResellerRoyalty + .ResellerType + .AWS + ) + .addApplicableProductId("string") + .addApplicableProductTag("string") + .awsAccountNumber("aws_account_number") + .awsOfferId("aws_offer_id") + .awsPayerReferenceId("aws_payer_reference_id") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .fraction(0.0) + .gcpAccountId("gcp_account_id") + .gcpOfferId("gcp_offer_id") + .netsuiteResellerId("netsuite_reseller_id") + .resellerContractValue(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .addAddScheduledCharge( + ContractEditResponse.Data.Edit.AddScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddScheduledCharge + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addSpendThresholdConfiguration( + SpendThresholdConfigurationV2.builder() + .commit( + BaseThresholdCommit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .discountConfiguration( + SpendThresholdConfigurationV2.DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addAddSubscription( + ContractEditResponse.Data.Edit.AddSubscription.builder() + .billingPeriods( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .builder() + .current( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Current + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .next( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Next + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .previous( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Previous + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .collectionSchedule( + ContractEditResponse.Data.Edit.AddSubscription + .CollectionSchedule + .ADVANCE + ) + .proration( + ContractEditResponse.Data.Edit.AddSubscription.Proration + .builder() + .invoiceBehavior( + ContractEditResponse.Data.Edit.AddSubscription + .Proration + .InvoiceBehavior + .BILL_IMMEDIATELY + ) + .isProrated(true) + .build() + ) + .quantityManagementMode( + ContractEditResponse.Data.Edit.AddSubscription + .QuantityManagementMode + .SEAT_BASED + ) + .addQuantitySchedule( + ContractEditResponse.Data.Edit.AddSubscription + .QuantitySchedule + .builder() + .quantity(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .subscriptionRate( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .builder() + .billingFrequency( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .BillingFrequency + .MONTHLY + ) + .product( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + ContractEditResponse.Data.Edit.AddSubscription + .CustomFields + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .fiatCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .seatConfig( + ContractEditResponse.Data.Edit.AddSubscription + .SeatConfig + .builder() + .seatGroupKey("seat_group_key") + .build() + ) + .build() + ) + .addAddUsageFilter( + ContractEditResponse.Data.Edit.AddUsageFilter.builder() + .groupKey("group_key") + .addGroupValue("string") + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .addArchiveCommit( + ContractEditResponse.Data.Edit.ArchiveCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addArchiveCredit( + ContractEditResponse.Data.Edit.ArchiveCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addArchiveScheduledCharge( + ContractEditResponse.Data.Edit.ArchiveScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addRemoveOverride( + ContractEditResponse.Data.Edit.RemoveOverride.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .uniquenessKey("x") + .addUpdateCommit( + ContractEditResponse.Data.Edit.UpdateCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessSchedule( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .AddScheduleItem + .builder() + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceSchedule( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .AddScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rateType( + ContractEditResponse.Data.Edit.UpdateCommit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .updateContractEndDate( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .updateContractName("update_contract_name") + .addUpdateCredit( + ContractEditResponse.Data.Edit.UpdateCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessSchedule( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .AddScheduleItem + .builder() + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rateType( + ContractEditResponse.Data.Edit.UpdateCredit.RateType + .LIST_RATE + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addUpdateDiscount( + ContractEditResponse.Data.Edit.UpdateDiscount.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + ContractEditResponse.Data.Edit.UpdateDiscount + .CustomFields + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .schedule( + ContractEditResponse.Data.Edit.UpdateDiscount.Schedule + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .doNotInvoice(true) + .recurringSchedule( + ContractEditResponse.Data.Edit.UpdateDiscount + .Schedule + .RecurringSchedule + .builder() + .amountDistribution( + ContractEditResponse.Data.Edit + .UpdateDiscount + .Schedule + .RecurringSchedule + .AmountDistribution + .DIVIDED + ) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .frequency( + ContractEditResponse.Data.Edit + .UpdateDiscount + .Schedule + .RecurringSchedule + .Frequency + .MONTHLY + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addScheduleItem( + ContractEditResponse.Data.Edit.UpdateDiscount + .Schedule + .ScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .build() + ) + .build() + ) + .updatePrepaidBalanceThresholdConfiguration( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .builder() + .commit( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .Commit + .builder() + .description("description") + .name("name") + .priority(0.0) + .productId("product_id") + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .builder() + .cap( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .paymentFraction(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .addUpdateRecurringCommit( + ContractEditResponse.Data.Edit.UpdateRecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .AccessAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .invoiceAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .InvoiceAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .RateType + .LIST_RATE + ) + .build() + ) + .addUpdateRecurringCredit( + ContractEditResponse.Data.Edit.UpdateRecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCredit + .AccessAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .rateType( + ContractEditResponse.Data.Edit.UpdateRecurringCredit + .RateType + .LIST_RATE + ) + .build() + ) + .addUpdateRefundInvoice( + ContractEditResponse.Data.Edit.UpdateRefundInvoice.builder() + .date(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduledCharge( + ContractEditResponse.Data.Edit.UpdateScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .invoiceSchedule( + ContractEditResponse.Data.Edit.UpdateScheduledCharge + .InvoiceSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit + .UpdateScheduledCharge + .InvoiceSchedule + .AddScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit + .UpdateScheduledCharge + .InvoiceSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit + .UpdateScheduledCharge + .InvoiceSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .updateSpendThresholdConfiguration( + ContractEditResponse.Data.Edit.UpdateSpendThresholdConfiguration + .builder() + .commit( + UpdateBaseThresholdCommit.builder() + .description("description") + .name("name") + .priority(0.0) + .productId("product_id") + .build() + ) + .discountConfiguration( + ContractEditResponse.Data.Edit + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .builder() + .cap( + ContractEditResponse.Data.Edit + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .paymentFraction(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .build() + ) + .addUpdateSubscription( + ContractEditResponse.Data.Edit.UpdateSubscription.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addQuantityUpdate( + ContractEditResponse.Data.Edit.UpdateSubscription + .QuantityUpdate + .builder() + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .quantity(0.0) + .quantityDelta(0.0) + .build() + ) + .seatUpdates( + ContractEditResponse.Data.Edit.UpdateSubscription + .SeatUpdates + .builder() + .addAddSeatId( + ContractEditResponse.Data.Edit + .UpdateSubscription + .SeatUpdates + .AddSeatId + .builder() + .addSeatId("string") + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addAddUnassignedSeat( + ContractEditResponse.Data.Edit + .UpdateSubscription + .SeatUpdates + .AddUnassignedSeat + .builder() + .quantity(1.0) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveSeatId( + ContractEditResponse.Data.Edit + .UpdateSubscription + .SeatUpdates + .RemoveSeatId + .builder() + .addSeatId("string") + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveUnassignedSeat( + ContractEditResponse.Data.Edit + .UpdateSubscription + .SeatUpdates + .RemoveUnassignedSeat + .builder() + .quantity(1.0) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .build() + ) .build() assertThat(contractEditResponse.data()) - .isEqualTo(Id.builder().id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build()) + .isEqualTo( + ContractEditResponse.Data.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .edit( + ContractEditResponse.Data.Edit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addAddCommit( + ContractEditResponse.Data.Edit.AddCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddCommit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(ContractEditResponse.Data.Edit.AddCommit.Type.PREPAID) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceSchedule( + ContractEditResponse.Data.Edit.AddCommit.InvoiceSchedule + .builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + ContractEditResponse.Data.Edit.AddCommit + .InvoiceSchedule + .ScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType( + ContractEditResponse.Data.Edit.AddCommit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addAddCredit( + ContractEditResponse.Data.Edit.AddCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddCredit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(ContractEditResponse.Data.Edit.AddCredit.Type.CREDIT) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType( + ContractEditResponse.Data.Edit.AddCredit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addAddDiscount( + Discount.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + Discount.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .customFields( + Discount.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addAddOverride( + ContractEditResponse.Data.Edit.AddOverride.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addApplicableProductTag("string") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .entitled(true) + .isCommitSpecific(true) + .multiplier(0.0) + .addOverrideSpecifier( + ContractEditResponse.Data.Edit.AddOverride.OverrideSpecifier + .builder() + .billingFrequency( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .BillingFrequency + .MONTHLY + ) + .addCommitId("string") + .presentationGroupValues( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .addRecurringCommitId("string") + .build() + ) + .addOverrideTier( + OverrideTier.builder().multiplier(0.0).size(0.0).build() + ) + .overwriteRate( + ContractEditResponse.Data.Edit.AddOverride.OverwriteRate + .builder() + .rateType( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .RateType + .FLAT + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .customRate( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .CustomRate + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) + .isProrated(true) + .price(0.0) + .quantity(0.0) + .addTier( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .Tier + .builder() + .price(0.0) + .size(0.0) + .build() + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddOverride.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .target( + ContractEditResponse.Data.Edit.AddOverride.Target + .COMMIT_RATE + ) + .type(ContractEditResponse.Data.Edit.AddOverride.Type.OVERWRITE) + .build() + ) + .addPrepaidBalanceThresholdConfiguration( + PrepaidBalanceThresholdConfigurationV2.builder() + .commit( + PrepaidBalanceThresholdConfigurationV2.Commit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig.builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig.PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .addAddProService( + ProService.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .maxAmount(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .quantity(0.0) + .unitPrice(0.0) + .customFields( + ProService.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .description("description") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addAddRecurringCommit( + ContractEditResponse.Data.Edit.AddRecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.AddRecurringCommit + .AccessAmount + .builder() + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractEditResponse.Data.Edit.AddRecurringCommit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractEditResponse.Data.Edit.AddRecurringCommit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddRecurringCommit.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.AddRecurringCommit.RateType + .COMMIT_RATE + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .contract( + ContractEditResponse.Data.Edit.AddRecurringCommit.Contract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceAmount( + ContractEditResponse.Data.Edit.AddRecurringCommit + .InvoiceAmount + .builder() + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractEditResponse.Data.Edit.AddRecurringCommit.Proration + .NONE + ) + .recurrenceFrequency( + ContractEditResponse.Data.Edit.AddRecurringCommit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + ) + .addAddRecurringCredit( + ContractEditResponse.Data.Edit.AddRecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.AddRecurringCredit + .AccessAmount + .builder() + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractEditResponse.Data.Edit.AddRecurringCredit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractEditResponse.Data.Edit.AddRecurringCredit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddRecurringCredit.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.AddRecurringCredit.RateType + .COMMIT_RATE + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .contract( + ContractEditResponse.Data.Edit.AddRecurringCredit.Contract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractEditResponse.Data.Edit.AddRecurringCredit.Proration + .NONE + ) + .recurrenceFrequency( + ContractEditResponse.Data.Edit.AddRecurringCredit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + ) + .addAddResellerRoyalty( + ContractEditResponse.Data.Edit.AddResellerRoyalty.builder() + .resellerType( + ContractEditResponse.Data.Edit.AddResellerRoyalty + .ResellerType + .AWS + ) + .addApplicableProductId("string") + .addApplicableProductTag("string") + .awsAccountNumber("aws_account_number") + .awsOfferId("aws_offer_id") + .awsPayerReferenceId("aws_payer_reference_id") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .fraction(0.0) + .gcpAccountId("gcp_account_id") + .gcpOfferId("gcp_offer_id") + .netsuiteResellerId("netsuite_reseller_id") + .resellerContractValue(0.0) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .addAddScheduledCharge( + ContractEditResponse.Data.Edit.AddScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddScheduledCharge.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addSpendThresholdConfiguration( + SpendThresholdConfigurationV2.builder() + .commit( + BaseThresholdCommit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig.builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig.PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .discountConfiguration( + SpendThresholdConfigurationV2.DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addAddSubscription( + ContractEditResponse.Data.Edit.AddSubscription.builder() + .billingPeriods( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .builder() + .current( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Current + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .next( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Next + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .previous( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Previous + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .collectionSchedule( + ContractEditResponse.Data.Edit.AddSubscription + .CollectionSchedule + .ADVANCE + ) + .proration( + ContractEditResponse.Data.Edit.AddSubscription.Proration + .builder() + .invoiceBehavior( + ContractEditResponse.Data.Edit.AddSubscription + .Proration + .InvoiceBehavior + .BILL_IMMEDIATELY + ) + .isProrated(true) + .build() + ) + .quantityManagementMode( + ContractEditResponse.Data.Edit.AddSubscription + .QuantityManagementMode + .SEAT_BASED + ) + .addQuantitySchedule( + ContractEditResponse.Data.Edit.AddSubscription + .QuantitySchedule + .builder() + .quantity(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .subscriptionRate( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .builder() + .billingFrequency( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .BillingFrequency + .MONTHLY + ) + .product( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + ContractEditResponse.Data.Edit.AddSubscription.CustomFields + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .description("description") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .fiatCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .seatConfig( + ContractEditResponse.Data.Edit.AddSubscription.SeatConfig + .builder() + .seatGroupKey("seat_group_key") + .build() + ) + .build() + ) + .addAddUsageFilter( + ContractEditResponse.Data.Edit.AddUsageFilter.builder() + .groupKey("group_key") + .addGroupValue("string") + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .addArchiveCommit( + ContractEditResponse.Data.Edit.ArchiveCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addArchiveCredit( + ContractEditResponse.Data.Edit.ArchiveCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addArchiveScheduledCharge( + ContractEditResponse.Data.Edit.ArchiveScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addRemoveOverride( + ContractEditResponse.Data.Edit.RemoveOverride.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .uniquenessKey("x") + .addUpdateCommit( + ContractEditResponse.Data.Edit.UpdateCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessSchedule( + ContractEditResponse.Data.Edit.UpdateCommit.AccessSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .AddScheduleItem + .builder() + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceSchedule( + ContractEditResponse.Data.Edit.UpdateCommit.InvoiceSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .AddScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rateType( + ContractEditResponse.Data.Edit.UpdateCommit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .updateContractEndDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .updateContractName("update_contract_name") + .addUpdateCredit( + ContractEditResponse.Data.Edit.UpdateCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessSchedule( + ContractEditResponse.Data.Edit.UpdateCredit.AccessSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .AddScheduleItem + .builder() + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .addApplicableProductId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rateType( + ContractEditResponse.Data.Edit.UpdateCredit.RateType + .LIST_RATE + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addUpdateDiscount( + ContractEditResponse.Data.Edit.UpdateDiscount.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + ContractEditResponse.Data.Edit.UpdateDiscount.CustomFields + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .schedule( + ContractEditResponse.Data.Edit.UpdateDiscount.Schedule + .builder() + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .doNotInvoice(true) + .recurringSchedule( + ContractEditResponse.Data.Edit.UpdateDiscount + .Schedule + .RecurringSchedule + .builder() + .amountDistribution( + ContractEditResponse.Data.Edit + .UpdateDiscount + .Schedule + .RecurringSchedule + .AmountDistribution + .DIVIDED + ) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .frequency( + ContractEditResponse.Data.Edit + .UpdateDiscount + .Schedule + .RecurringSchedule + .Frequency + .MONTHLY + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addScheduleItem( + ContractEditResponse.Data.Edit.UpdateDiscount + .Schedule + .ScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .build() + ) + .build() + ) + .updatePrepaidBalanceThresholdConfiguration( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .builder() + .commit( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .Commit + .builder() + .description("description") + .name("name") + .priority(0.0) + .productId("product_id") + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .builder() + .cap( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .paymentFraction(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig.builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig.PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .addUpdateRecurringCommit( + ContractEditResponse.Data.Edit.UpdateRecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .AccessAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .invoiceAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .InvoiceAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .RateType + .LIST_RATE + ) + .build() + ) + .addUpdateRecurringCredit( + ContractEditResponse.Data.Edit.UpdateRecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCredit + .AccessAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .rateType( + ContractEditResponse.Data.Edit.UpdateRecurringCredit + .RateType + .LIST_RATE + ) + .build() + ) + .addUpdateRefundInvoice( + ContractEditResponse.Data.Edit.UpdateRefundInvoice.builder() + .date(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduledCharge( + ContractEditResponse.Data.Edit.UpdateScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .invoiceSchedule( + ContractEditResponse.Data.Edit.UpdateScheduledCharge + .InvoiceSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateScheduledCharge + .InvoiceSchedule + .AddScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateScheduledCharge + .InvoiceSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateScheduledCharge + .InvoiceSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .updateSpendThresholdConfiguration( + ContractEditResponse.Data.Edit.UpdateSpendThresholdConfiguration + .builder() + .commit( + UpdateBaseThresholdCommit.builder() + .description("description") + .name("name") + .priority(0.0) + .productId("product_id") + .build() + ) + .discountConfiguration( + ContractEditResponse.Data.Edit + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .builder() + .cap( + ContractEditResponse.Data.Edit + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .paymentFraction(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig.builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig.PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .build() + ) + .addUpdateSubscription( + ContractEditResponse.Data.Edit.UpdateSubscription.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addQuantityUpdate( + ContractEditResponse.Data.Edit.UpdateSubscription + .QuantityUpdate + .builder() + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .quantity(0.0) + .quantityDelta(0.0) + .build() + ) + .seatUpdates( + ContractEditResponse.Data.Edit.UpdateSubscription + .SeatUpdates + .builder() + .addAddSeatId( + ContractEditResponse.Data.Edit.UpdateSubscription + .SeatUpdates + .AddSeatId + .builder() + .addSeatId("string") + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addAddUnassignedSeat( + ContractEditResponse.Data.Edit.UpdateSubscription + .SeatUpdates + .AddUnassignedSeat + .builder() + .quantity(1.0) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveSeatId( + ContractEditResponse.Data.Edit.UpdateSubscription + .SeatUpdates + .RemoveSeatId + .builder() + .addSeatId("string") + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveUnassignedSeat( + ContractEditResponse.Data.Edit.UpdateSubscription + .SeatUpdates + .RemoveUnassignedSeat + .builder() + .quantity(1.0) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .build() + ) } @Test @@ -26,7 +3647,1868 @@ internal class ContractEditResponseTest { val jsonMapper = jsonMapper() val contractEditResponse = ContractEditResponse.builder() - .data(Id.builder().id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build()) + .data( + ContractEditResponse.Data.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .edit( + ContractEditResponse.Data.Edit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addAddCommit( + ContractEditResponse.Data.Edit.AddCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddCommit.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(ContractEditResponse.Data.Edit.AddCommit.Type.PREPAID) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceSchedule( + ContractEditResponse.Data.Edit.AddCommit.InvoiceSchedule + .builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + ContractEditResponse.Data.Edit.AddCommit + .InvoiceSchedule + .ScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType( + ContractEditResponse.Data.Edit.AddCommit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addAddCredit( + ContractEditResponse.Data.Edit.AddCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddCredit.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(ContractEditResponse.Data.Edit.AddCredit.Type.CREDIT) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType( + ContractEditResponse.Data.Edit.AddCredit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addAddDiscount( + Discount.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + Discount.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .customFields( + Discount.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addAddOverride( + ContractEditResponse.Data.Edit.AddOverride.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductTag("string") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .entitled(true) + .isCommitSpecific(true) + .multiplier(0.0) + .addOverrideSpecifier( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .builder() + .billingFrequency( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .BillingFrequency + .MONTHLY + ) + .addCommitId("string") + .presentationGroupValues( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + ContractEditResponse.Data.Edit.AddOverride + .OverrideSpecifier + .PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .addRecurringCommitId("string") + .build() + ) + .addOverrideTier( + OverrideTier.builder().multiplier(0.0).size(0.0).build() + ) + .overwriteRate( + ContractEditResponse.Data.Edit.AddOverride.OverwriteRate + .builder() + .rateType( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .RateType + .FLAT + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .customRate( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .CustomRate + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) + .isProrated(true) + .price(0.0) + .quantity(0.0) + .addTier( + ContractEditResponse.Data.Edit.AddOverride + .OverwriteRate + .Tier + .builder() + .price(0.0) + .size(0.0) + .build() + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddOverride.Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .target( + ContractEditResponse.Data.Edit.AddOverride.Target + .COMMIT_RATE + ) + .type( + ContractEditResponse.Data.Edit.AddOverride.Type + .OVERWRITE + ) + .build() + ) + .addPrepaidBalanceThresholdConfiguration( + PrepaidBalanceThresholdConfigurationV2.builder() + .commit( + PrepaidBalanceThresholdConfigurationV2.Commit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .addAddProService( + ProService.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .maxAmount(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .quantity(0.0) + .unitPrice(0.0) + .customFields( + ProService.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addAddRecurringCommit( + ContractEditResponse.Data.Edit.AddRecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.AddRecurringCommit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractEditResponse.Data.Edit.AddRecurringCommit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractEditResponse.Data.Edit + .AddRecurringCommit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddRecurringCommit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.AddRecurringCommit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractEditResponse.Data.Edit.AddRecurringCommit + .Contract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceAmount( + ContractEditResponse.Data.Edit.AddRecurringCommit + .InvoiceAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractEditResponse.Data.Edit.AddRecurringCommit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractEditResponse.Data.Edit.AddRecurringCommit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addAddRecurringCredit( + ContractEditResponse.Data.Edit.AddRecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.AddRecurringCredit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractEditResponse.Data.Edit.AddRecurringCredit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractEditResponse.Data.Edit + .AddRecurringCredit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractEditResponse.Data.Edit.AddRecurringCredit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.AddRecurringCredit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractEditResponse.Data.Edit.AddRecurringCredit + .Contract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractEditResponse.Data.Edit.AddRecurringCredit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractEditResponse.Data.Edit.AddRecurringCredit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addAddResellerRoyalty( + ContractEditResponse.Data.Edit.AddResellerRoyalty.builder() + .resellerType( + ContractEditResponse.Data.Edit.AddResellerRoyalty + .ResellerType + .AWS + ) + .addApplicableProductId("string") + .addApplicableProductTag("string") + .awsAccountNumber("aws_account_number") + .awsOfferId("aws_offer_id") + .awsPayerReferenceId("aws_payer_reference_id") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .fraction(0.0) + .gcpAccountId("gcp_account_id") + .gcpOfferId("gcp_offer_id") + .netsuiteResellerId("netsuite_reseller_id") + .resellerContractValue(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .addAddScheduledCharge( + ContractEditResponse.Data.Edit.AddScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ContractEditResponse.Data.Edit.AddScheduledCharge + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .addSpendThresholdConfiguration( + SpendThresholdConfigurationV2.builder() + .commit( + BaseThresholdCommit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .discountConfiguration( + SpendThresholdConfigurationV2.DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addAddSubscription( + ContractEditResponse.Data.Edit.AddSubscription.builder() + .billingPeriods( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .builder() + .current( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Current + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .next( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Next + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .previous( + ContractEditResponse.Data.Edit.AddSubscription + .BillingPeriods + .Previous + .builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .collectionSchedule( + ContractEditResponse.Data.Edit.AddSubscription + .CollectionSchedule + .ADVANCE + ) + .proration( + ContractEditResponse.Data.Edit.AddSubscription.Proration + .builder() + .invoiceBehavior( + ContractEditResponse.Data.Edit.AddSubscription + .Proration + .InvoiceBehavior + .BILL_IMMEDIATELY + ) + .isProrated(true) + .build() + ) + .quantityManagementMode( + ContractEditResponse.Data.Edit.AddSubscription + .QuantityManagementMode + .SEAT_BASED + ) + .addQuantitySchedule( + ContractEditResponse.Data.Edit.AddSubscription + .QuantitySchedule + .builder() + .quantity(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .subscriptionRate( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .builder() + .billingFrequency( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .BillingFrequency + .MONTHLY + ) + .product( + ContractEditResponse.Data.Edit.AddSubscription + .SubscriptionRate + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + ContractEditResponse.Data.Edit.AddSubscription + .CustomFields + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .fiatCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .seatConfig( + ContractEditResponse.Data.Edit.AddSubscription + .SeatConfig + .builder() + .seatGroupKey("seat_group_key") + .build() + ) + .build() + ) + .addAddUsageFilter( + ContractEditResponse.Data.Edit.AddUsageFilter.builder() + .groupKey("group_key") + .addGroupValue("string") + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .addArchiveCommit( + ContractEditResponse.Data.Edit.ArchiveCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addArchiveCredit( + ContractEditResponse.Data.Edit.ArchiveCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addArchiveScheduledCharge( + ContractEditResponse.Data.Edit.ArchiveScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addRemoveOverride( + ContractEditResponse.Data.Edit.RemoveOverride.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .uniquenessKey("x") + .addUpdateCommit( + ContractEditResponse.Data.Edit.UpdateCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessSchedule( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .AddScheduleItem + .builder() + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .AccessSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceSchedule( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .AddScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCommit + .InvoiceSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rateType( + ContractEditResponse.Data.Edit.UpdateCommit.RateType + .COMMIT_RATE + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .updateContractEndDate( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .updateContractName("update_contract_name") + .addUpdateCredit( + ContractEditResponse.Data.Edit.UpdateCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessSchedule( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .AddScheduleItem + .builder() + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit.UpdateCredit + .AccessSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rateType( + ContractEditResponse.Data.Edit.UpdateCredit.RateType + .LIST_RATE + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .build() + ) + .addUpdateDiscount( + ContractEditResponse.Data.Edit.UpdateDiscount.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + ContractEditResponse.Data.Edit.UpdateDiscount + .CustomFields + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .schedule( + ContractEditResponse.Data.Edit.UpdateDiscount.Schedule + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .doNotInvoice(true) + .recurringSchedule( + ContractEditResponse.Data.Edit.UpdateDiscount + .Schedule + .RecurringSchedule + .builder() + .amountDistribution( + ContractEditResponse.Data.Edit + .UpdateDiscount + .Schedule + .RecurringSchedule + .AmountDistribution + .DIVIDED + ) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .frequency( + ContractEditResponse.Data.Edit + .UpdateDiscount + .Schedule + .RecurringSchedule + .Frequency + .MONTHLY + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addScheduleItem( + ContractEditResponse.Data.Edit.UpdateDiscount + .Schedule + .ScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .build() + ) + .build() + ) + .updatePrepaidBalanceThresholdConfiguration( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .builder() + .commit( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .Commit + .builder() + .description("description") + .name("name") + .priority(0.0) + .productId("product_id") + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .builder() + .cap( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .paymentFraction(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractEditResponse.Data.Edit + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .addUpdateRecurringCommit( + ContractEditResponse.Data.Edit.UpdateRecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .AccessAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .invoiceAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .InvoiceAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .rateType( + ContractEditResponse.Data.Edit.UpdateRecurringCommit + .RateType + .LIST_RATE + ) + .build() + ) + .addUpdateRecurringCredit( + ContractEditResponse.Data.Edit.UpdateRecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractEditResponse.Data.Edit.UpdateRecurringCredit + .AccessAmount + .builder() + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .rateType( + ContractEditResponse.Data.Edit.UpdateRecurringCredit + .RateType + .LIST_RATE + ) + .build() + ) + .addUpdateRefundInvoice( + ContractEditResponse.Data.Edit.UpdateRefundInvoice.builder() + .date(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .invoiceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduledCharge( + ContractEditResponse.Data.Edit.UpdateScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .invoiceSchedule( + ContractEditResponse.Data.Edit.UpdateScheduledCharge + .InvoiceSchedule + .builder() + .addAddScheduleItem( + ContractEditResponse.Data.Edit + .UpdateScheduledCharge + .InvoiceSchedule + .AddScheduleItem + .builder() + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .amount(0.0) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .addRemoveScheduleItem( + ContractEditResponse.Data.Edit + .UpdateScheduledCharge + .InvoiceSchedule + .RemoveScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addUpdateScheduleItem( + ContractEditResponse.Data.Edit + .UpdateScheduledCharge + .InvoiceSchedule + .UpdateScheduleItem + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .updateSpendThresholdConfiguration( + ContractEditResponse.Data.Edit.UpdateSpendThresholdConfiguration + .builder() + .commit( + UpdateBaseThresholdCommit.builder() + .description("description") + .name("name") + .priority(0.0) + .productId("product_id") + .build() + ) + .discountConfiguration( + ContractEditResponse.Data.Edit + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .builder() + .cap( + ContractEditResponse.Data.Edit + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .paymentFraction(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfigV2.builder() + .paymentGateType( + PaymentGateConfigV2.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfigV2.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfigV2.StripeConfig.builder() + .paymentType( + PaymentGateConfigV2.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfigV2.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfigV2.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .build() + ) + .addUpdateSubscription( + ContractEditResponse.Data.Edit.UpdateSubscription.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addQuantityUpdate( + ContractEditResponse.Data.Edit.UpdateSubscription + .QuantityUpdate + .builder() + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .quantity(0.0) + .quantityDelta(0.0) + .build() + ) + .seatUpdates( + ContractEditResponse.Data.Edit.UpdateSubscription + .SeatUpdates + .builder() + .addAddSeatId( + ContractEditResponse.Data.Edit + .UpdateSubscription + .SeatUpdates + .AddSeatId + .builder() + .addSeatId("string") + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addAddUnassignedSeat( + ContractEditResponse.Data.Edit + .UpdateSubscription + .SeatUpdates + .AddUnassignedSeat + .builder() + .quantity(1.0) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveSeatId( + ContractEditResponse.Data.Edit + .UpdateSubscription + .SeatUpdates + .RemoveSeatId + .builder() + .addSeatId("string") + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .addRemoveUnassignedSeat( + ContractEditResponse.Data.Edit + .UpdateSubscription + .SeatUpdates + .RemoveUnassignedSeat + .builder() + .quantity(1.0) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .build() + ) .build() val roundtrippedContractEditResponse = diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractGetEditHistoryResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractGetEditHistoryResponseTest.kt index 74640afd..a9e96016 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractGetEditHistoryResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractGetEditHistoryResponseTest.kt @@ -449,6 +449,45 @@ internal class ContractGetEditHistoryResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -810,6 +849,13 @@ internal class ContractGetEditHistoryResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() @@ -1317,6 +1363,16 @@ internal class ContractGetEditHistoryResponseTest { .UpdatePrepaidBalanceThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -1352,6 +1408,41 @@ internal class ContractGetEditHistoryResponseTest { ) .rechargeToAmount(0.0) .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) .build() ) .addUpdateRecurringCommit( @@ -1473,6 +1564,16 @@ internal class ContractGetEditHistoryResponseTest { .UpdateSpendThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractGetEditHistoryResponse.Data + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -1971,6 +2072,44 @@ internal class ContractGetEditHistoryResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2313,6 +2452,13 @@ internal class ContractGetEditHistoryResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() @@ -2793,6 +2939,16 @@ internal class ContractGetEditHistoryResponseTest { .UpdatePrepaidBalanceThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -2827,6 +2983,41 @@ internal class ContractGetEditHistoryResponseTest { ) .rechargeToAmount(0.0) .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) .build() ) .addUpdateRecurringCommit( @@ -2943,6 +3134,16 @@ internal class ContractGetEditHistoryResponseTest { .UpdateSpendThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractGetEditHistoryResponse.Data + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -3470,6 +3671,45 @@ internal class ContractGetEditHistoryResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -3831,6 +4071,13 @@ internal class ContractGetEditHistoryResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() @@ -4338,6 +4585,16 @@ internal class ContractGetEditHistoryResponseTest { .UpdatePrepaidBalanceThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -4373,6 +4630,41 @@ internal class ContractGetEditHistoryResponseTest { ) .rechargeToAmount(0.0) .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractGetEditHistoryResponse.Data + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) .build() ) .addUpdateRecurringCommit( @@ -4494,6 +4786,16 @@ internal class ContractGetEditHistoryResponseTest { .UpdateSpendThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractGetEditHistoryResponse.Data + .UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractListResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractListResponseTest.kt index 9f1bc8a5..6c908f87 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractListResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractListResponseTest.kt @@ -176,6 +176,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation( @@ -635,6 +640,45 @@ internal class ContractListResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -936,6 +980,51 @@ internal class ContractListResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -1183,6 +1272,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation( @@ -1622,6 +1716,44 @@ internal class ContractListResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1898,6 +2030,47 @@ internal class ContractListResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -2146,6 +2319,11 @@ internal class ContractListResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation( @@ -2605,6 +2783,45 @@ internal class ContractListResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2906,6 +3123,51 @@ internal class ContractListResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractRetrieveResponseTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractRetrieveResponseTest.kt index c89c0a24..ae62f2e1 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractRetrieveResponseTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/models/v2/contracts/ContractRetrieveResponseTest.kt @@ -176,6 +176,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation( @@ -635,6 +640,45 @@ internal class ContractRetrieveResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -936,6 +980,51 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -1183,6 +1272,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation( @@ -1622,6 +1716,44 @@ internal class ContractRetrieveResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1898,6 +2030,47 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier.SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency(ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() @@ -2146,6 +2319,11 @@ internal class ContractRetrieveResponseTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractV2.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .subscriptionConfig( RecurringCommitSubscriptionConfig.builder() .allocation( @@ -2605,6 +2783,45 @@ internal class ContractRetrieveResponseTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2 + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2906,6 +3123,51 @@ internal class ContractRetrieveResponseTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractV2.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractV2.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractV2.SpendTracker.ApplicableSpendSpecifier.Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractV2.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractV2.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractV2.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .accumulatedSpend( + ContractV2.SpendTracker.AccumulatedSpend.builder() + .amount(0.0) + .periodEndingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .periodStartingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) .build() ) .build() diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/ErrorHandlingTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/ErrorHandlingTest.kt index 8b073495..5a120db2 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/ErrorHandlingTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/services/ErrorHandlingTest.kt @@ -215,6 +215,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -540,6 +545,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -897,10 +941,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -1144,6 +1227,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -1469,6 +1557,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -1826,10 +1953,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -2073,6 +2239,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -2398,6 +2569,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -2755,10 +2965,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -3002,6 +3251,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -3327,6 +3581,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -3684,10 +3977,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -3931,6 +4263,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -4256,6 +4593,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -4613,8 +4989,47 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -4860,6 +5275,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -5185,6 +5605,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -5542,8 +6001,47 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -5789,6 +6287,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -6114,6 +6617,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -6471,8 +7013,47 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -6718,6 +7299,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -7043,6 +7629,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -7400,10 +8025,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -7647,6 +8311,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -7972,6 +8641,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -8329,10 +9037,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -8576,6 +9323,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -8901,6 +9653,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -9258,10 +10049,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -9505,6 +10335,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -9830,6 +10665,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -10187,10 +11061,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -10434,6 +11347,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -10759,6 +11677,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -11116,10 +12073,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -11363,6 +12359,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -11688,6 +12689,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -12045,8 +13085,47 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -12292,6 +13371,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -12617,6 +13701,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -12974,8 +14097,47 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( @@ -13221,6 +14383,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -13546,6 +14713,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -13903,10 +15109,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -14150,6 +15395,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -14475,6 +15725,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -14832,10 +16121,49 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -15077,6 +16405,11 @@ internal class ErrorHandlingTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -15402,6 +16735,45 @@ internal class ErrorHandlingTest { PrepaidBalanceThresholdConfiguration.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -15759,8 +17131,47 @@ internal class ErrorHandlingTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker + .ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addSubscription( diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/ServiceParamsTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/ServiceParamsTest.kt index 0375640e..06dd07cc 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/ServiceParamsTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/services/ServiceParamsTest.kt @@ -173,6 +173,11 @@ internal class ServiceParamsTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -465,6 +470,41 @@ internal class ServiceParamsTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier.builder() + .addExclude( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -795,10 +835,44 @@ internal class ServiceParamsTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap.builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/ContractServiceAsyncTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/ContractServiceAsyncTest.kt index 079f171b..28dfc1e4 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/ContractServiceAsyncTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/ContractServiceAsyncTest.kt @@ -173,6 +173,11 @@ internal class ContractServiceAsyncTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -476,6 +481,44 @@ internal class ContractServiceAsyncTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -814,10 +857,45 @@ internal class ContractServiceAsyncTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -1110,6 +1188,11 @@ internal class ContractServiceAsyncTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractAmendParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/PackageServiceAsyncTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/PackageServiceAsyncTest.kt index 61321c1c..07465e08 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/PackageServiceAsyncTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/PackageServiceAsyncTest.kt @@ -379,6 +379,44 @@ internal class PackageServiceAsyncTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -638,10 +676,45 @@ internal class PackageServiceAsyncTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + PackageCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( PackageCreateParams.Subscription.builder() .collectionSchedule( diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsyncTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsyncTest.kt deleted file mode 100644 index 5948cd08..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v1/PaymentServiceAsyncTest.kt +++ /dev/null @@ -1,78 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.services.async.v1 - -import com.metronome.api.TestServerExtension -import com.metronome.api.client.okhttp.MetronomeOkHttpClientAsync -import com.metronome.api.models.v1.payments.PaymentAttemptParams -import com.metronome.api.models.v1.payments.PaymentCancelParams -import com.metronome.api.models.v1.payments.PaymentListParams -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith - -@ExtendWith(TestServerExtension::class) -internal class PaymentServiceAsyncTest { - - @Test - fun list() { - val client = - MetronomeOkHttpClientAsync.builder() - .baseUrl(TestServerExtension.BASE_URL) - .bearerToken("My Bearer Token") - .build() - val paymentServiceAsync = client.v1().payments() - - val pageFuture = - paymentServiceAsync.list( - PaymentListParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - ) - - val page = pageFuture.get() - page.response().validate() - } - - @Test - fun attempt() { - val client = - MetronomeOkHttpClientAsync.builder() - .baseUrl(TestServerExtension.BASE_URL) - .bearerToken("My Bearer Token") - .build() - val paymentServiceAsync = client.v1().payments() - - val responseFuture = - paymentServiceAsync.attempt( - PaymentAttemptParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - ) - - val response = responseFuture.get() - response.validate() - } - - @Test - fun cancel() { - val client = - MetronomeOkHttpClientAsync.builder() - .baseUrl(TestServerExtension.BASE_URL) - .bearerToken("My Bearer Token") - .build() - val paymentServiceAsync = client.v1().payments() - - val responseFuture = - paymentServiceAsync.cancel( - PaymentCancelParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - ) - - val response = responseFuture.get() - response.validate() - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v2/ContractServiceAsyncTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v2/ContractServiceAsyncTest.kt index c4ea62e1..449f8484 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v2/ContractServiceAsyncTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/services/async/v2/ContractServiceAsyncTest.kt @@ -278,6 +278,11 @@ internal class ContractServiceAsyncTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractEditParams.AddCommit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -544,6 +549,44 @@ internal class ContractServiceAsyncTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -900,8 +943,44 @@ internal class ContractServiceAsyncTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addAddSpendTracker( + ContractEditParams.AddSpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractEditParams.AddSpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addAddSubscription( @@ -967,6 +1046,7 @@ internal class ContractServiceAsyncTest { .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) + .addArchiveSpendTracker("string") .addRemoveOverride( ContractEditParams.RemoveOverride.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -1189,6 +1269,16 @@ internal class ContractServiceAsyncTest { ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -1223,6 +1313,40 @@ internal class ContractServiceAsyncTest { ) .rechargeToAmount(0.0) .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) .build() ) .addUpdateRecurringCommit( @@ -1313,6 +1437,15 @@ internal class ContractServiceAsyncTest { ContractEditParams.UpdateSpendThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractEditParams.UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/ContractServiceTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/ContractServiceTest.kt index 1f60edde..f064af1c 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/ContractServiceTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/ContractServiceTest.kt @@ -173,6 +173,11 @@ internal class ContractServiceTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractCreateParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -476,6 +481,44 @@ internal class ContractServiceTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -814,10 +857,45 @@ internal class ContractServiceTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + ContractCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( ContractCreateParams.Subscription.builder() .collectionSchedule( @@ -1104,6 +1182,11 @@ internal class ContractServiceTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractAmendParams.Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/PackageServiceTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/PackageServiceTest.kt index a5fc5fd9..978397e7 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/PackageServiceTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/PackageServiceTest.kt @@ -379,6 +379,44 @@ internal class PackageServiceTest { .discountConfiguration( PrepaidBalanceThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -638,10 +676,45 @@ internal class PackageServiceTest { .discountConfiguration( SpendThresholdConfiguration.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .build() ) .build() ) + .addSpendTracker( + PackageCreateParams.SpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier.builder() + .addSource( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + PackageCreateParams.SpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) + .build() + ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + PackageCreateParams.SpendTracker.ResetFrequency.BILLING_PERIOD + ) + .build() + ) .addSubscription( PackageCreateParams.Subscription.builder() .collectionSchedule( diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/PaymentServiceTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/PaymentServiceTest.kt deleted file mode 100644 index 5b6b5fee..00000000 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v1/PaymentServiceTest.kt +++ /dev/null @@ -1,75 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.metronome.api.services.blocking.v1 - -import com.metronome.api.TestServerExtension -import com.metronome.api.client.okhttp.MetronomeOkHttpClient -import com.metronome.api.models.v1.payments.PaymentAttemptParams -import com.metronome.api.models.v1.payments.PaymentCancelParams -import com.metronome.api.models.v1.payments.PaymentListParams -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith - -@ExtendWith(TestServerExtension::class) -internal class PaymentServiceTest { - - @Test - fun list() { - val client = - MetronomeOkHttpClient.builder() - .baseUrl(TestServerExtension.BASE_URL) - .bearerToken("My Bearer Token") - .build() - val paymentService = client.v1().payments() - - val page = - paymentService.list( - PaymentListParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - ) - - page.response().validate() - } - - @Test - fun attempt() { - val client = - MetronomeOkHttpClient.builder() - .baseUrl(TestServerExtension.BASE_URL) - .bearerToken("My Bearer Token") - .build() - val paymentService = client.v1().payments() - - val response = - paymentService.attempt( - PaymentAttemptParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - ) - - response.validate() - } - - @Test - fun cancel() { - val client = - MetronomeOkHttpClient.builder() - .baseUrl(TestServerExtension.BASE_URL) - .bearerToken("My Bearer Token") - .build() - val paymentService = client.v1().payments() - - val response = - paymentService.cancel( - PaymentCancelParams.builder() - .customerId("13117714-3f05-48e5-a6e9-a66093f13b4d") - .invoiceId("6162d87b-e5db-4a33-b7f2-76ce6ead4e85") - .build() - ) - - response.validate() - } -} diff --git a/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v2/ContractServiceTest.kt b/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v2/ContractServiceTest.kt index 217b05b2..22ed8b17 100644 --- a/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v2/ContractServiceTest.kt +++ b/metronome-java-core/src/test/kotlin/com/metronome/api/services/blocking/v2/ContractServiceTest.kt @@ -276,6 +276,11 @@ internal class ContractServiceTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + ContractEditParams.AddCommit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) .temporaryId("temporary_id") .build() ) @@ -542,6 +547,44 @@ internal class ContractServiceTest { PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration .builder() .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfigurationV2.ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfigurationV2 + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) .build() ) .build() @@ -898,8 +941,44 @@ internal class ContractServiceTest { .discountConfiguration( SpendThresholdConfigurationV2.DiscountConfiguration.builder() .paymentFraction(0.0) + .cap( + SpendThresholdConfigurationV2.DiscountConfiguration.Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addAddSpendTracker( + ContractEditParams.AddSpendTracker.builder() + .alias("alias") + .addApplicableSpendSpecifier( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .builder() + .addSource( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .Source + .THRESHOLD_RECHARGE + ) + .spendType( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .SpendType + .COMMIT_PURCHASE + ) + .discounted( + ContractEditParams.AddSpendTracker.ApplicableSpendSpecifier + .Discounted + .ANY + ) .build() ) + .creditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .resetFrequency( + ContractEditParams.AddSpendTracker.ResetFrequency.BILLING_PERIOD + ) .build() ) .addAddSubscription( @@ -965,6 +1044,7 @@ internal class ContractServiceTest { .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) + .addArchiveSpendTracker("string") .addRemoveOverride( ContractEditParams.RemoveOverride.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -1187,6 +1267,16 @@ internal class ContractServiceTest { ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) @@ -1221,6 +1311,40 @@ internal class ContractServiceTest { ) .rechargeToAmount(0.0) .thresholdAmount(0.0) + .addThresholdBalanceSpecifier( + ContractEditParams.UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + ContractEditParams + .UpdatePrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) .build() ) .addUpdateRecurringCommit( @@ -1311,6 +1435,15 @@ internal class ContractServiceTest { ContractEditParams.UpdateSpendThresholdConfiguration .DiscountConfiguration .builder() + .cap( + ContractEditParams.UpdateSpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) .paymentFraction(0.0) .build() ) diff --git a/metronome-java-proguard-test/src/test/kotlin/com/metronome/api/proguard/ProGuardCompatibilityTest.kt b/metronome-java-proguard-test/src/test/kotlin/com/metronome/api/proguard/ProGuardCompatibilityTest.kt index c618f3dd..47a68496 100644 --- a/metronome-java-proguard-test/src/test/kotlin/com/metronome/api/proguard/ProGuardCompatibilityTest.kt +++ b/metronome-java-proguard-test/src/test/kotlin/com/metronome/api/proguard/ProGuardCompatibilityTest.kt @@ -6,16 +6,27 @@ import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.metronome.api.client.okhttp.MetronomeOkHttpClient import com.metronome.api.core.JsonValue import com.metronome.api.core.jsonMapper +import com.metronome.api.models.BaseThresholdCommit import com.metronome.api.models.Commit import com.metronome.api.models.CommitHierarchyConfiguration import com.metronome.api.models.CommitSpecifier +import com.metronome.api.models.CommitSpecifierInput +import com.metronome.api.models.Credit import com.metronome.api.models.CreditTypeData -import com.metronome.api.models.Id +import com.metronome.api.models.HierarchyConfiguration +import com.metronome.api.models.Override +import com.metronome.api.models.OverrideTier +import com.metronome.api.models.OverwriteRate +import com.metronome.api.models.PaymentGateConfig +import com.metronome.api.models.PrepaidBalanceThresholdConfiguration +import com.metronome.api.models.RecurringCommitSubscriptionConfig import com.metronome.api.models.ScheduleDuration import com.metronome.api.models.SchedulePointInTime +import com.metronome.api.models.ScheduledCharge +import com.metronome.api.models.SpendThresholdConfiguration +import com.metronome.api.models.Subscription import com.metronome.api.models.v1.contracts.ContractCreateResponse import com.metronome.api.models.v1.contracts.ContractListBalancesResponse -import com.metronome.api.models.v1.payments.PaymentStatus import java.time.OffsetDateTime import kotlin.reflect.full.memberFunctions import kotlin.reflect.jvm.javaMethod @@ -67,7 +78,1190 @@ internal class ProGuardCompatibilityTest { val jsonMapper = jsonMapper() val contractCreateResponse = ContractCreateResponse.builder() - .data(Id.builder().id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build()) + .data( + ContractCreateResponse.Data.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .contract( + ContractCreateResponse.Data.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addCommit( + Commit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .product( + Commit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(Commit.Type.PREPAID) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .amount(0.0) + .addApplicableContractId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .archivedAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .balance(0.0) + .contract( + Commit.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .customFields( + Commit.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceContract( + Commit.InvoiceContract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .invoiceSchedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addLedger( + Commit.Ledger.PrepaidCommitSegmentStartLedgerEntry + .builder() + .amount(0.0) + .segmentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .type( + Commit.Ledger + .PrepaidCommitSegmentStartLedgerEntry + .Type + .PREPAID_COMMIT_SEGMENT_START + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType(Commit.RateType.COMMIT_RATE) + .recurringCommitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rolledOverFrom( + Commit.RolledOverFrom.builder() + .commitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .rolloverFraction(0.0) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder() + .countsAsDiscounted(true) + .build() + ) + .subscriptionConfig( + Commit.SubscriptionConfig.builder() + .allocation( + Commit.SubscriptionConfig.Allocation.INDIVIDUAL + ) + .applySeatIncreaseConfig( + Commit.SubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdBy("created_by") + .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addOverride( + Override.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductTag("string") + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .entitled(true) + .isCommitSpecific(true) + .isProrated(true) + .multiplier(0.0) + .addOverrideSpecifier( + Override.OverrideSpecifier.builder() + .billingFrequency( + Override.OverrideSpecifier.BillingFrequency + .MONTHLY + ) + .addCommitId("string") + .presentationGroupValues( + Override.OverrideSpecifier + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + Override.OverrideSpecifier.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .addRecurringCommitId("string") + .build() + ) + .addOverrideTier( + OverrideTier.builder().multiplier(0.0).size(0.0).build() + ) + .overwriteRate( + OverwriteRate.builder() + .rateType(OverwriteRate.RateType.FLAT) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .customRate( + OverwriteRate.CustomRate.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) + .isProrated(true) + .price(0.0) + .quantity(0.0) + .addTier( + OverwriteRate.Tier.builder() + .price(0.0) + .size(0.0) + .build() + ) + .build() + ) + .price(0.0) + .priority(0.0) + .product( + Override.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .quantity(0.0) + .rateType(Override.RateType.FLAT) + .target(Override.Target.COMMIT_RATE) + .addTier( + Override.Tier.builder().price(0.0).size(0.0).build() + ) + .type(Override.Type.OVERWRITE) + .value( + Override.Value.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + .addScheduledCharge( + ScheduledCharge.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + ScheduledCharge.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .schedule( + SchedulePointInTime.builder() + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .doNotInvoice(true) + .addScheduleItem( + SchedulePointInTime.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .quantity(0.0) + .timestamp( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .unitPrice(0.0) + .invoiceId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .archivedAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .customFields( + ScheduledCharge.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .name("x") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .build() + ) + .startingAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addTransition( + ContractCreateResponse.Data.Contract.Transition.builder() + .fromContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .toContractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .type( + ContractCreateResponse.Data.Contract.Transition.Type + .SUPERSEDE + ) + .build() + ) + .addUsageFilter( + ContractCreateResponse.Data.Contract.UsageFilter.builder() + .groupKey("group_key") + .addGroupValue("string") + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .usageStatementSchedule( + ContractCreateResponse.Data.Contract.UsageStatementSchedule + .builder() + .billingAnchorDate( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .frequency( + ContractCreateResponse.Data.Contract + .UsageStatementSchedule + .Frequency + .MONTHLY + ) + .build() + ) + .addCredit( + Credit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .product( + Credit.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .type(Credit.Type.CREDIT) + .accessSchedule( + ScheduleDuration.builder() + .addScheduleItem( + ScheduleDuration.ScheduleItem.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .amount(0.0) + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .creditType( + CreditTypeData.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .addApplicableContractId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .balance(0.0) + .contract( + Credit.Contract.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .customFields( + Credit.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .addLedger( + Credit.Ledger.CreditSegmentStartLedgerEntry.builder() + .amount(0.0) + .segmentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .timestamp( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .type( + Credit.Ledger.CreditSegmentStartLedgerEntry.Type + .CREDIT_SEGMENT_START + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .priority(0.0) + .rateType(Credit.RateType.COMMIT_RATE) + .recurringCreditId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rolledOverFrom( + Credit.RolledOverFrom.builder() + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .creditId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .salesforceOpportunityId("salesforce_opportunity_id") + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + Credit.SubscriptionConfig.builder() + .allocation( + Credit.SubscriptionConfig.Allocation.INDIVIDUAL + ) + .applySeatIncreaseConfig( + Credit.SubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .customFields( + ContractCreateResponse.Data.Contract.CustomFields.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .customerBillingProviderConfiguration( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .billingProvider( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .BillingProvider + .AWS_MARKETPLACE + ) + .deliveryMethod( + ContractCreateResponse.Data.Contract + .CustomerBillingProviderConfiguration + .DeliveryMethod + .DIRECT_TO_BILLING_PROVIDER + ) + .build() + ) + .endingBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hasMore( + ContractCreateResponse.Data.Contract.HasMore.builder() + .commits(true) + .credits(true) + .build() + ) + .hierarchyConfiguration( + HierarchyConfiguration.ParentHierarchyConfiguration.builder() + .addChild( + HierarchyConfiguration.ParentHierarchyConfiguration + .Child + .builder() + .contractId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customerId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .parentBehavior( + HierarchyConfiguration.ParentHierarchyConfiguration + .ParentBehavior + .builder() + .invoiceConsolidationType( + HierarchyConfiguration + .ParentHierarchyConfiguration + .ParentBehavior + .InvoiceConsolidationType + .CONCATENATE + ) + .build() + ) + .build() + ) + .multiplierOverridePrioritization( + ContractCreateResponse.Data.Contract + .MultiplierOverridePrioritization + .LOWEST_MULTIPLIER + ) + .name("name") + .netPaymentTermsDays(0.0) + .packageId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .prepaidBalanceThresholdConfiguration( + PrepaidBalanceThresholdConfiguration.builder() + .commit( + PrepaidBalanceThresholdConfiguration.Commit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .addSpecifier( + CommitSpecifierInput.builder() + .presentationGroupValues( + CommitSpecifierInput + .PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifierInput.PricingGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addProductTag("string") + .build() + ) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfig.builder() + .paymentGateType( + PaymentGateConfig.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfig.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfig.StripeConfig.builder() + .paymentType( + PaymentGateConfig.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfig.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfig.TaxType.NONE) + .build() + ) + .rechargeToAmount(0.0) + .thresholdAmount(0.0) + .customCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .discountConfiguration( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + PrepaidBalanceThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .addThresholdBalanceSpecifier( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .builder() + .addExclude( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .builder() + .addCustomFieldFilter( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .builder() + .entity( + PrepaidBalanceThresholdConfiguration + .ThresholdBalanceSpecifier + .Exclude + .CustomFieldFilter + .Entity + .COMMIT + ) + .key("key") + .value("value") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .rateCardId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addRecurringCommit( + ContractCreateResponse.Data.Contract.RecurringCommit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractCreateResponse.Data.Contract.RecurringCommit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractCreateResponse.Data.Contract.RecurringCommit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractCreateResponse.Data.Contract + .RecurringCommit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractCreateResponse.Data.Contract.RecurringCommit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractCreateResponse.Data.Contract.RecurringCommit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractCreateResponse.Data.Contract.RecurringCommit + .InnerContract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .invoiceAmount( + ContractCreateResponse.Data.Contract.RecurringCommit + .InvoiceAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .quantity(0.0) + .unitPrice(0.0) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractCreateResponse.Data.Contract.RecurringCommit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractCreateResponse.Data.Contract.RecurringCommit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .addRecurringCredit( + ContractCreateResponse.Data.Contract.RecurringCredit.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .accessAmount( + ContractCreateResponse.Data.Contract.RecurringCredit + .AccessAmount + .builder() + .creditTypeId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .unitPrice(0.0) + .quantity(0.0) + .build() + ) + .commitDuration( + ContractCreateResponse.Data.Contract.RecurringCredit + .CommitDuration + .builder() + .value(0.0) + .unit( + ContractCreateResponse.Data.Contract + .RecurringCredit + .CommitDuration + .Unit + .PERIODS + ) + .build() + ) + .priority(0.0) + .product( + ContractCreateResponse.Data.Contract.RecurringCredit + .Product + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .rateType( + ContractCreateResponse.Data.Contract.RecurringCredit + .RateType + .COMMIT_RATE + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .addApplicableProductId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .addApplicableProductTag("string") + .contract( + ContractCreateResponse.Data.Contract.RecurringCredit + .InnerContract + .builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .hierarchyConfiguration( + CommitHierarchyConfiguration.builder() + .childAccess( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .builder() + .type( + CommitHierarchyConfiguration.ChildAccess + .CommitHierarchyChildAccessAll + .Type + .ALL + ) + .build() + ) + .build() + ) + .name("name") + .netsuiteSalesOrderId("netsuite_sales_order_id") + .proration( + ContractCreateResponse.Data.Contract.RecurringCredit + .Proration + .NONE + ) + .recurrenceFrequency( + ContractCreateResponse.Data.Contract.RecurringCredit + .RecurrenceFrequency + .MONTHLY + ) + .rolloverFraction(0.0) + .addSpecifier( + CommitSpecifier.builder() + .presentationGroupValues( + CommitSpecifier.PresentationGroupValues + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .pricingGroupValues( + CommitSpecifier.PricingGroupValues.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .productId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addProductTag("string") + .build() + ) + .subscriptionConfig( + RecurringCommitSubscriptionConfig.builder() + .allocation( + RecurringCommitSubscriptionConfig.Allocation + .INDIVIDUAL + ) + .applySeatIncreaseConfig( + RecurringCommitSubscriptionConfig + .ApplySeatIncreaseConfig + .builder() + .isProrated(true) + .build() + ) + .subscriptionId( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" + ) + .build() + ) + .build() + ) + .scheduledChargesOnUsageInvoices( + ContractCreateResponse.Data.Contract + .ScheduledChargesOnUsageInvoices + .ALL + ) + .spendThresholdConfiguration( + SpendThresholdConfiguration.builder() + .commit( + BaseThresholdCommit.builder() + .productId("product_id") + .description("description") + .name("name") + .priority(0.0) + .build() + ) + .isEnabled(true) + .paymentGateConfig( + PaymentGateConfig.builder() + .paymentGateType( + PaymentGateConfig.PaymentGateType.NONE + ) + .precalculatedTaxConfig( + PaymentGateConfig.PrecalculatedTaxConfig + .builder() + .taxAmount(0.0) + .taxName("tax_name") + .build() + ) + .stripeConfig( + PaymentGateConfig.StripeConfig.builder() + .paymentType( + PaymentGateConfig.StripeConfig + .PaymentType + .INVOICE + ) + .invoiceMetadata( + PaymentGateConfig.StripeConfig + .InvoiceMetadata + .builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .build() + ) + .taxType(PaymentGateConfig.TaxType.NONE) + .build() + ) + .thresholdAmount(0.0) + .discountConfiguration( + SpendThresholdConfiguration.DiscountConfiguration + .builder() + .paymentFraction(0.0) + .cap( + SpendThresholdConfiguration + .DiscountConfiguration + .Cap + .builder() + .amount(0.0) + .spendTrackerAlias("spend_tracker_alias") + .build() + ) + .build() + ) + .build() + ) + .addSubscription( + Subscription.builder() + .billingPeriods( + Subscription.BillingPeriods.builder() + .current( + Subscription.BillingPeriods.Current.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .next( + Subscription.BillingPeriods.Next.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .previous( + Subscription.BillingPeriods.Previous.builder() + .endingBefore( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .startingAt( + OffsetDateTime.parse( + "2019-12-27T18:11:19.117Z" + ) + ) + .build() + ) + .build() + ) + .collectionSchedule(Subscription.CollectionSchedule.ADVANCE) + .proration( + Subscription.Proration.builder() + .invoiceBehavior( + Subscription.Proration.InvoiceBehavior + .BILL_IMMEDIATELY + ) + .isProrated(true) + .build() + ) + .quantityManagementMode( + Subscription.QuantityManagementMode.SEAT_BASED + ) + .addQuantitySchedule( + Subscription.QuantitySchedule.builder() + .quantity(0.0) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .startingAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .subscriptionRate( + Subscription.SubscriptionRate.builder() + .billingFrequency( + Subscription.SubscriptionRate.BillingFrequency + .MONTHLY + ) + .product( + Subscription.SubscriptionRate.Product.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .build() + ) + .build() + ) + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .customFields( + Subscription.CustomFields.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .description("description") + .endingBefore( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .fiatCreditTypeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .seatConfig( + Subscription.SeatConfig.builder() + .seatGroupKey("seat_group_key") + .build() + ) + .build() + ) + .uniquenessKey("x") + .build() + ) + .build() + ) .build() val roundtrippedContractCreateResponse = @@ -209,6 +1403,9 @@ internal class ProGuardCompatibilityTest { .addProductTag("string") .build() ) + .spendTrackerAttributes( + Commit.SpendTrackerAttributes.builder().countsAsDiscounted(true).build() + ) .subscriptionConfig( Commit.SubscriptionConfig.builder() .allocation(Commit.SubscriptionConfig.Allocation.INDIVIDUAL) @@ -232,18 +1429,4 @@ internal class ProGuardCompatibilityTest { assertThat(roundtrippedContractListBalancesResponse).isEqualTo(contractListBalancesResponse) } - - @Test - fun paymentStatusRoundtrip() { - val jsonMapper = jsonMapper() - val paymentStatus = PaymentStatus.PENDING - - val roundtrippedPaymentStatus = - jsonMapper.readValue( - jsonMapper.writeValueAsString(paymentStatus), - jacksonTypeRef(), - ) - - assertThat(roundtrippedPaymentStatus).isEqualTo(paymentStatus) - } }